A Decentralized Internet?

I believe that the internet is truly the most important invention the world has ever seen. It gives the world of knowledge to the masses and is not controlled by any one person.

The last remaining problem with the internet is that all traffic routes through internet servrice providers (ISP’s). Each and every single request you ever make to the world wide web at some point routes through your ISP, and ISP’s are controlled by whom?

ISP’s are the last blockade to true freedom of speech and knowledge.

I recently stumbled across something called Maidsafe.


Is this a solution?

Persisting sessions between node js app restart with redis and passport js

Install Redis onto your server & start

Redis is a “NoSQL” key-value data store. More precisely, it is a data structure server. Not like MongoDB (which is a disk-based document store), though MongoDB could be used for similar key/value use cases. The closest analog is probably to think of Redis as Memcached, but with built-in persistence (snapshotting or journaling to disk) and more datatypes.

Similar to a MySQL server or a Mongod server, Redis needs to be installed and run for your app to be able to establish a connection.

apt-get install redis-server

After installed to your server, run this command to start it, the default port it will be listening on should be 6379:


Now to your node app.

First, include the connect-redis and redis to your package.json file eg:

“name”: “node-app”,
“main”: “server.js”,
“private”: true,
“version”: “0.0.0”,
“description”: “A new app with redis”,
“homepage”: “none set”,
“dependencies” : {
“body-parser”: “~1.0.0”,
“connect-flash” : “~0.1.1”,
“cookie-parser”: “~1.0.0”,
“bcrypt-nodejs” : “latest”,
“express” : “~4.0.0”,
“express-session”: “~1.0.0”,
“html-to-text” : “latest”,
“http-auth” : “latest”,
“method-override”: “~1.0.0”,
“mongoose” : “~3.8.1”,
“morgan”: “~1.0.0”,
“passport” : “~0.1.17”,
“passport-local” : “~0.1.6”,
“passport-facebook” : “~1.0.2”,
“passport-twitter” : “~1.0.2”,
“passport-google-oauth” : “~0.1.5”,
“connect-redis” : “latest”,
“redis” : “latest”,

“swig” : “~1.4.2”
“scripts”: {
“postinstall”: “bower install”,
“prestart”: “npm install”,
“start”: “node server.js”

Install the new dependencies

npm install

Next, require them in your kickoff file, for me it is server.js:

// get all the tools we need
var express = require(‘express’),
app = express(),
bodyParser = require(‘body-parser’),
cookieParser = require(‘cookie-parser’),
flash = require(‘connect-flash’),
mongoose = require(‘mongoose’),
morgan = require(‘morgan’),
passport = require(‘passport’),
path = require(‘path’),
session = require(‘express-session’),
redis = require(‘redis’),
RedisStore = require(‘connect-redis’)(session),

swig = require(‘swig’);

Now start a redis client which will be passed to the session construct.

var redisClient = redis.createClient();
redisClient.on(‘error’, function(err) {
console.log(‘Redis error: ‘ + err);

Now simply pass your redis client to the session construct like so:

store: new RedisStore({
client: redisClient
secret: ‘secrettokensfjkjkdf’

And that is it, your node app should be able to persist session data between app restarts.

Local to dev server running a node instance via rsync on windows

The following setup is good for remote teams, it allows everyone from directors to developers to view the work in progress. It keeps the dev’s computer light ie no local node required just a good ide or editor.

Step 1 – Download and install cygwin

https://cygwin.com/  Download the cygwin setup.exe file. Move the .exe file to a new location, eg “C:\cygwin_install_directory\cygwin.exe”.

The first run through the setup will create install the all the basics and the cywin terminal.
First run through:
1 – Now run the setup-x86_64.exe, choose the first option “Install from internet”.
2 – On the next screen leave the default install location to be “C:\cygwin64”.
3 – On the next screen set the “Local Package Directory” to be the folder you created at the start.
4 – Connection type, whatever suits.
5 – Choose a mirror to download from.. I have always used the cygwin.mirror.constant.com
6 – Just click next and whatever else follows to finish the install.

You should now have a cygwin terminal available, this is a linux style terminal. In “C:\cygwin64” you will find a std linux directory structure. You don’t have much else yet, ie no ssh or rsync or basically anything.
Second run through, you need to download nano, ssh and rsync:
1 – Run the setup-x86_64.exe again and use the above settings, ie same local package dir and same mirror.
2 – When you land at the “select packages” dialogue box it should look like this:
select cygwin pachages
3 – Don’t just install everything as it takes about a week to get it all, also you only a fraction of what is available. You will have to run this each time you want something new, ie 3 times for nano, ssh and rsync. Start by searching for “nano”. The interface is horrid. After searching for “nano” where it reads “Install” in the image below it should read default on your screen, press the word “Default” and it should switch all the options below to install… the interface really had no thought put into the design:
cygwin intsall
4 – Just hit next and it will download and install “nano” to c:\cygwin64.
5 – Repeat the last four steps for ssh then rsync.

You now have rsync ready to go on you machine, you now just need to add the path to the binaries to your $PATH environment variable.
1 – Go to “Control Panel\All Control Panel Items\System” then click “Advanced system settings on the left”
2 – On the “advanced tab” click the “Environment variables” at the bottom.
3 – Might as well add the new path to the globals, in the second box scroll down and click to edit the Path variable and add your new option which should be “C:\cygwin64\bin;” like this:
windows path variable
4 – You now have all the unix tools in your windows cmd, eg to list the contents of a folder both the windows “dir” and the unix “ls” will work. You also have a right click with normal options that cmd bizarely missed out, if think cmd was designed by a chimp on drugs. Here’s a list of some basic unix commands: http://mally.stanford.edu/~sr/computing/basic-unix.html

Step 2 – SSH keys between your local machine and the dev server

You should now have ssh and rsync available to your windows command prompt which means any programs on your local machine have access to rsync, however you don’t want to be entering your password every single time you want to run rsync on your local file set to push changes to your dev server. This is where ssh keys come in.
Create your key set
1 – Open your cygwin terminal.
2 – Run “cd ~” to make sure you are in you users home directory.
3 – Run ssh-keygen
4 – Just press enter and accept all the defaults.
5 – This will have created a new folder “/home/john/.ssh/” with two files inside “id_rsa” and “id_rsa.pub”. List the contents of the folder to see the hidden “.ssh” folder with the options “l” and “a”:  ls -la

Now you just need to place the public key onto the dev server.
1 – The id_rsa.pub is what goes on the server, run cat on the file to display: cat .ssh/id_rsa.pub
2 – What the cat spat out you need to copy to the server. Open another cygwin terminal and ssh to your dev server: ssh bob@
3 – ensure you are in you home directory, cd ~
4 – If your home directory doesn’t have a .ssh folder in it, just run ssh-keygen to create it and accept all the defaults.
5 – Create/edit a file within .ssh/ called “authorized_keys”:
cd ~
cd .ssh
nano authorized_keys

6 – Right click and paste the contents of your public key, it is important that there are no line breaks in the key else shit wont work, each key must be on its own line and must occupy a single line only. Comments start with hash #.
7 – In nano there are a bunch of options listed at the bottom of the page. With the key pasted in, exit the file “ctrl + x”, it will be asking some Q’s at the bottom of the page, just press enter till you exit nano.
8 – If this is a new authorized key file set the permissions to 0600: chmod 0600 authorized_keys

That’s it, you should now be able to ssh to your dev server without being prompted for a password. Test this by logging out of the server and ssh’ing back in (‘logout’ from cli in the server to logout).

Running the rsync command

So far you should have the cygwin packages for ssh nano and rsync installed and you should be able to ssh to your dev server without being prompted for your password. Now lets try running rsync.

Try running this from a new cygwin terminal, obv with your own details in🙂
rsync -avz --delete –-chmod=ug=rwx,o=rx -e"ssh -p 22" /cygdrive/d/work/projectX/ john@

The command broken down,
-avz options are to do with compression and speed.
–delete this flag will delete any files it finds on the target that do not exist on the source.
–chmod=ug=rwx,o=rx This sets the permission of the files on the target, this is required on windows as permissions are handled differently between unix and windows. Without it you files would not have any permissions set at all
-e”ssh -p 22″ this flag saying use port 22 for the ssh connection
/cygdrive/d/work/projectX/ this is the source, note the trailing /. cygdrive is kind of like the mnt folder in linux, it is where other drives are accessed.
john@ this is the target note the trailing /
The / at the end of the paths there says to rsync, copy everything from within the folder.

See these two posts for linking rsync commands to editors: phpstorm/webstorm komodo edit/netbeans/eclipse

Keep your node alive and auto restarts during your rsync

pm2 is your friend here. This can keep your node application running even after you close your terminal. With the –watch flag, your node instance will restart each time a file is changed

pm2 start server.js –watch

After you have started your app you can tail the logs with

pm2 logs



Now you are all setup. Run an rsync command and watch your pm2 logs fly by in a cygwin terminal, save a file and give your graphics designer a shout to get him to look at something without having to get him to come over to you.

Creating a host entry on windows and macs

A computers hosts files is effectively a local domain name server… It is somewhere your computer will look first  before asking your ISP which IP to head to for any particular domain name, eg google.

The name of the file is “hosts” without a file extension.

Hosts files on macs, windows and linux are all the same (thankfully, just in different locations) and all must be edited by the computer admin account.

On windows the location is at:


To add an entry to your hosts file on windows:
1 – search for “notepad.exe” from the start menu
2 – right click and choose “run as administrator
3 – Once you get into notepad (after pressing Yes to the UAC popup) hit file > open
4 – Navigate to the above location ie: c:/windows/system32/drivers/etc/
5 – The drop down above open and cancel shuold read “Text Documents (*.txt). As we need to open our “hosts” file, choose “All files” and there should be a list of files appear.
6 – Choose the “hosts” file and open.
7 – There might be a bunch of stuff in there already. Just scroll right down to the bottom if so.
8 – Now enter you entry, for this example my ip is and my domain is john.test.com. The entry will then look like this on its own line:  john.test.com

9 – After entering the entry, just hit file save and close. Now when you point your browser to john.test.com (or whatever you entered) the browser will head off to or whatever IP you entered.

(on some older versions of windows a reboot was required to take note of the new entry, not on win7 or win8)

On macs and linux the location is:


1 – Editing the hosts file requires a terminal command prompt. Just search for it in spotlight or applications (on mac’s it is in /applications/utilities/terminal).
2 – With a terminal open type then press enter:


3 – You should be asked for your password, type it (you wont see your password being typed for security but it is being entered) then press enter.
4 – Now you to edit the hosts file. Try one of the following to access the hosts file:

nano /etc/hosts


pico /etc/hosts

5 – Hold ‘ctrl’ and then ‘v’ to scroll to the bottom of the page (there is no mouse).
6 – Type in your entry eg:  john.test.com
7 – Hold ‘ctrl’ and press ‘x’  at the bottom of the screen it should be asking something like:

“Save modified buffer….”

Press enter, then press enter again.

8 – You should now be out of the file. Close terminal. Your browsers should now go to when you enter john.test.com into the address bar.

Sync fileset from local to remote using default phpstorm tools

In a previous post I discussed syncing projects to remote servers using Komodo, Eclipse and Netbeans.

I have come to dislike all of the above editors and ide’s for various reasons. So, I thought I would give phpstorm a go, so far so good and here is how to run an rsync command…

phpstorm does come with some nice built in tools and ways to send your files to other places… but none of those options are via rsync. Phpstorm does allow you to create your own “External Tools” which is fine for this job. The external tool can then be hooked up to a shortcut and away you go.

Step 1 – Create the new “tool”

File > Settings > Tools > External Tools
Click the little green plus and a new box should popup, enter the details and save, eg (note that the program and parameters are separated here. Leave the working directory blank.):

Step 2 – Check the tool works

Check the tool works by running it manually: Tools > External Tools > rsyn…:

Step 3 – Linking the tool to a macro

Assuming that step 2 ran smoothly (if it did not, please visit here to trouble shoot the rsync command), record a macro that essentially does what you just did.

Edit > Macros > Start Recording Macro

Now repeat step 2.

After the rsync command has run, stop the macro:

Edit > Macros > Stop Recording Macro

Give it a name and hit save.

Step 4 – Linking the macro to a keyboard shortcut

File > Settings > Appearance & Behaviour > Keymap

By default on my installation the “Editor actions” is open, hit the tiny down arrow to close it.

Open the “Macros” folder and you should see the macro you just created, right click on it and you will see a few options… choose keyboard shortcut and assign a shortcut in the first box by pressing the shortcut you want to assign to it… eg ctrl+alt+r

If nothing is already assigned to this shortcut you are good to go, just hit ok then apply and you are good to go.

Unroot moto g 2nd gen

This post is taken from a few other posts around the net, but the firmware placed on a gdrive for you/me.  Also see:  http://www.techbii.com/how-to-manually-update-moto-g-2nd-gen-xt1068-to-lollipop/ to upgrade to lollipop. I had many issues with unrooting the handset, mainly around locking the bootloader.

Getting Prepared

1 – Get the 2nd Gen. Moto G firmware: GDrive or from filefactory but is a super slow on the non paid for service, a pain that i already went through and put on gdrive filefactory.com

2 – Download mini fastboot kit: mfastboot-v2.zip [mirror
3 – Download and install Motorola USB Drivers (alternate link) your computer. 
4 – Enable USB Debugging on your Moto G 2014: go to Settings> About and tab Build version 7 times to unlock Developer options. The go to Settings> Developeroptions and enable USB Debugging. 
5 – Charge your phone to ensure at least 70% battery. Restore Moto G 2014 to Stock


1 – Download the firmware file and extract it to a folder.
2 – Extract mfastboot-v2.zip and copy its content to the same folder where the extracted firmware files exist.
3 – Reboot your Moto G into the Bootloader Mode. Either…
a – Turn off your phone and then press and hold the Volume Down + Power buttons simultaneously for a few seconds. 
b – Connect your Moto G to computer using the USB cable. Open the firmware folder where you have copied the mfastboot files. Launch a command window, type the following command and press the Enter key: 
adb reboot-bootloader

4 – Now here is how to flash the stock firmware. Make sure the device is connected via USB cable and launch a command window from inside the firmware folder and type the following commands one by one: 

mfastboot.exe flash partition gpt.bin
mfastboot.exe flash motoboot motoboot.img
mfastboot.exe flash logo logo.bin
mfastboot.exe flash boot boot.img
mfastboot.exe flash recovery recovery.img
mfastboot.exe flash system system.img_sparsechunk.0
mfastboot.exe flash system system.img_sparsechunk.1
mfastboot.exe flash system system.img_sparsechunk.2
mfastboot.exe flash modem NON-HLOS.bin
mfastboot.exe erase modemst1
mfastboot.exe erase modemst2
mfastboot.exe flash fsg fsg.mbn
mfastboot.exe erase cache
mfastboot.exe erase userdata

5 – If you also want to lock your phone’s bootloader, type the following command and hit the Enter key: 
mfastboot.exe oem lock

6 – Finally, reboot your device by typing: 

mfastboot.exe reboot

7 – Your Moto G will reboot now but if it is unable to pass the boot screen, try this: 

a) turn off the device, 
b) go to Bootloader mode, launch command window wipe cacahe and userdata by issuing these commands: 

mfastboot.exe erase cache
mfastboot.exe erase userdata
mfastboot.exe reboot

8 – To relock the bootloader on your Moto G 2014, type the following command and hit the Enter key:
mfastboot.exe oem lock

Wait till your phone boots up. Done! You have successfully restored your Moto G 2014 to stock!