Sunday, December 13, 2015

nginx local proxy




I wanted just a simple nginx setup to forward to a local app.  Here's the result:


http {
...

    server {
      server_name  52.62.72.255;
      #access_log   /var/log/nginx/histories.log;
      location / {
        proxy_pass      http://127.0.0.1:3000;
      }
    }



For some reason it was hard to find this info!  I had to pull it from one of my other servers.  But one good example is this reference: http://wiki.nginx.org/FullExample


Wednesday, July 15, 2015

Unable to SSH to new AWS servers, until: route table

Symptoms: I've had an AWS account for years, and I went back and created some instances this past week but then I couldn't access them (via SSH: "Operation timed out"). One oddity was that my old instances had no VPC ID, but every new instance had one (and the VPC was created if none existed).

Solution: I found this troubleshooting guide for connecting, and I followed the step on route tables and added a route with a destination of 0.0.0.0/0 and target of igw... (which is auto-filled with my internet gateway ID).

I've never had to do this before.  Hopefully I'll remember!

Tuesday, May 5, 2015

PermanentRedirect when accessing AWS S3 bucket

When running this on the command-line:
aws s3 ls s3://my-bucket/
I kept getting this error:
A client error (PermanentRedirect) occurred when calling the ListObjects operation: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
The problem was that my region wasn't set. I did this to fix it:
export AWS_DEFAULT_REGION=us-west-2
This is a pretty stupid situation: when using the web console, the S3 service says that there's no need to choose a region, and it won't even let you select one. But obviously it's very important for configurations. Dumb.

Thursday, September 4, 2014

Solutions for Vagrant deployment to AWS


Here are a bunch of notes from troubleshooting Vagrant out to AWS:





An active machine was found with a different provider. Vagrant currently allows each machine to be brought up with only a single provider at a time. A future version will remove this limitation. Until then, please destroy the existing machine to up with a new provider. Machine name: default Active provider: virtualbox Requested provider: aws

 ... yep, destroy it



<br /><span style="font-family: Arial, Helvetica, sans-serif;">Here are a bunch of old notes on errors I got while trying to use Vagrant with AWS.</span><br /> The box you're attempting to add doesn't support the provider you requested. Please find an alternate box or use an alternate provider. Double-check your requested provider to verify you didn't simply misspell it. Name: hashicorp/precise64 Address: https://vagrantcloud.com/hashicorp/precise64 Requested provider: [:aws] ... change to the dummy box There was an error talking to AWS. The error message is shown below: UnauthorizedOperation =&gt; You are not authorized to perform this operation. ... IAM... had to make user with that key ID have power access




==&gt; default: Warning! Vagrant might not be able to SSH into the instance. ==&gt; default: Please check your security groups settings. /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/middlewares/expects.rb:6:in `response_call': The image id '[ami-21e6e964]' does not exist (Fog::Compute::AWS::NotFound) from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/middlewares/response_parser.rb:8:in `response_call' from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/connection.rb:363:in `response' from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/connection.rb:233:in `request' from /Users/tlarson/.vagrant.d/gems/gems/fog-1.23.0/lib/fog/xml/sax_parser_connection.rb:35:in `request' ... had to find an AMI, in the right zone ==&gt; default: Warning! Vagrant might not be able to SSH into the instance. ==&gt; default: Please check your security groups settings. /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/middlewares/expects.rb:6:in `response_call': The key pair 'halfpricedgranite-workbook' does not exist (Fog::Compute::AWS::NotFound) from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/middlewares/response_parser.rb:8:in `response_call' from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/connection.rb:363:in `response' from /Users/tlarson/.vagrant.d/gems/gems/excon-0.39.5/lib/excon/connection.rb:233:in `request' from /Users/tlarson/.vagrant.d/gems/gems/fog-1.23.0/lib/fog/xml/sax_parser_connection.rb:35:in `request' ... again, in the right zone ==&gt; default: Waiting for instance to become "ready"... ==&gt; default: Waiting for SSH to become available... ^C ... because networking is restricted: security_groups ... and may want to name it


Saturday, August 16, 2014

Adding tables to Etherpad Lite



So I love the real-time sharing of Google Docs, so I installed our own Etherpad Lite... and then I wanted tables so I installed ep_tables, but it was a bear to try and copy existing tables into there, so I finally exported some tables and found the format and here's what I recommend, in this example of 2 lines:

{"payload":[["This is a sample row on table 1"," "," "]],"tblId":"1","tblClass":"data-tables"}

{"payload":[[" "," "," row 2 column 3"]],"tblId":"1","tblClass":"data-tables"}


... where each row of data is a line of text.  Just paste them in the document and it reformats into a table.
It turns out the plugin doesn't like line breaks (or tabs) in a row, so don't even try... and that's one reason I wouldn't try and put multiple rows inside one payload line like this:
{"payload":[["This is a sample row on table 1","",""],["",""," row 2 column 3"]],"tblId":"1","tblClass":"data-tables"}

Since you can't split each row onto a new line it is pretty unreadable.
Other hints:

  • Only use the 'Table' button at the top to manipulate the table and not the little mouse-overs... they just never did anything reliable for me.
  • I also installed styles and formatting, but I couldn't get them to apply inside the table.
  • I don't see the purpose of the tblId; I put rows with the same tblId in different places and they showed at their location in the document, with line breaks or whatever in between.


Monday, July 7, 2014

The day-of-week for any day this year (and this century)


I came up with this approach to figure out the day-of-week for any day during the current year:

  • Each year, remember the weekday of first day of the year, eg. Wed in 2014  (See below for a formula for this in the 21st century.)
  • Memorize this set of numbers, one for each month: 155274263153 ... which is the date of the first time that day occurs each month

You can probably get it from there... so here's an example: what day is Dec 25 this year?
  • December is month #12, so take the last digit in that set of numbers: 3
  • That means the 3rd is the first time that Wed occurs this December.
  • Add multiples of 7 to get to other Wed that are close: 
    • +7=10
    • +14=17
    • +21 = 24
  • Since Dec 24 is on Wed, Dec 25 must be on Thurs
  • The exception is leap years, and I typically subtract one from the first day in January and February.
This makes it pretty easy, because that first weekday only changes each year and I can remember that day for the whole year.

Now, for the majority of my lifetime (if things don't go as I hope), it's actually pretty easy to find the first day of the year for any year:
  • Take the year without the 2000 part, eg. 14 for 2014
  • Calculate (y + y div 4) mod 7
    • or (y mod 7 + y div 4) mod 7
    • or (y mod 7 + (y div 4) mod 7) mod 7
  • 0=Sun, 1=Mon, etc.
    • except for on leap years (divisible by 4) subtract 1 day for Jan-Feb
Pretty easy to remember for us mathematicians... it starts with Sunday, and then moves one day each year with an extra adjustment on leap years.

The rules get really complicated for previous or future centuries because we don't have leap-years every 100 years but then we do have them every 400 years.  But, like I say, this works for my foreseeable future, in 99.9% of the times I ever need to find a day.

I haven't written this up before because I checked years ago and found people had already written about this algorithm, but I think it's worth mentioning now because it's so easy for the vast majority of cases people use for a while to come.  BTW, if I want a comprehensive algorithm, I'll probably try Conway's Doomsday Algorithm.


Saturday, June 28, 2014

Get on RespectNetwork and get your XRI name.

Just a little motivation for getting involved with RespectNetwork and grabbing one of their "cloud names" (ie. an XRI) at their great one-time price of $25:

For a while there, I was playing with the APIs for "unhosted" and P2P apps quite a bit, just doing things that seemed fun personally.  I played with Kynetx (founded by my BYU professor Phil Windley) and Singly (founded by Jeremie Miller of XMPP fame), both of which are still very worthwhile projects with huge potential (and you can see from my labels that I've posted about them before).  Other related projects are redecentralize.org and projectdanube.com and cozy.io.  Anyway, the Respect Network in particular is a brainchild of Drummond Reed and it's had a few changes of directions, starting with connect.me, though I look on that activity feed and I don't see much happening there; Drummond Reed and Doc Searls and Kaliya Hamlin and Phil Windley (remember?) are big people in the identity space, eg. the internetidentityworkshop.com conferences, and so I still expect to see big things out of this set of initiatives for owning our own data.  Anyway, my hope is to push for these kinds of tools and protocols to help fight the silos and lock-in of Facebook and even Google... on top of the basic infrastructure tools (eg. pack.resetthenet.org).

Saying all that, I realize that it's not very widespread at this point.  I think they're laying out the protocols and doing cool stuff, but it's still at the experimentation point, I'd say.  But some of the concepts are sticking, eg. these XRI names... I got my first one a few years ago... so I think they're worth getting now.