Monthly Archives: July 2013

Installing Node.js on Debian

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

An old version of Node.js is available in official repo for Debian Sid(unstable).

To build a package and install it on Debian (as root):

apt-get install python g++ make checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
./configure
checkinstall #(remove the "v" in front of the version number in the dialog)
dpkg -i node_*

To uninstall:

dpkg -r node

MySQL Database Backup and Restore

To backup or restore a MySQL database, use the following commands:

Backup:

# mysqldump -u db_user -p[password] [database_name] > dump_file.sql 

Restore:

# mysql -u db_user -p[password] [database_name] < dump_file.sql

The dump_file.sql file will include all the information necessary to drop and re-create any table contained therein. However, if you are using this dump / restore mechanism to keep a development database in a “as needed” sync with production, it would probably be best to add a step of entering into mysql and dropping / recreating the database. This is because the dump file will not remove any tables in your schema that are not contained in the dump file.

# mysql -u db_user -p
> drop database database_name
> create database database_name

Git: Push to Remote Branch

The push command has the form of

git push remote_name source_ref:destination_ref

 Example:

git push origin +branch42:branch42

The plus is optional and allows non-fast-forward updates.

Alternate syntax is

git push -f origin branch42

if you omit the destination, it’s implied that it’s the same name. If tracking is set up to a particular branch on the remote it will go to that one. The -f is –force.

Deleting branches has 2 syntaxes, the old:

git push -f origin :branch42

and

git push --delete origin branch42

The first is read as “push nothing into branch42” which deletes it.

One trick is that if you specify . as the remote name, it implies the current repo as the remote. This can be used for updating a local branch without having to check it out:

git push . origin/master:master

will update master without having to checkout master.

git: revert (reset) a single file

I’ve made the leap from subversion to git.  I really like git, but there are a few things that confused me.  One is how to (in svn terms) revert an uncommitted file back to the latest version of the file under source control.

git checkout filename

This will checkout the file from HEAD of the current branch, overwriting your changed file.  Since this is the same command used to checkout branches, if you have a file with the same name as a branch you have to make a slight change.

git checkout -- filename

You can also pull files from any location in your repository like this.  man git-checkout for all the details.

git checkout [<tree-ish>] -- [<paths>...]

If you need to revert (reset) all your uncommitted work, the command is

git reset --hard