Monday, May 30, 2011

useful iterm2 shortcuts

iTerm2 is a good replacement for Terminal on OS X

Splitting the window: Command+D to split the window vertically, or Command+Shift+D to split the window horizontally.

Switching between the sub-windows: Command+[ or Command+] or Command+Opt+arrows

Fullscreen: Command+Enter

Saturday, May 21, 2011

req.body undefined in POST request in Express js

You have to use a bodyparser to process the body of a POST request

app.use(express.bodyParser());

and put this before the routing definition, like this

app.configure('development', function() {

console.log("Development mode");

app.configure(function() {
app.use(express.bodyParser());
app.use(app.router);
.....
});
});


here is the related google groups thread.

Sunday, May 15, 2011

bash history

Bash history preserved in ~/.bash_history there are a few ways to search it.
history | grep

history | grep git

the output would be like that
475 git checkout -f
479 gitx
481 git co sp/sprint1
487 git co master
488 git branch -D sp/sprint1
489 git br
491 git co sp/sprint1
496 git diff | gitx
502 git st
510 history | grep git


the followings will reference to line '502 git st'
> !502

# counting back from the last one
> !-1

# same as !-1
> !!

using the last event starting with 'git'
> !git



Or press Ctrl-R, and as you start typing the search goes back in reverse order to the first command that matches the letters you’ve typed.

Once you’ve found the command you have several options:

- Run it verbatim – just press Enter
- Cycle through other commands that match the letters you’ve typed – press Ctrl-R successively
- Quit the search and back to the command line empty-handed – press Ctrl-G


if you're using the history a lot you may want to add these line to your bash init file (~/.bash_profile)


# remove duplicates from the history
export HISTCONTROL=erasedups

# increases the history size
export HISTSIZE=10000

# ensures that when you exit a shell, the history from the session is appended to bash_history
shopt -s histappend


I copy and pasted from the following articles
working-with-history-in-bash, bash-history-reverse-intelligent-search, man history

i like Bash a lot.

top commiters on a git branch

You want to have a list of contributors sorted by number of commits?

git log --format=format:%an | sort | uniq -c | sort -r


will output something like that

1081 Mito
1033 sudo
872 Yusuke
478 morita
423 Yuki
396 Takahiro

Sunday, May 8, 2011

Sniffing Android Tablets

On Android devices the "Mobile" string in the User Agent indicates that the device would prefer a version of the website optimized for Mobile (small form factor devices).
Tablets don't have this, for example

Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; device Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1

unlike phones

Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1


This can be used to detect Android tablet devices

is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i


in context

def is_mobile?
is_iosmobile = request.user_agent =~ /iphone|ipod/i
is_androidmobile = request.user_agent =~ /android/i && request.user_agent =~ /mobile/i

return is_iosmobile || is_androidmobile
end



more on that here,
android-browser-user-agent-issues