Not Ready for Prime Twine : A review of Super Mechanical’s Kickstarter hardware

A lack of an in-apartment washer and dryer can make life a bit of a drag.  Earlier this year I was wondering why our building’s washers/dryers don’t have internet monitoring.  I did some research and found a number of companies were offering internet monitored washers/dryers but they mainly seemed to be in use at college campuses.  Makes sense.

I brought it up to my  landlord and it turned out that the company that sold him the system in the building had them available and was willing to do an upgrade for him.  There was, however, the small problem of cost.  They wanted over $200 a machine to upgrade the “readers” as well as an ongoing monthly fee of around $100 for the service.  He and I concluded that people weren’t willing to pay $5 per load of laundry and that we’d all just have to keep using our microwave timers / iphones to keep track of our laundry.

It was around this time that I ran across a project on Kickstarter that I thought might help. I’m a big fan of Kickstarter and have funded a variety of things on there including Double Fine Adventure , Mail Pilot, and my personal favorite The Travoltas who I will be traveling to see in Houston this February.  But, the Kickstarter I’m talking about in this case is this one called Twine.

It looked interesting since it was a simple sensor system with built-in wireless.  It  included temperature and vibration sensors and since I had this washer/dryer thing stuck in my head I figured I should check it out.  The project had already been fully funded but I went ahead and pre-ordered one and then promptly forgot about it. That is until about a month ago when I got an email saying that my Twine was ready for shipping.  The email also said that things had turned out a little more expensive than they expected so the cost of the Twine with full sensor package was $199 instead of the $174 when I pre-ordered.

My Twine arrived within a couple days and I have to admit as far as packaging goes it was amazing.  The guys at SuperMechanical certainly know how to put together a cardboard package.

The Twine itself as well as all the add-on sensors are sleek looking and well made.

Open Box 1
Open Box 2

After pulling everything out of the box I was pretty excited to start playing with my new toy.  Unfortunately this is where the excitement ended and the disappointment began to set in.

I installed the batteries in the Twine and fired up my laptop.  A new wireless network appeared and after connecting my laptop to it, a browser popped up asking me to select my local network and password so it could jump on my wireless.  I had a moment of trepidation here as I’m not big on putting passwords on devices that I don’t have the source code to but I moved ahead.

After that I had to create an account on SuperMechanical so that my Twine could start sending data to their web site.  This was all a relatively painless process and within a few minutes I could see that the Twine knew what orientation it was sitting in and that it was sending the temperature of my apartment.  Immediately I noticed that the Twine thought my apartment was anywhere from 78-80 degrees which is pretty much about 10 degrees too high. Oh well no biggy, next I thought I’d check out the vibration sensor. “Currently not supported”.  Huh what?  That’s why I bought the thing.  Nope,  I was out of luck.

I moved on to play with the other sensors, moisture, magnetic switch, and break out.  They all worked as expected.

The Twine is easy to take apart and if you look at the main board it’s pretty clean with a 32 bit ARM based MCU, a Gainspan low power wifi module, and some Flash memory. The board has a Micro-USB port but that is only for power, not communication.  The 4 pin sensor adapter plug is wired with the following : 3.3V,GND, Input, 1 Wire.  The Input is the input voltage from a sensor and the 1 wire is used to identify that sensor.  Each of the sensor boards has a 64 bit Unique ID chip with 1 wire interface. I’m pretty sure the people who are planning to plug their sensors in using a Y cable are going to be in for a surprise.

Take it apart

After playing around with the website for a while what I really wanted was to get the data directly from the device to one of my local computers.  Why make me round trip from the Twine to the SuperMechanical web site back down to my local computer.  I understand the “hey you can see it anywhere on the internet this way”, but “hey maybe I only want to see it locally”.

I posted a message asking about the local network support in the software developer section but didn’t receive any kind of acknowledgement from the powers that be.  A couple of other Twine users responded they’d like to see the same support.  My guess is the SM guys are probably a bit overwhelmed right now.  (I sent them a copy of this to see if they had any comments back on December 19th and never heard a word.)

At one point I considered throwing a proxy in the middle to see what the device is actually sending to the SM servers, but I decided I wasn’t going to invest that much time in it since I was probably going to shelve it for now anyway.

The Twine sends its updates to the server at a couple of different rates.  One is about every 45 seconds, the other is in a continuous fast update mode.  It will switch back to the slower mode on its own if you don’t click a button on the website stopping it.  This was another reason I wanted to access it locally instead of the whole crazy round trip it was doing to be able to monitor it from 3 feet away.

Although the actual hardware of the Twine seems to be well thought out and well designed (maybe even over-designed a bit) the software side is quite lacking.   As it stands today if you want to sense temperature and a single input of one other type, send that info to a server somewhere, then have it email you, tweet, or post to an http url using very simple rules then this is the device for you.  If your use doesn’t match that exacting criteria then $200 seems a little high when you can buy an Arduino or a Raspberry PI for less than 1/5th the price.

I hope they open source the system or at least open up the interface to the local network. This would allow alternate uses for the hardware to grow. Without that I think the Twine is in for a rough road. I wish them luck as they seem like good guys who really know how to do physical product design.  Right now there’s better value for your money if you have any DIY skills at all.

Using WordPress for a Simple News Web Widget.

I often find myself needing a simple blog type news feed for the various sites I’m creating.  In the past when I was still doing my primary development on .NET I rolled my own solution using a SQL database to hold the entries.  At first I’d just put the data into the database directly but of course over time I wanted to be able to edit and add new entries from a web interface.  So I found myself incorporating TinyMCE and pretty soon I was writing a whole management interface just for editing news posts.  I knew it was time to stop myself before completely falling prey to NIH syndrome.

Lately I’ve been doing a fair amount of small projects using WordPress and it seemed that I could just use its CMS to hold my news posts. I’d now have a repository for my posts as well as the ability to edit them.
In order to use the post data in my other sites I wanted to export my posts in JSON format. I’ve written a fair amount of JSON exporting code server side so I knew this wouldn’t be a problem. Luckily I took a look in the WordPress plugin repository and there’s already a pretty nice plugin that dumps any post in JSON.
If you want to do this you first need to download and install the latest version of WordPress.  This should take you all of 5 minutes unless you’ve never done it before in which case it might take you 30 minutes if you need to install LAMP or WAMP if you’re on Windows.  You can also do it in about 5 minutes on an Amazon EC2 micro instance by following this excellent guide.
You will also need to download the JSON plugin and copy it to the plugins directory.  You can now create new posts in WordPress and pull the data out in JSON.
I’m using this for my Madtown yoga website.  If you look at the site you will see a list of  news posts on the right that are fed by the WordPress blog.
The simple blog interface is here, where you can see a series of posts in the default wp skin. If you look here you can see the exact same posts rendered out as JSON data. Since I’m only using the blog as a data repository I didn’t bother messing with the WordPress UI.

If you look at the HTML for the news section on the right you will only see two lines of relevant code.

<script src="/Scripts/wpnews.js" type="text/javascript"></script>
<div id="news-widget-container"></div>

I’ve implemented this as a web widget. A web widget is a way to allow people to very simply place some kind of functionality on a web page.  A container div with a specific ID is placed on the page and then that div is filled in on the client side by the corresponding JavaScript. If you want a good tutorial on web widgets you can check out this article.  It’s the article I used to originally craft this news widget a few months ago.

In this case the JavaScript checks to see if JQuery v1.6.4 is currently loaded on the page and if not it loads it. It then reads the data from my WordPress site as JSON into an array and then adds the posts as a series of divs to the HTML DOM . The actual formatting of the data is handled by a separate CSS file.

If you want to have some fun make a simple text document on your desktop that looks like this and save it as test.html.

<script src="" type="text/javascript"></script>
<div id="news-widget-container"></div>

If you then open this test.html file in your browser you should see an unformatted list of my news posts in the document you just created. If you add in the line

<link href="" rel="stylesheet" type="text/css" />

you will then see it with my formatting applied to the divs.  What’s nice about widgets, besides the simplicity of using them, is the ability to their look on your page.  In this case add simple formatting to the classes FrontPageNewsTitle and FrontPageNewsContent and you can make my news feed look however you like on your web page.

If you take a look at the source code for wpnews.js it should be pretty straight forward to understand what I’m doing.  The majority of the code at the bottom is simply used to get JQuery loaded up if it isn’t already used on the page.

A special note to be aware of when pulling data from a web site in JSON  format. Often when pulling data into a web widget the domain which has the data may be different from the domain from which we load our page.  The issue here is that JavaScript is not allowed to load JSON data cross domain. The way that you solve this problem is by using a format called JSONP. The only difference in JSON and JSONP is that in the latter case the data is wrapped in a function and then returned as an object when that function is called.  Since code can be loaded and executed cross domain you just got around the problem!

Raspberry Pi a la Node – Running nodejs on the Raspberry Pi

My local hackerspace Sector67 held a 24 hour build fest this weekend. Late last week in preparation for the event a few of us purchased some Raspberry Pi‘s.  If you’re not familiar with the Pi, it’s a credit card sized ARM based computer with a USB port, Ethernet port, GPU,  HDMI and Composite video out that runs Linux for about $35.  You can read more about it at the link above but the “overall real world performance is something like a 300MHZ Pentium 2, only with much, much swankier graphics.”

I bought 2 with the plan to install nodejs on them.  I figured it’d be a super cheap way to create a web based controller people could use in other projects.  I’m happy to say it only took me about 3 days to make this a reality.  However it was pretty much 3 days of frustration that I’d like to keep the rest of you from having to experience so here’s the scoop.

I bought the bare bones Raspberry Pi for $35.  When you buy the bare bones card you’re going to need some more hardware to make it run. Here’s a quick list:

1) Class 4 SD card from 4 gigs to 32 gigs in size.  The Pi uses this for its boot device.
2) A 5v 700mA micro usb power supply.
3) A powered usb hub.
4) USB Mouse/keyboard.
5) A monitor with HDMI input or an HDMI to DVI converter if your monitor is DVI only.
6) An SD card reader/writer to image the SD card with the linux boot image.

My Pi’s arrived in the middle of the week along with the 2 32g SD cards I ordered off Amazon.  I rooted around my junk hardware closet and dug out an extra USB keyboard/mouse and an old Blackberry phone power supply that was 5V/650mA micro USB.  The one thing I realized I was missing was an SD card reader/writer.  I made a quick search on the internet and found that my local Target claimed to have a $10 cheap-o reader in stock.  Of course when I got there they didn’t have it but they did have a $20 Belkin universal media writer as well as a couple of powered USB hubs on closeout for $5 each.  So I grabbed them and headed over to Sector67 to get things up and running.

The first order of business was to get the linux images on to my SD cards.  I decided to do this from my Windows based laptop so I downloaded the latest Debian image from the Raspberry Pi download page.  The actual release I picked up was the September 18th Raspbian “Wheezy” image.  After downloading and unzipping the image I was left with an .img file I needed to get onto the SD cards.  In order to facilitate this I needed a piece of imaging software called Image Writer for Windows.  After downloading and installing this I was able to quickly image both my SD cards with the Raspbian .img file.

Here’s where I ran into my first problem.  I have a Dell monitor with HDMI input but I didn’t have it at Sector.  I had an HDMI cable with an HDMI to DVI converter but when I plugged it in all I got was a blank screen.  I tried it with both Pi’s and both of them did the same thing.  Ok fine, the Pi’s also have a composite video output so I tried that next.  Same problem.  For some reason when I plugged both the composite and HDMI/DVI in at the same time I suddenly got video out through the HDMI/DVI combo.  If I unplugged the composite or the HDMI/DVI neither output would work.  If I plugged them both back in then the HDMI/DVI would work.  At least it allowed me to get working on the thing.  Later on I switched to my HDMI monitor with a straight HDMI connection and everything was fine.  However, I did experience some weirdness in that occasionally I would get a weird “puttering” sound through the HDMI audio.  This happened on both Pi’s so I’m not quite sure what’s up with that.

I was finally up and running with a basic Linux image on my Pi.  Now it was time to try and get nodejs up and running.  I did some looking around the web and the best article I could find was this one from July.  It looked highly promising.  Here’s where I ran into my next gotcha.  While editing with VI I found that I couldn’t enter a # character on my keyboard.  I got around it by cutting and pasting a # from somewhere else in the document but a few minutes later when I needed to use the | character on the command line I knew I was going to have to fix the problem.

The image that is on the Raspberry Pi website was obviously generated by someone in the UK as the keyboard settings are set for a UK keyboard and this is what was causing me grief.  To fix this issue you first have to type in the following:

$ sudo dpkg-reconfigure keyboard-configuration
You’ll have to go through a few dialog boxes to select your keyboard and the region of US.  At one point you have to select Other to get to the other regions besides the UK ones.After finishing you can reboot the system or just do the following:

$ sudo invoke-rc.d keyboard-setup start
Moving on with a functional keyboard I followed the instructions in the article and downloaded the 6.15 node distribution and attempted to get it compiled on the Pi.  So here’s where things started to suck.  The first thing I found was it took anywhere from a 90 minutes to 2 hours to compile the v8 library on the Raspberry Pi.  I immediately, and by immediately I mean 90 minutes later, I ran into a problem when trying to link the library.  After searching around the net for a solution I found what I thought was my issue and recompiled.  90 minutes later I ran into another issue.  This went on for some time with trying different compiler options to get things working.  After 4 hours or so of frustration I decided to head home and work on it there.  Here came my next problem.  In my haste to head home I didn’t bother issuing a

$ sudo halt
so when I got home my SD disc image was corrupted and wouldn’t boot correctly.  Awesome.  So after a re-imaging of the card, upping the file system to use all the card, (I didn’t mention this earlier but you need to do this to use all the space on the card and it takes like 30 minutes), and fixing the keyboard thing I was ready to go back at it.Now for another woe.  The Pi has an option to overclock/overvolt it for better performance.  In the past this wasn’t recommended and could void your warranty.  As of the latest release there is a turbo mode that lets you crank up your 700MHz processor in a variety of steps to 1GHz.  However they note that you need to “test stability” as it’s dependent on your Pi and your power supply.

At this point I was getting pretty frustrated with compile times so I cranked that baby up to 1GHz, re-downloaded node and got to work compiling.  Unfortunately this ended really quick as for some reason the node compile died almost immediately.  I took a look at the file that wouldn’t compile and found that the text file was corrupted.  Turns out that my “stability” was not good.  I assumed that my power supply was not up to the job, so I cranked my CPU back down to 700 MHz and reformatted again to get rid of my corrupt files.

I continued to get nowhere with building node and spent a lot of time searching for other ways to get it to build.  I probably tried 3 different articles that people had posted as well as one binary distribution that immediately died with a segmentation fault.  Finally on Saturday morning I came across this gist.  This is the one that made it all happen.  Down near the bottom is the post from a month ago with the script that worked for them as well as me:

export NODE_VER=0.8.7
cd ~
rm -rf ~/work/node-build/node-$NODE_VER;mkdir -p ~/work/node-build && cd ~/work/node-build
rm -rf ~/opt/node-$NODE_VER;mkdir -p ~/opt/node-$NODE_VER

curl -O

curl$NODE_VER/node-v$NODE_VER.tar.gz | tar xz
cd node-v$NODE_VER
git apply --stat --apply ../arm-patches-2.patch

./configure --shared-openssl --without-snapshot --prefix=~/opt/node-$NODE_VER

date;time make CFLAGS+=-O2 CXXFLAGS+=-O2 install;date

If you copy this into a shell script and run it you should get an actual build of node 0.8.7 and npm that works.  After the build I was quickly able to install express and have a web site up and running on the Raspberry Pi.  I was also able to install the serialport library for nodejs and talk to an Arduino board over the USB connection (a topic for another day).

I was so excited to have node running that I even went ahead and compiled redis for the Pi as well.
I just pulled down the distribution off this link  and did a

$ make -j 2
When it’s done it will tell you to run “make test” which I did as well just for grins.  This takes quite a while to run but it passed everything for me.I’m really looking forward to messing around with this more.  A super cheap, super tiny embedded linux system that is powered by nodejs has got me fired up to put all sorts of stuff online.  A HUGE HUGE tip of the hat to Adam Malcontenti-Wilson for the gist that got me up and running.

Finally here’s the obligatory screenshot of my Raspberry Pi running the default Express installation on nodejs.



Yoga, Morse Code, and that Damn Song!

After an extended break I’m back to doing yoga 3 or 4 times a week.  I roll out for the 6 am class at Capital Fitness, grab a coffee on my way back from Pinkus Mcbride and by 7:15 I’m drinking it while catching up on the webs.

I really enjoy yoga.  It gives me an hour to center myself and pretty much changes my attitude for the day.  I can tell when I’ve been away from it.  It’s hard to get other tech guys to try it out but luckily I know a few who have and they’ve become converts as well.

Last Monday I got up, got all my stuff together and headed out the door at 5:50 A.M.  It takes me 5 minutes to walk to the studio so my timing was perfect. I got down to the elevators and after pushing the button I heard it.  There was a faint electronic sound coming from somewhere that was going “Beep beep beep, beeeeeep beeeeeep beeeeep, beep beep beep”.  3 short beeps, 3 long beeps, and then 3 short beeps.  Now maybe it’s because I’m old or was a boy scout, but I recognized that immediately as SOS, the international Morse code cry for help.

I tried to track the source but couldn’t get a bead on where it was coming from.  At the same time another tenant came out in scrubs obviously headed off to his job at a hospital somewhere.  I asked him if he heard the beeping and he said “Yeah it’s been doing that for a while.”  I said “Well that’s Morse code for SOS” and he responded, “Whoa you’re right, you should call our landlord or 911 or something.”  He then jumped in the elevator and took off.

Now there is no way I’m making it to yoga.  There are people out there who will roll into yoga class late.  I’m not one of them.  It’s just too disruptive and not good manners. I’m thinking calling 911 is not a great idea. The only solution is to call my landlord.

Our landlord is a pretty cool guy and he lives right above us in our building.  This is great since when something is wrong in the building it’s typically fixed immediately.  I happen to have his cell phone so I decided it was time to wake him up.  I went back to our apartment and gave him a ring.  After a sleepy “Hello” I explained what was up and I’m pretty sure he was thinking “WTF, why are you calling me about this” but he agreed to meet me at the elevators in a couple minutes.

After hearing the beeping from the air vent he agreed that something was up.  We headed down a floor and couldn’t hear anything, so we went back up a couple floors where the sound was loudly emitting from a service closet.  After unlocking it the cause was pretty apparent.  The drain for the building’s air conditioner was clogged and water was pooling in the closet.  My landlord had put a moisture meter in the room for this very occurrence and it was sending out the “SOS” message over and over.

I was a little pissed at this point.  Wouldn’t an annoying electronic “whoop whoop”, or siren, or anything other than “SOS” have been just as effective?  Perhaps not as it probably wouldn’t have stopped me in my tracks on the way to yoga if it had been anything else. But still……

Later in the day I sent him an email apologizing for getting him out of bed at 6 A.M. but that it would make a good blog post. His response was

"I was almost up anyway and better safe than sorry.  
You're right--you are likely the only person who knows the SOS sequence. 

Please be sure to list how quickly McBride responded too."

So if you’re ever looking for an apartment know that McBride Companies has awesome response time to apartment issues, even if they have annoying Flash Music on their website. Seriously go listen to it.

Thursday morning I went off for my usual 6 am Yoga class.  Before the class got rolling our instructor Erin said we’d be working on opening up for Hanumanasana, also known as the splits, not exactly my forte. She also said she had put together an inspirational playlist for the day.

Now  if you asked me to name what tranquil yoga song we’d be starting off with I can guarantee you that my first 10,000 guesses would not be the song that haunts my life, Europe’s Final Countdown.  If you remember, it was only a few months ago I last ran into this song outside my bedroom window.  When it came on I pretty much lost it. I was laughing so hard I couldn’t even pay attention to what was going on.

As a bonus here’s a couple of pretty decent yoga type tunes relating to the Monkey God,  Hanuman. One is by MC Yogi and the other one by Wah.


Sherman Hemsley – Peace

Sherman Hemsley left us yesterday and that sucks.

In the late 90s we were releasing our product ACID to the market and getting ready to hit COMDEX and NAMM (our largest trade shows).  One day our head of marketing Roy Elkins came up to me and said that he was considering using Sherman Hemsley as our spokesperson at the tradeshows.  Roy had been long time friends with Sherman and what many people didn’t know was Sherman was a musician.  Roy had hooked him up with a copy of ACID and Sherman was loving making his own music with it.

At COMDEX we had these giant laminated 10 foot tall head shots of Sherman.  When we came back I remember that one of those hung on the wall of our shipping department for years.  Every day you’d roll through there would be a giant Sherm staring at you.  There was something right about that.  One of the guys from that shipping department works in sales today at Sonic Foundry.  A couple years ago I asked him if he knew whatever happened to that poster. He wasn’t sure and we both were a little bit bummed that it’d been lost.  I have know idea where I’d ever hang it but I really wish I still had it.

A good friend of mine Steve who worked for Creative Labs, the makers of the Soundblaster card, came up to me one day during the convention.  As he stood looking over at Sherman he said, “You guys really have Sherman Hemsley as your spokesperson for ACID.  Man, I love you guys, you’re so weird!” He then quickly rushed over to meet him.

Later that evening Roy, Rimas, and I were sitting at a black jack table in the casino of our hotel.  Sherman had told Roy that he wanted to come down and hang with us for a while.  It was pretty apparent when Sherman had hit the casino.  I swear that every single table in that casino turned and looked when he went by.  You could hear people saying “Hey! isn’t that George Jefferson?”.

I didn’t get to spend a lot of time with Sherman, but from what I did I noticed a humble, sincerely nice man.  His voice always quiet and a huge smile as he met with adoring fans.  He loved music, and he loved making music.  I am lucky to have met him.

I have a lot of mementos from my days at Sonic Foundry, but this is one of my favorites.  At the shows we handed out CD’s with 3 tracks that Sherman had created using ACID.  His vocals are buried quietly in the tracks, much like the gentle soul that he was.  His simple message of “peace”, so representative of the man.  So where ever you are are Sherman Hemsley, “Peace”.



On my way!

I’m “On my way!” to Mexico for my annual house building trip.  Each year I join my dad and about 100 others to build 5 houses outside Tecate.    It’s always a test in connectivity since we stay at a small ranch with lots of bunk beds and iffy wireless.  It’s also a serious test of my rudimentary Spanish.

I fly out to San Diego a day ahead of time to buy tools and such so last night I dropped in a local Mexican restaurant to grab some food.  While I was waiting I heard a guy say to his girlfriend/wife “Not only are you ruining my life but you’re ruining my meal as well”.  Classy.

Can someone tell my why Apple decided that the auto-correct in the IPhone should change “omw” to “On my way!”.  Really Apple?  We don’t all know what omw means?  Someone there decided that we should all look super cheery with “On my way!”. I don’t know why this bugs me so much.

Nos vemos!

Automatic Teller UI, Can we fix this please?

While sitting in a restaurant last night I was watching the waitress use the touch screen POS system.  I’m always interested in the user interface of systems like this, and though it certainly seemed functional enough, I have to say that the button look and layout was just plain ugly.  I could only think “would it really have been that hard to pretty this thing up a bit.”

Earlier in the day I had stopped at my local Chase ATM to grab some cash.  The woman in front of me finished up her transaction and rushed off.  When I approached the screen I was met with the “Do you want another transaction?” screen.  While I was pressing the “No” response, I thought “Thank God I’m not somebody who would extract cash from this person’s account”.

Which brings me to one of my biggest User Interface pet peeves.  Why does this screen exist?  What programming genius decided that every person who ever uses an ATM should be asked if they would like to perform another transaction?  I have got to believe that literally 99% of all users walk up to an ATM and perform a single transaction.   Whoever designed this decided that it was better for 99 people to have to press NO, taking the chance that they walk away and have money stolen from their account, for the convenience of the 1 person who does multiple transactions.

Some bank web-sites even mention this in their ATM security section.  And I quote:

Make sure you have finalized the transaction and removed your card before leaving the ATM. Some ATMs ask if you want “another transaction”. You must reply “No” to close out your card’s transactions. If you do not close your card’s transactions and remove your card, the next ATM user can use your card.

The simple answer here is to do away with this screen. Let the 1 out of 100 users who actually wants to do a deposit and get some cash re-swipe his card and reenter his PIN.

Occasionally you still run into ATMs that have the “suck your card inside mechanism.”  A number of times I’ve watched people walk away counting their money leaving their card inside the machine.  I never understood why those machines don’t kick out the card and then dispense your money. No one is ever going to leave without their money.  It would’ve been so simple to just change the order of cash dispersion and card ejection and problem solved.

As a programmer these kinds of things make me nuts.  I’m hoping that the ATM industry did lots of research and there’s something I’m missing here. There is some mysterious reason why they chose to program these machines in this fashion.  My guess is it was someone not thinking about it, or someone who did, but thought that fighting to get the change made late in production was too much of a hassle.  No matter what the reason it’s not helping out the poor person who doesn’t have an honest person behind them when they forget to press No.

Using Webstorm or PHPStorm and Mocha for unit testing in Node.js

I have been working on a node.js project and decided I wanted to get some unit testing going .  I did some research and there are a lot of test frameworks out there for node.  You can use Jasmine, node-unit, Expresso, Mocha or a myriad of other frameworks.  Apparently this is a problem people have decided to solve over and over and over.  After a bit of research I settled on Mocha.  It’s written by the same guy who writes the awesome Express library and is well supported.
You can write your unit tests in a variety of formats whether you like BDD or TDD and you can write them in either javascript or coffeescript.  Mocha is pretty deep and supports all sorts of input and output formats. There is actually a great tutorial on peepcode called Full Stack Node JS that goes into a lot of stuff on getting started with node and has a lengthy section on testing with Mocha. Spend the $12 right now it’s worth it.
After you get done watching that you should be able to write some basic unit tests in javascript or coffeescript and run them from the command line using npm test.  I say “should” because like all things “node”, documentation is pretty sparse.  Be prepared to do some googling.
So now that I was able to write unit tests and run them from the command line I should’ve been happy as a clam right?  Wrong.  Typically when I’m writing code I like to write a test method and then run it in a debugger.  I did some searching around and couldn’t fine a way to do this with Webstorm, my choice of javascript editor.  I like Webstorm because you can debug your javascript from within the IDE and single step through the code. If you need to do PHP stuff you probably want to buy PHPStorm as it has all of the functionality of Webstorm plus the ability to work with PHP.  I bought Webstorm first but 6 months after the fact the people at JetBrains were nice enough to give me a discount when I upgraded to PHPStorm.
When you run the Mocha test framework it runs a node.js program that takes a list of test files on the command line.  I realized that if I could figure out a way to pass the files without having to use the command line I could probably debug my js files that are loaded by Mocha.  My plan was to run the mocha.js file from Webstorm in debug mode and that would then load up my test js files. After spending a few hours digging into the Mocha code, it looked like the plumbing was there for what I needed but it was still going to take some time to figure out exactly what to do.
I don’t know why but for some reason I decided to poke around a bit on TJ Holowaychuk’s blog (the author of Mocha).  I clicked on “About” which took me to the footer of his blog. By coincidence the last blog entry on the page from March 24th said:
“A new JS API was added, which mocha(1) now utilizes. This higher-level JS API will make it easier for those who want to script the testing process with Mocha. I have yet to document this API but it looks like this:”
There it was right in front of me.  20 lines of code that would help me do exactly what I needed to put together my own “runner” file for doing my unit tests in a project.  Holy stroke of luck! I found the “I have yet to document this API” statement to be quite humorous since you rarely find heavily documented node.js libraries.  Here’s what I’m doing to make my test files Mocha compatible as well as debuggable from within Webstorm.
First add Mocha to your node project by doing the usual “npm install mocha” and make a directory called test.  This is where all your tests will live.  You can make subdirectories for your tests if you’ve got lots of them but make sure everything lives in test.  In test you create a base file called testRunner.js.  This file has the code you need to load your other tests and it is the file you will run in debug mode from within Webstorm.
Your project should look something like this:
The code for testRunner is as follows
var testFiles=["test/_helper.js","test/tests.js","test/"];

var Mocha = require('mocha');

var mocha = new Mocha;


for (var i =0;i



var runner ={


The array at the top is where you put the names of the files that contain all your tests.  As you can see above I’m going to run 3 test files named _helper.js,tests.js, and  The _helper.js is stub file and all it contains is the follow line of code:
If you’re not going to write any of your test scripts in coffeescript then you don’t need to include this file.  If you are, then make sure it’s the first file in your list of tests.
The next lines of code load Mocha, create an instance of it, specify that you want to use the behavior driven development style of tests, add the test files, and then run them. When you run this from Webstorm the output from your tests wlll show up in the Webstorm console window and you can single step through the code for debugging.
I hope this helps some of the other people out there who were trying to figure out how to work with Mocha and Webstorm.

Programming with the IPad.. not so much

Lately I’ve been doing a lot of coding for WordPress and node.js. So with my dead laptop I wanted to see if I could get any work done on a recent trip with my IPad.

With my laptop I’ve got everything I need for this kind of development. I have WordPress running under IIS on my laptop and use Chrome with its built in debugger to debug html, css and javascript on the client side. For node.js I again use Chrome for client side debugging and Webstorm for code editing and server side debugging. I can quickly make code changes and see the results both client and server side. This is just not possible on the IPad.

First let’s look at the client side. On the IPad you don’t have the advantage of a nice client side debugger for web pages. You can turn on the Safari debug window in the IPad settings section but all this will show you is when you’ve got a Javascript error. It’s almost useless. I did find a tip for viewing the source of web pages. Basically it saves a short amount of Javascript into a book mark, which you then select when you’re on a web page. It runs the following code:


 var newDoc=sourceWindow.document;; 

 newDoc.write('Source of' +<br /><br /> document.location.href +<br /><br /> '');


 var pre=newDoc.body.appendChild(newDoc.createElement("pre"));


The code opens a new blank window. Writes an empty html page with the title “Source of” and the url of the current page. It finishes by appending the html source of the current page into a text element of the new page. Voila! You’ve got source.

Now for the server side. I have yet to find an “app” that lets me run node.js or the WordPress php software on the IPad. So basically I was stuck using the IPad as a terminal to a server. I needed two things to make this happen. First I needed a server on which to run WordPress and node.js. Second I needed to be connected to said server anytime I want to do work. The latter was a bit of a pain on this trip as even though the plane said it had wifi, it didn’t, and my AT&T; coverage in Georgia pretty much sucked as well as the DSL from Southern Bell. But putting aside the whole connection issue lets look at what it took to actually get up and running from a server standpoint.

There are a lot of hosting options out there these days but I wanted something I could get up and running quickly, inexpensively, and that let me at a command line interface.  The last requirement was so I could install and run any software I wanted for development. The thing that fit the bill was Amazon’s EC2 instance. Amazon has a variety of levels of cloud server that you can spin up for varying prices. The cool thing is that to get people started they allow you to run a micro instance for free for up to a year. This allows you to fire up your own linux server at their expense. You can’t get crazy with it and you surely don’t want to use it for any real production but for my purposes of doing light weight development it would do the trick.

Setting up an ec2 instance is relatively painless. There are a few things you’ll need to know including you need to edit your security settings to open up some ports. They’re all closed off at first and you’re going to need to open them up for node, http, and ssh. If you don’t do this it can be pretty frustrating at first trying to figure out why you can’t shell in to your instance.

You’re going to need something that allows you to ssh into your ec2 instance and the thing i use is putty for windows. You’ll need to set up putty to use your private key from amazon. Once you’ve done this you can bring up a shell on your ec2 linux instance and install pretty much anything you want. I installed both WordPress and node.js on mine, opened up the ports I needed and was ready to roll. I also installed mongodb as I needed a database for my node.js development.

There are two apps you’re going to want for working with the code on yourIPad in conjunction with your ec2 instance. These are Textastic a sweet little context sensitive code editor and Prompt by Panic. Prompt is an ssh client for the IPad that works really well. In fact I installed node.js and mongodb from my IPad using Prompt. The important thing to know is that both Textastic and Prompt will need to have key pairs to work with the ec2 instance and you will need Putty to generate those for you. Here’s additional info on hooking up ec2 with Prompt.

Once you’ve done all this you’re ready to make code changes on your ec2 instance from your IPad.

I got a call from Best Buy while I was out of town that my laptop was back from Asus and I literally stopped to pick it up on the way home from the airport. What I found is that while you can do work using the IPad I wouldn’t really consider it an alternative to a laptop for full on development.  I found myself frustrated not being able to do basic editing and debugging tasks without jumping through hoops. It’ll definitely get you out of a pinch if you want to log on a server and do some basic maintenance of code but that’s about it.

Maybe I’m missing something and I’d love to hear from others with suggestions for better methods of development or tools.

As an aside another tool I use alot and works fine from the IPad is This site allows you to edit code snippets of html,css, and javascript online and see the results immediately. You can save the code, iterate on it and share it with others. I highly recommend it.

In conclusion I’d say I actually did a fair amount of work. I’m just not sure I was really productive,  since the majority of the work I did was just setting up my IPad to prove the concept that I could do work with it.

Facebook making it interesting

I saw this letter Paul Graham put together for the Y-Combinator folks yesterday and I thought it was interesting.  When I was down at Tech Stars in April everyone was absolutely giddy about Facebook’s purchase of Instagram. It didn’t matter whether it was an organizer, participant, or investor they were all simply besides themselves with $$$ in their eyes over that acquisition.  I remember thinking “oh geez valuations of start-ups are going to be over the top now.”

It’s still too early to see what effect the Facebook IPO will really have but the one line I agree with 100 percent is this:

 “I often tell startups after raising money that they should act as if it’s the last they’re ever going to get. 

It reminds me of a conversation I had one time at NAMM with an unnamed band member from what you’d call a One Hit Wonder Band of the 80’s.  He told me that when they had their first (and only) hit that they blew all the money from it as they figured they’d just write another hit.  After all, they had it figured out now and it was easy.  Needless to say that didn’t happen.

Unfortunately I’ve heard this same kind of bravado now from a number of young entrepreneurs.  I often say “hey I could be wrong here, but…” and then try to impress on them how hard it can be to raise money.  The problem is when the first round is easy it’s often hard to convince them that the second might be harder.

I really hope they are able to keep their visions going if they need more capital. Even if they can’t I guess they can always go back to working a day job just like the one hit wonder bands ended up touring Brazil for years to come.