Sep 19, 2013

Add Google Coder to my PiBang

Google Coder is a new Node.JS-based application to help kids create web pages that include HTML, JavaScript and CSS. Google releases it as a new distribution that based on wheezy Raspbian.

I don't want to re-invent the wheel, thus I try to add Google Coder to my current PiBang.
~ # cd ~git.d
~/git.d # git clone git://github.com/googlecreativelab/coder
~/git.d # cd coder/coder-base
~/git.d # npm install

Then I modified the coder/coder-base/config.js to make ensure it starts on the TCP ports that I want. See below:
exports.listenIP = null; //Defaults to *
exports.listenPort = '9181'; //the SSL port things run on
exports.httpListenPort = '9180'; //this will all be redirected to SSL
exports.cacheApps = true;
exports.httpVisiblePort = '9080'; //forwarded http port the user sees
exports.httpsVisiblePort = '9443'; //forwarded https port the user sees

Lastly, I can start it instantly with the command below:
~/git.d # cd coder/coder-base
~/git.d # npm start
Then, from another computer, I launched the browser and browse to my RPi at the URL https://192.168.1.[my-RPi-IP]:9181/ and create the password (for 'pi'). After that I just login again the newly created password and below is the screenshot:
Google Coder on PiBang 
P/S: If you want to configure the node.js to start automatic in PiBang (which using systemd instead of sysV), you will need the below. Below is my sample at /etc/systemd/system/coder.service
[Unit]
Description=Google Coder
After=network.target

[Service]
Type=simple
WorkingDirectory=/root/git.d/coder/coder-base
ExecStart=/usr/local/bin/npm start
Restart=always

[Install]
WantedBy=multi-user.target

Sep 10, 2013

Setup KeySequences and Bindings Manually

Recently, I switch from bash to zsh, and face some keys binding issue. The [Home] and [End] keys are not working like bash.

Then I learn a manual way to setup the correct key-sequences and binding them manually that will always work. For example, here's how I test the 3 key-sequences, [Home] and [End]:
$ cat > /dev/null
^[[1~
^[[4~
^C
Then, I setup the key bindings in my $HOME/.zshrc file:
bindkey '^[[1~' beginning-of-line      # Home
bindkey '^[[4~' end-of-line            # End
bindkey '^[[2~' beep                   # Insert
bindkey '^[[3~' delete-char            # Del
bindkey '^[[5~' vi-backward-blank-word # Page Up
bindkey '^[[6~' vi-forward-blank-word  # Page Down

Sep 9, 2013

Backup my RPi using Google Drive

Here's how I setup gdrive in my Raspberry Pi to backup things I want to Google Drive.

Install GDrive
After update my RPi, I install some additional packages and also GDrive.
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-filesystem-dev libboost-program-options-dev binutils-dev libboost-test-dev libqt4-dev libyajl-dev
 
$ git clone git://github.com/Grive/grive.git
$ cd ./grive
$ cmake .
$ make
 
$ mkdir ~/google_drive
$ cp ./grive/grive ~/google_drive

The 1st time to execute grive, I use the -a option in order to authenticate with Google. (You only have to do this once).

$ cd ../google_drive/
$ ./grive -a

The terminal will print out a very long URL. Copy and paste the URL to your browser, then click Accept button. From the browser, it will then print a long authentication code for you. Copy the authentication code an paste back to your terminal. Then the 1-time authentication is done.

Usually, I perform manual backup to my Google Drive. Just copy to google_drive folder and execute grive.

Below is an example of bash shell script to save your time.
#!/bin/bash
tar -zcvf /root/google_drive/backup_$(date +%y.%m.%d).tar.gz /etc
 
cd ./google_drive && ./grive
You may choose to setup a cronjob to execute the script as well.

Adding Node.js into Your Raspberry Pi

Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop. 
It contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache/Lighttpd/nginx, and allowing more control of how the web server works.

Here's an easy way to install/upgrade Node.js on your Raspberry Pi is to use n.
npm install -g n
and use:
n 0.10.17