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

Tuesday, April 26, 2011

my ~/.gitconfig file

[user]
name = Viktor Kelemen

[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
pager = true

[color "status"]
added = yellow
changed = green
untracked = cyan

[core]
pager = less -FRSX
whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol

[alias]
co = checkout
st = status
ci = commit
co = checkout
w = whatchanged
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative


You can find more about .gitconfig customization on Hackernews or on Stackoverflow

Thursday, April 21, 2011

Get HTTP status code with curl in bash


curl --write-out %{http_code} --silent --output /dev/null URL

and then wrapping it into a function

getHTTPCode () {
echo $(curl --write-out %{http_code} --silent --output /dev/null $1)
}

response=$(getHTTPCode URL)
echo $response

Monday, April 18, 2011

Failed to install db46 on Snow Leopard

I have a brand new macbook (2011/04/19) and have some trouble with installing db46 with ports

port install db46

fails badly and complains about dependencies.

The easiest fix is to install it without java (and you don't need java)

sudo port -v selfupdate
port clean db46
port install db46 +no_java


There are other articles about this problem, How to fix db46 problem macport installation
or MacPorts 1.8.2 fails to build db46 on Mac OS X 1.6.3