Over-thinking #1: Node.js HTTP requests

Something I’ve been toying with is a tip and trick, but mostly horrible hacking away and over-thinking things blog series highlighting the stupid things I do. These things will likely come from stuff for my work or simply curiosity.

Without further ado, here’s #1.

A couple a weeks ago, I needed to migrate a web server and test the sites before going live. Due to a variety of constraints, editing the hosts file, using something like DNShifter or editing the hostname for the vhosts was out of the question. What is a guy to do? Thinking over the problem I figured node.js would be the quickest route to write a testing routine with.

The first problem and probably the biggest was to construct the http request in such a way that I would connect to a different host than the hostname would otherwise send me to. Looking at the node.js code on github made me think it was going to be a piece of cake, just a couple additions to the /lib http files would allow me to specify the actual host to connect with.

//around /lib/http.js:1425
else if(options.connection) {

This allowed me to use a specific socket made by net.createConnection. However, this is clunky and I’d have to maintain a copy of the mainline http with this and all the other necessary code changes. Obviously this is more work in the long run and my future self is lazy.

Thankfully the folks who wrote the http module decided to check if the options object for http.request() has “createConnection” defined and then uses that to initiate the TCP stream. This makes the task so much easier and should work for the foreseeable future.

var url = require().parse("http://example.com/");
url.createConnection = require('net').createConnection.bind(null, 80, "snoj.us");
require('http').request(url, function(res) {
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);

And of course since drafting all this drivel I find that wget (starting with 1.10), Invoke-WebRequest, and node.js allow the Host header to be specified and each works excellently. However, I still like this technique as it allows you to leave the original URL in place while forcing a connection to another server. Using custom headers means editing the URL which may or may not be doable in some situations and calls for more code changes to accomplish the same end.

What’s the motto with you?

Last year during a men’s retreat weekend my church put on, we men were challenged to come up with a “Family Charter”,  a document of rules and regulations concerning interpersonal interactions. You could look at it as something akin to The Constitution for Minnesota, the U.S.A or any organization. Though I’m not too keen on having a charter for several reasons that are another post, one thing did stick out to me, the family motto.

So I started digging into my family background to see if there was anything I could revive or use for inspiration. thus far, I’ve only come across one I might have claim to.

From the old maternal side I found, “Nil sine numine” or “Nothing without God”. Quite spine tingling if you ask me, invoking the idea that nothing is possible without God’s hand or blessing and reminding us of his sovereignty.

As far as I am aware, my paternal family descends from common farming folk. I’ll have to dig around more on that side.

The Bond family has a neat one as well, “The world is not enough” (“Orbis non sufficit”). Which is an actual family and crest. I had always assumed it was the realm of fiction. At any rate, I had thought it a motto with gravitas, proclaiming that there is something better, something that this world cannot satisfy. Or perhaps, the price required to “buy one off” would be more than the world.

Other ideas being toyed with:

  • To the sky/ad caelum
  • Seek the Lord/Quaerite Dominum
  • With strength, comes peace/cum virtute, fit cum pace

ref: http://en.wikipedia.org/wiki/List_of_Latin_phrases_(full)

Josh: Nerd in the country

It’s getting official, we’re moving to the country. It’s something that the mrs and I have been thinking of doing, mostly in a “sometime-in-the-future” way, several years from now and the earliest.

Then earlier this year we found ourselves a piece of land for sale about 20-30 minutes away from our current home that we could not say no to. (Intra-family deal.) Now after a month or so of unknown timelines, we have some concrete dates for moving. Which do not easily jive with other dates like when newbie is coming or snow melting. I hate moving with snow on the ground.

Why move to the country? Won’t I miss the high-speed internet offerings? Well, yes, I will. 30Mb+ internet down speed is really, really nice, but there are some other reasons I’ve had my eye on the country side.

During my childhood, we’d go visit relatives in California for a week or a month at a time. I loved the time there with my cousins and just being in California. There were several reasons we were able to do this, one of which was that my Aunt and Uncle had a large enough house that we could comfortably stay with them. To be able to do the same thing for my friends and family is something I’ve wanted to do as well.

We’ve wanted to have a garden for a couple years, but our home so far have either been rentals and the land lords prohibited it or the lot was too small. Though our last lot probably could have had a small one if we did some terracing. Our (well more my goal) is to eventually have the garden offset store bought veggies to such a degree that we’re only buying if much spoils or we’re needing extra for a feast.

There’s a chicken coup that we’re hoping to make use this summer. Our little family can go though a couple dozen eggs a week easily when only accounting for breakfast. So even just over a half dozen chickens should keep up with our weekly demand for eggs. Meat though is another matter. Thinking of all the times we have just chicken breast, wings, or legs, we’d have to have a lot of chickens to satisfy that want.

I love a good fire with friends on a brisk fall night or the warm glow of a fireplace. While we have “room” at our current digs, I’m looking forward to the additional space to have a pit instead of a portable steel bowl. We’re also looking at using wood to offset fuel oil use down the road. This will mean a lot of wood chopping.

It melts the heart

Over the last couple months, my little flower and overflow have started waking up when I get up for work. Following me downstairs and starting to play or demanding to watch Kipper before mom comes down and turns it off.

However this week has been slightly different. The little flower has started saying “Daddy no work, stay home!” I’m almost tearing up right now thinking about it.

I love being a dad.

NAS and cloud and EC2 oh my!

Building my own awesome “NAS” box for precious family photos will take a pretty penny to complete and even then I wouldn’t have backups in case of disaster (I’m a disk over tape/dvd guy). So to get me started I’m using Amazon’s EC2 service.

For the moment, I’m using one Micro instance with 3x50GB extra drives in a ZFS RAIDZ. Later on I’m hoping to either compliment it with NAS at home or perhaps another Micro instance in another datacenter…or both.

Either way, I basically only had to do the following after creating the instance.

sudo apt-get install zfs-fuse
sudo mkdir /cloudnas

sudo zpool create cloudnas -m /cloudnas raidz /dev/xvdf /dev/xvdg /dev/xvdh
sudo adduser myself
sudo mkdir /cloudnas/myself
sudo chown myself:myself /cloudnas/myself

I really wish I could have used the native ZFS modules instead of the fuse, but I couldn’t get it to work and I wasn’t in the mood to build zfs from source…yet.

It’s a bird! It’s a project! It’s Magpie!

It’s all official now with papers signed and everything. I’m joining the folks at Magpie Software to help make the world of planes walkers easier.

A couple weeks ago my friend (CTO of Magpie) Nick Davis contacted me about joining the team and working on the various parts that make up their flagship software. My main focus being the back-end, like making sure the card prices are “on the money”.

If you want to know more or even subscribe, check them out at their site.

Find a network route

The Linux ip tool has a really handy feature to get the route a given IP will take. Unfortunately, I know of no native Windows equivalent.

This is built for Windows 8 or Powershell v3 as it makes use of Get-NetRoute.

function Find-Route {

    $rs = Get-NetRoute -AddressFamily ({if($IP.AddressFamily -eq "Internetwork"){"ipv4"} else {"ipv6"}}).invoke();

    foreach($ri in $rs) {
        if(Confirm-SameSubnet $ri.DestinationPrefix.split("/")[0] $ri.DestinationPrefix.split("/")[1] $IP) {

Example output


ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
------- -----------------                              -------                                  ----------- -----------
13                                                                  0 ActiveStore


ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
------- -----------------                              -------                                  ----------- -----------
13                                                                256 ActiveStore
13                                                                  0 ActiveStore


ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
------- -----------------                              -------                                  ----------- -----------
13                                                                  0 ActiveStore

Find-Route 2001:4860:4860::8844

How is a raven like a writing desk?

With the eminent birth of my second child and since I’ll be working primarily from home for a couple weeks, I’m going to need an office and desk. Luckily our new house has a couple room options, the second floor and basement, but both locations are not very friendly to moving large pieces of furniture into or out of.

Enter my problem. I want/need a larger desk, but these are either too expensive, are poor quality, don’t come in small enough sections to easily bring into the rooms or some combination of these. So I decided to design my own.

The design needed to be something that could be built in one place, quickly assembled and easy to move. Eventually I decided on a modular block design that would allow the desk to be quickly reconfigured and extended if need be. These modules are 2 foot squares with “stubs” with holes on the other tree sides to accept another similar square or accessories.

modular desk sketch
modular desk sketch

However when it comes to cables, there’s usually a mess at my desk. So I’m probably going to need some sort of management. Probably my favorite idea so far is the gutter system. I figure that the cables will get messed up anyway, might as well just make it easy to hide them.

cord gutter trench
mock up of a cable gutter accessory

Hopefully I’ll be able to get started within the week. Of course, if the wee one doesn’t pop out before then.