Node.js Compile & Run Script for Windows

When developing on node.js, I find that I do this routine a lot:

  1. Make code change
  2. Kill/restart node.js process
  3. Reload browser
Instead of switching between 3 windows, I decided to make a batch script (.bat) to do this for me. As an added extra, it also concatinates separate javascript files too.


c:
cd C:\yourworkingdirectory\
taskkill /IM node.exe /F
taskkill /IM firefox.exe /F
rm server.js
type globals.js game.js nodeserver.js > server.js
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "http://localhost/"
node server.js

 

 

P.S. Yes, sometimes I do develop in windows. Until AAA games are developed for linux I will continue occasionally.

Install and Setup Node.js to Run Forever

Install Node.js

$ sudo apt-get update
$ sudo apt-get install git-core curl build-essential openssl libssl-dev
$ git clone https://github.com/joyent/node.git && cd node

I had trouble using the latest (head) verson of node so I used an older version which is optional.
git checkout origin/v0.4
If you don’t want the older version, skip the previous command.

$ ./configure
$ make
$ sudo make install
$ node -v

 

Install Node Package Manager (NPM)

$ curl http://npmjs.org/install.sh | sudo sh
$ npm -v

 

Install Forever

Next, lets make it persistent using Forever, so once we logoff it still runs and will restart even if node throws an error.

sudo npm install forever --global

 

Make a Test Script

Create a file called test.js and paste this into it.

var util = require('util'),
http = require('http');

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello, i know nodejitsu.')
res.end();
}).listen(8000);

/* server started */
util.puts('> hello world running on port 8000');

 

Run it Forever (until you kill it)

forever start test.js

You should be able to see it here
ps axl | grep node
And here
forever list
You can kill it using
forever stop 0
Where 0 is the index of your code in the forever list.

Time to start javascripting.

References

Installing Node Wiki https://github.com/joyent/node/wiki/Installation

Installing Node.js and NPM on Ubuntu 11.04 http://www.giantflyingsaucer.com/blog/?p=2775

Keep A Node.js Server Up with Forever http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever

Keyboard Shortcuts For Reddit

Being a fan of Google Reader’s keyboard shortcuts, I decided to implement similar features in Reddit using a bookmarklet.

All you have to do is create a new bookmark, paste the following into it, then when you are in Reddit, click the bookmark.


javascript:var s=document.createElement("script");
s.type="text/javascript";document.body.appendChild(s);
s.src="http://www.garrows.com/reddit.js";
void(0);

The keys are:

  • j : next
  • k : previous
  • v : view selected in foreground tab
  • o : open selected in background tab
  • u : upvote
  • d : downvote
  • c : comments
  • s : share post
  • a : save post
  • h : hide post
  • + : increase bottom padding
  • - : decrease bottom padding

As a bonus feature, once you reach the last item, it will automatically load more at the bottom of the page.

 

Let me know what you think. Hopefully the wonderful developers at reddit will add this script to their standard page so you wont have to keep clicking the bookmarklet.

How to Migrate a Web Server Running Apache, MySQL, WordPress and Drupal

Well folks its time that my old home hosted server is retired. Which means I have to migrate all of my 5 websites to a new server. Thanks to the way apache, MySQL WordPress and Drupal work, its easy.

1. Copy Apache Config Files

# ssh username@oldserver

# scp /etc/apache2/sites-available/ user@newserver:/etc/apache2/sites-available/

This will copy all the apache config files over to the new server. Now enable all the sites you copied by creating a symbolic link for each .config file you copied in sites-enabled.

# ln -s /etc/apache2/sites-available/yourwebsite.com.conf /etc/apache2/sites-enabled/yourwebsite.com.conf

or use the command a2ensite which does the same thing for you

# a2ensite yourwebsite.com

Restart apache for the changes to take effect.
# /etc/init.d/apache2 restart

2. Copy Your Websites

# scp -r /var/www/ username@newserver:/var/www

Default WordPress and Drupal installs are just files and we have now copied them across. However all the content, comments etc are stored within MySQL so lets migrate that now.

3. Migrate MySQL

Start by being logged into the old server.

# mysqldump --all-databases -u root -p > backup.sql

# scp backup.sql username@newserver:/home/username/

# ssh username@newserver

# mysql -u root -p < backup.sql

What we did here was use mysqldump to script every database and its contents into several sql commands. Then we copied them to the new server and piped them into the new sql server. All our databases, users and table contents have been imported. Magic.

4. DNS Migration

Now all you need to do is reconfigure your DNS servers to point to the new IP address. Chances are your not hosting your own DNS server so you will have to update them using your provider’s web interface. A word of advice though, create a new entry like test.yourdomain.com and point it to the new server first to make sure everything works.

Update Dell Streak To Froyo Officially and Easily (without chewing up your 3G data)

EDIT:

There are some newer versions as of 30th November 2010 for more baseband numbers.
GAUSB1A111800: Streak_318_12821_00.pkg
GAUSB1A120900: Streak_318_12821_00.pkg
GAUSB1A121100: Streak_318_12821_00.pkg
GAUSB1A120621: Streak_319_12792_21.pkg
GAUSB1A120821: Streak_319_12792_21.pkg
GAUSB1A130112: Streak_324_0_12.pkg
GAUSB1A131312: Streak_324_0_12.pkg

Introduction

The long awaited Android 2.2 (Froyo) update from Dell has officially been released. Since I don’t have wifi at work and I don’t want to download 150MB over 3G I decided to do some reverse engineering upgrade pain free. I’m also heading out of town this afternoon so I couldn’t just wait until I got home.

My Specs

OEM Version: GAUSB1A111800

Current OS Version: 1.6

Carrier: Optus (Australia)

Unrooted. Unlocked (by default).

Warning

This update only works if your OEM Version ends in 00.

Procedure

0. BACKUP. Dell provides a nice program called ‘Backup & Restore’ in the Android market. Install and create backup.

1. Download the pkg file from http://mobileupdate.dell.com/PackageProductionLocations/Streak_315_12332_00.pkg on your pc or android. I used my pc and would probably recommend you to also to minimize chances of download corruption. When installing, it reveals itself as being built on 5 Nov 2010 at 1:16:55.

2. Copy it to your sdcard.

3. Rename it to Update.pkg

4. Turn off your phone.

5. Hold down the volume up, volume down and power button together until it turns on.

6. Select option 2 ‘Software upgrade via Update.pkg on SD Card’ by using your volume buttons and select with the shutter button.

7. Think, did you remember to backup?

8. Press the shutter button to begin.

9. Go get a cup of coffee because the install takes about 5mins.

10. Rejoice! If nothing went wrong, you should have booted up into Froyo.

Problems?

There have been a lot of reported problems with the build however I have been pretty lucky with this.

Originally, my standard browser wouldn’t load anything but every other application (opera, maps) would. I fixed this by removing a mystery proxy server that was in my APN settings.

If you have troubles with the newer build, you could try this older one http://mobileupdate.dell.com/PackageProductionLocations/Streak_309_0_00.pkg which worked for me originally.

Also, if you are finding it slow and laggy (which I’m not) you can try following these instructions http://forum.xda-developers.com/showthread.php?t=848487 but I haven’t tested this yet.

Let me know if anyone has any other problems.

How To Setup and Test Node.js, CouchDB and MongoDB

Introduction

A project using a combination of Node.js and CouchDB can solve some pretty difficult problems with ease. Since originally writing this, I decided to use MongoDB instead of CouchDB and have now added in the instructions. I am attempting to solve one that involves consolidating several conflicting data sources into one document orientated database while providing a web interface for reading and writing.

Article Scope

This article will detail how I setup Node.js, CouchDB and MongoDB on Ubuntu Server Edition and preformed a few experiments with the system. The scope of this article does not include how you should do it or go into any detail as to how you could do it. It will only detail how to replicate what I did.

Server Setup

Download and install VMware Player. I installed it on Windows 7.

Download Ubuntu Server Edition iso. I got version 10.10.

Create a new virtual machine on VMware player but do not start the install already. Simply select the “I will install the operation system later” option since we don’t want VMware to configure our install for us. I gave the installation a 10GB hard drive and 128MB of memory.

Start the virtual machine and mount the ubuntu ISO to the cd drive and install it. When asked what software to install I selected LAMP, OpenSSH, PostgreSQL, Samba and Tomcat Java Servers.

Install CouchDB, MongoDB & Node.js

CouchDB is easy to install since ubuntu has added it to their software repositories.

sudo apt-get install couchdb

MongoDB is just as easy

sudo apt-get install mongodb

Node.js is a bit trickier. The easiest way it to get it from the git repository. First install git if you haven’t already got it.

sudo apt-get install git

Then get the node.js source from git.

git clone git://github.com/ry/node.git

cd node

./configure

The configure script told me I was missing g++ and openssl. The openssl one was a bit tricky since I needed openssl, libssl-dev and pkg-config installed.

sudo apt-get install g++

sudo apt-get install openssl

sudo apt-get install libssl-dev

sudo apt-get install pkg-config

When you make ./configure happy, its time to make.

make

Now make a coffee because it takes a little while to compile.

sudo make install

One more thing, felixge has created “a thin node.js idiom based module for CouchDB’s REST API that tries to stay close to the metal”. Lets make life easier and install that.

cd ~/node

git clone git://github.com/felixge/node-couchdb.git

cd /usr/local/lib/node

sudo ln -s ~/node/node-couchdb couchdb

If everything worked correctly, we now have CouchDB and Node.js installed along with the node-couchdb library.

Tests Node.js

Lets check that the installs worked. The command node will take you to its console. Try these commands.

var sys = require('sys');

sys.puts('hello world');

This should simply print ‘hello world’. Pretty easy. Now lets make sure that the node-couchdb library works.

couchdb = require('couchdb');

This should print out some JSON if everything works.

Test CouchDB

CouchDB is a RESTful so to test CouchDB, we need a web browser. Installed lynx which is a command line web browser.

sudo apt-get install lynx

Now navigate to the default CouchDB page.

lynx http://localhost:5984/

It should simply display welcome and the version number in JSON.

Test MongoDB

MongoDB has a nice console so lets use that.

mongo
db.foo.save( { test : 'hello world' } )
db.foo.find()

This should print out something along the lines of { “_id” : ObjectId(“4cb82f963af8744e5572e430″), “test” : “hello world” }

Simple Website

Create a file called example.js and put the following example from node.js into it:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8000, "");
console.log('Server running at publicly on port 8000');

Now start the server

node example.js

You can now navigate to http://locahost:8000 and it will write Hello World. Unless you didn’t install apache, you probably wont be able to bind to port 80.

Coming soon: Testing Node.js and CouchDB to its full potential.

Make Google App Engine Development Server Serve Publicly

Ever wanted to quickly test that Google App Engine site on another computer without deploying but couldn’t because it only accepts localhost connections? Well it’s quite simple actually.

If you are using the command line add this argument to the end.
--address=

If you are using the windows launcher, select the application, click Edit > Application Settings…  then in the ‘Extra command line flags’ section, add in
--address=

This works because by default, the address arguement is ‘localhost’ which will restrict the server. However, leaving it blank will allow any host to connect to it.

You could even set up port forwarding on your router to allow anyone to connect if you dare.

Google Opens Phone Gallery

A new service has just opened from Google called the Google Phone Gallery http://www.google.com/phone/

Features Include:
  • Detailed technical specifications
  • Available operators
  • Side-by-side comparisons
  • ‘Buy from’ links
  • Sort by newest
  • Group by country
  • Group by manufacturers
  • Group by operators

Damn, I was hoping that I got the scoop on something. I was a couple of minutes late :(

Why I’m Excited About the New Arduino

Arduino UniMost would expect a newer version to have a faster processor, more memory and stuff like that. Although, there is one thing that makes me particularly excited… the new USB chip. Why?

We replaced the aging FTDI chipset with a custom made usb-serial converter built with an Atmel ATmega8U2 this provides lower latency and <snip> users will be able to reprogram the USB chip to make the board show up as a variety of USB devices (Keyboards, Mice, Joysticks, MIDI etc).

So why is this so exciting? This opens up a whole new world for Arduino developers who can finally make retail quality PC devices using the standard board without having to spend thousands of dollars as they have before.

Expect an explosion of creative devices in the coming months!

Source: http://arduino.cc/blog/2010/09/24/dinner-is-ready/

Disable Mobile Browser Zoom Function

After lots of searching, I struggled to figure out how to disable mobile browsers (i.e. Android/iPhone browsers) zoom function so I thought I would share it since its important for developing games and more advanced mobile sites.
I can confirm that the following works on the Android and iPhone browser. Unfortunately though it does not work on HTC’s custom browser that they have put on most of their Android devices. I have contacted them about this and they informed me that it is impossible. Not happy HTC.


<meta content='True' name='HandheldFriendly' />
<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' />
<meta name="viewport" content="width=device-width" />

Get Adobe Flash playerPlugin by wpburn.com wordpress themes