Posts tagged: javascript

Restart Forever.js After Reboot

I’m amid migrating from a Dreamhost shared server to a VPS. A benefit of this is the ability to have long running processes like node.js. I’m also migrating the back end for Menu Line George to Parse.com. My v1 process for recording the George calls was a kludge of scripts running on my home desktop to call via Skype. This was more a proof-of-concept than a long term solution. Now I’ll be using Twilio + node.js + Parse as my permanent solution, significantly reducing how much I’ll need to think about it on a daily basis.

The simplest way I’ve found to keep a node script running as a service is forever.js. If you’re new to node, I suggest checking it out. Otherwise, I’m sure you’ve heard of it.

I fired it up yesterday and it worked like a champ. That is, of course, until my VPS rebooted overnight for some reason and the call wasn’t made this morning. I found a handy little guide over at Hack Sparrow for creating a cron job to restart your node script with forever when the machine reboots.

First create a shell script like this one (I called mine app-starter.sh):

#!/bin/sh

if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
        export NODE_ENV=production
        export PATH=/usr/local/bin:$PATH
        forever start ~/example/app.js > /dev/null
fi

Then make the script executable:

chmod 700 ~/app-starter.sh

Now make cron run the script when the system is rebooted. Add this to your crontab (via crontab –e):

@reboot ~/app-starter.sh >> cron.log 2>&1

For the uninitiated like myself, use CTRL+K,X to save.

Thanks to Hack Sparrow for taking the time to share this.

via Hack Sparrow.

The Value of Documentation

Having been reared as a developer in Microsoft’s cozy little .NET world, I didn’t really appreciate the value of quality documentation until I ventured out into the wild jungle.

I’ve been using Appcelerator’s Titanium Mobile SDK for the past few months. It’s kind of become my Shere Khan here in the jungle. Theoretically, using Titanium Mobile is easier and faster than writing native code. This might be true if I didn’t waste so much time deciphering their documentation.

I made a button to toggle my table view’s editable status. The object had a property called editable, so that seemed to be what I wanted. After testing, however, all this did was toggle whether or not swipe-to-delete worked. What I really wanted was the little red minus sign to appear, and have the contents of each row shifted to the right to make room. After 30 minutes of trial and error, looking through TableViewRow properties, and searching their Q&A section (because Appcelerator has no official forums) I found that TableView actually has two properties: editable and editing.

 

image

 

Even after discovering this other property, I still had to actually test each one to see what they did. Apparently, “editable” toggles the swipe-to-delete, whereas “editing” toggles the minus-button-on-the-left thing. The two are independent of each other.

Thanks for saving me time, web based application framework!

Signed,

Bitter in Bossier