SQS WTF? Please someone tell me I’m crazy.
I sent AWS a screwed up response, just to test things, and I got this back:
HTTP/1.1 400 Bad Request Transfer-Encoding: chunked Date: Tue, 25 Nov 2008 03:26:27 GMT Cneonction: close Server: AWS Simple Queue Service
Note the “Cneoction” header.
WTF?
A Very Basic Ruby Rack App
Sometimes I write very small web applications. I like to have the power and flexibility of ruby and my libraries, but I don’t want to drag around a huge web stack like Rails or even Merb. For this there is the great interface of Rack.
From the rack project:
Rack provides an minimal interface between webservers supporting Ruby and Ruby frameworks.
So here are the basics of using rack in a [semi]useful project:
First, we install the gem:
gem install rackThen we implement a very basic app. Save this as “app.ru”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | use Rack::ShowExceptions use Rack::CommonLogger require 'rack/request' require 'rack/response' module Rack class App def call(env) req = Request.new(env) Response.new.finish do |res| res.write("<html><body>") res.write req.fullpath res.write("</body></html>") end end end end run Rack::App.new |
Next we need to run a server. The rackup command should be installed with the rack gem.
rackup app.ru -p 3000
This fires up one of the rack handlers. It defaults to either using Mongrel or Webrick.
Now in your web browser go to http://localhost:3000/this/is/the/path.
Magic, right? Now if you also need this application of yours to be screaming fast and not need to lean on [crappy] ruby threading, we need to add EventMachine, which is one of the greatest additions to Ruby network programming ever. The easiest way to do this is to use Thin.
From the Thin site:
Thin is a Ruby web server that glues together 3 of the best Ruby libraries in web history:
- the Mongrel parser, the root of Mongrel speed and security
- Event Machine, a network I/O library with extremely high scalability, performance and stability
- Rack, a minimal interface between webservers and Ruby frameworks
Which makes it, with all humility, the most secure, stable, fast and extensible Ruby web server bundled in an easy to use gem for your own pleasure.
The next steps are easy for all that goodness.
gem install thin thin start -R app.ru
Stick that in your pipe and smoke it!
Dial Tone Nostalgia
Luke and I were having an in-depth conversation about the UI for our Zeep Media product. We’re doing some really cool work with geographic targeting and report visualization on top of Google Maps. I’m sure that there will be subsequent blog posts about the technical challenges here.
I was trying to explain the NANP (North American Numbering Plan) and exactly what the NXX in NPA-NXX meant. NPA is a set of three numbers ([2-9][0-8][0-9]) that you will probably know as “Area Code” and NXX is just the next three digits.
So if we pick apart my number:
+1 (778) 227-3859
- + means we’re using E164
- 1 means we’re dialing in NANP
- 778 is the NPA or area code
- 227 is the NXX or exchange
- 3859 is the station code
Unimportant as they may seem, the NXX digits used to prominently have a real, practical use.
Before cell phones, before digital-electronic switching, in fact before digital-mechanical switching there was the operator. The operator’s job was to manually connect wires running to people’s phones.
A telephone operator manually connecting calls with patch cables at a telephone switchboard.
As everyone knows, the best of systems can be ruined when you introduce human error, greed or incompetence. That brings us to an undertaker, Almon Brown Strowger. Almon was convinced that the local manual telephone exchange operators were sending calls to a competing undertaker business and thus set out to invent the automatic telephone exchange.
The exchange existed of a collection of Strowger Switches that would allow a phone connected to a wire pair on one side to dial using a set of pulses to connect a wire pair at the end, making another phone ring. Each switch would move the the corresponding index based on the number of pulses it received.
Dialing 3-8-5-9 a switch would take the first three pulses and place the initiating pair on the “3” circuit, the switch connected on that circuit there would then select the “8” circuit. As you can imagine, when you add a lot of numbers, say 10,000 of them, you need a lot of these switches. A lot of these switches would take up a lot of space. So, for every 10,000 numbers (0000-9999) there would be one building that housed all of these switches, the exchange. This is why old phones pulsed, they were actually moving a mechanical piece every time a pulse went over the wire.
Eventmachine HTTP Client
For some reason, this simple example has eluded me for some time. “EventMachine is a library for Ruby, C++, and Java programs. It provides event-driven I/O using the Reactor pattern.” When using Eventmachine, as I often do, asynchronous network calls are key. And often in the word of web services, crawling and scraping most useful clients I write these days deal with HTTP. So here is the most basic example of an HTTP client written using eventmachine:
require 'rubygems' require 'eventmachine' EM.run do include EM::Protocols conn = HttpClient2.connect('simonwex.com', 80) req = conn.get('/') req.callback do p(req.content) EM.stop end end
Nested Hashes Fuck Me Up
Mr. Anonymous
12:29
had to play dumb
Simon Wex
12:29
hehe
bettter than playing smart
You know…
Mr. Anonymous
12:31
…
Simon Wex
12:31
I can’t get over it, I think people to speak to themselves are stupid.
Maybe an unfair bias…
but if you actually have to vocalize something to understand it, what sorts of limitations does that put on your understandings?
Mr. Anonymous
12:32
probably none
fuck you
Simon Wex
12:32
hehe
You you talk to yourself?
Mr. Anonymous
12:32
I’ve caught myself doing it
Simon Wex
12:32
is that part of your “playing dumb”?
Mr. Anonymous
12:32
and yes, I have trouble with certain levels of abstraction
12:33
Mr. Anonymous has left the conversation.
Mr. Anonymous
12:33
nested hashes fuck me up
Simon Wex
12:34
Easy killer.
My Girlfriend Loves The X-Files
Karilyn is also very excited to see the movie. All I have to say is this:


Chop Shop (2007)
I was trying to sleep last night just outside of Portland Oregon and, to be honest, I wasn’t doing a great job of it. So instead of shutting my eyes and ignoring the strange sounds coming from the woods, I watched Chop Shop [IMDB]
It was real to the point of feeling voyeuristic. It didn’t have a rocketing trajectory to a massive climax, but instead depressingly trudged on like the main characters’ lives. – Though my description doesn’t sell it, it was a very enjoyable watch and I highly recommend it.
Something funny I just noticed…
So here’s something sort of funny that I just noticed. When on my mac clicking on “Get Info” for my friend’s desktop (‘doze), you get this appropriate little preview…

Good old windows blue screen. It has been a while and I don’t miss you.
Contentment
I’m a happy kinda guy. I think a lot of this comes from generally being happy with what I have, not lusting after what I don’t. I think this explains my stance on things like plastic surgery and suicide bombings.
Around a month ago I blew out my back. I was well on my way to recovery – something you measure differently when you’re unable to put on your own socks – when I tweaked it and I’m now pretty much back to square one. So there I was, teetering on my rickety legs reaching down to the second shelf for a yogurt in one of those big multipacks. I was hoping for a strawberry as my hand touched a pack. I realized it didn’t matter. I was going to get what I got and the pain was not worth going back for a replacement. Mmnnn tasty yogurt.
Resurrecting the Electric Car
I suppose today I’m playing the optimist. I was playing with Google Trends this morning and noticed something I found promising. There are no brilliant insights I have to contribute, I’ll let this graph representing the popularity of search terms related to “oil prices” and “electric car” speak for itself:
Scale is based on the average traffic of electric car from United States in the last 12 months.
Learn more
| oil prices |
|
1.32 |
| electric car |
|
1.00 |

(Source: http://www.google.com/trends…)