Monday, February 28, 2011

Supervisor for NodeJS

Supervisor runs your nodejs programs and restarts them when a *.js file changes

npm install supervisor

supervisor -p server.js -w .
This example runs server.js and watches the current folder, if a js file changes in this folder it restarts the server.js

Installing NodeJS from source on Snow Leopard

git clone
cd node

mkdir ~/local
./configure --prefix=$HOME/local/node
make install
export PATH=$HOME/local/node/bin:$PATH

Now if you open a new terminal window

node --version

you should see the new version number.

Get page response time with bash

(time curl URL --head) 2>&1 | grep real | cut -c 6-

for instance

(time curl --head) 2>&1 | grep real | cut -c 6-

the response is something like this

Sunday, February 13, 2011

CoffeeScript Syntax Checker Textmate Bundle

Here is a rudimentary version of my CoffeeScript bundle that performs a quick syntax check.
You can bind this command to CMD + S, so it runs after save.

CoffeeScript-Syntax-Checker-Textmate-Bundle on Github

Building CoffeeScript from source

CoffeeScript includes a simple build system similar to Make and Rake. Naturally, it's called Cake, and is used for the build and test tasks for the CoffeeScript language itself.

git clone
cd coffee-script

To build the whole system
bin/cake build:full

To build the script for inclusion in the browser
bin/cake build:browser
MINIFY=false bin/cake build:browser

you may need to install uglify-js as well
npm install uglify-js

Friday, February 11, 2011

Infinite webkit keyframe animation

Here is a simple example of an infinite animation.

@-webkit-keyframes infinite-spinning {
from {
-webkit-transform: rotate(0deg);
to {
-webkit-transform: rotate(360deg);

#box {
-webkit-animation-name: infinite-spinning;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
width: 100px;
height: 100px;
background: #00f;
<div id="box">

Thursday, February 10, 2011

Janus vs 'unable to determine script type'

Update 2011/02/14
Janus developers pulled my changes so if you checkout the latest code you won't see this problem.

Janus is a basic distribution of vim plugins and tools intended to be run on top of the latest MacVIM snapshot.

I tried to install it today but i got this 'unable to determine script type' error

I opened the Rakefile and figured out that the problem is that the does not response.

I looked for mirrors and found one on github, git://
I replaced all the lines with, it seems working now.

Here is the diff for the Rakefile

Wednesday, February 9, 2011

Get folder size on OSX

Haruka had this problem, here is a simple solution

du (abbreviated from disk usage) is a standard Unix program used to estimate the file space usage—space used under a particular directory or files on a file system.

Tuesday, February 8, 2011

You want to attend GoogleIO 2011?

I'm sorry, but you cant!
It was sold out in the first hour after the registration

Good luck in 2012 ;)

The good news is that the GoogleIO 2011 will be live-streamed and the videos will be available from the WebSite later.
Stay tuned!

Monday, February 7, 2011

Customized google maps

You change the look and feel of google maps easily.

Here is a simple example that turns off all labels on the map

map = new google.maps.Map(mapContainer, {}));

var noLabelStyle = new google.maps.StyledMapType([ {
featureType: "all",
elementType: "labels",
stylers: [
{ visibility: "off" }
}], {
name: "no_labels_style"

map.mapTypes.set('stylename', noLabelStyle);

The most important part is the google.maps.StyledMapType class.
Its constructor expects an array, and that describes which element should be visible and how.

You can find the details documentation in the API reference.

Editing files in the user's path

I have lots of scripts in my path but the actual location differs.

If i have to edit them i often do
vim `which FILE_NAME`

for example
vim `which port_utility`

The which utility takes a command name and searches the path for each executable file that would be run had this commands actually been invoke.

Apache on Snow Leopard, "ulimit: open files: cannot modify limit: Invalid argument"

When I started apache on my Snow Leopard i got a weird exception

/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

So I opened the script and found that there is something wrong with $ULIMIT_MAX_FILES

The error message says that 'cannot modify limit' so i changed its value to empty string

# ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

Voila, it works, but deeper investigation need.

Base64 encoding

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.
Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data.

to encode

openssl base64 -in INPUT_FILE -out OUTPUT_FILE

and to decode from Base64:

openssl base64 -d -in INPUT_FILE -out OUTPUT_FILE

Sunday, February 6, 2011

Email filtering with Sieve

Sieve is a programming language that can be used to create filters for email.

I use Sieve to manage my emails on the company's IMAP server.

require "fileinto";

if address :is "From" "" {
fileinto "Support";

elsif header :contains "Subject" ["Develop", "Codereview"] {
fileinto "Develop"

else {
redirect "";

Saturday, February 5, 2011

Finder shortcuts

Today I realized that i don't know enough Finder shortcuts, here you are.

Command-A Select All Items
Command-C Copy Selected Items
Command-D Duplicate Selected Items
Command-F Search with Spotlight
Command-H Hide Window
Command-I Open Get Info (Property) Pane

Command-M Minimize Window
Command-N Open New Window
Command-O Open Selected Items
Command-V Paste Items
Command-W Close Finder Window

Command-1 View as Icons
Command-2 View as Lists
Command-3 View as Columns
Command-4 View as Coverflow

Command-Shift-A Go to Application Folder
Command-Shift-H Go to Home Folder
Command-Shift-N Create New Folder
Command-Option-O Open File and Close Finder

Friday, February 4, 2011

Creating a NPM package

NPM is a package manager for node.

Creating packages with NPM is not difficult so here are the steps.

1. Creating the package.json

Here is an example
"name": "packagename",
"version": "0.0.1",
"description": "Package description",
"main": "package.js",
"keywords": [
"repository" : {
"type" : "git",
"url" : ""

2. Linking it with NPM

npm link

3. Publishing the package

First, you have to create a user in the repo.
npm adduser

Then you can publishing the package
npm publish

This is a good resource (Introduction to npm) but for some strange reason it was difficult to read, maybe the writing style.

Wednesday, February 2, 2011

Reload the browser when files change on OSX

Web front-end development often looks like this, you change the code, which can be HTML, CSS, JavaScript, Ruby whatever and then you head over to the browser and reload it to see the changes.

This is not a big deal, but what if the browser could automatically does the reload.

My solution has three parts.
  1. You can detect file change with Kicker.

  2. Set the focus to the browser and reload it with AppleScript.

  3. Set the focus back to your texteditor.

Let's combine these

kicker -e "osascript reload-browser.applescript;focus-textmate.applescript" FOLDER_TO_WATCH

In my case this looks like this

kicker -e "osascript ~/workspace/MacGyver/reload-browser.applescript;osascript ~/workspace/MacGyver/focus-textmate.applescript" src/

You can find the reload_browser.applescript here and the focus-textmate.applescript here.