Java JDK Install on Ubuntu

Posted on May 07, 2011

sudo add-apt-repository ppa:sun-java-community-team/sun-java6

sudo apt-get update

sudo apt-get install sun-java6

To show the used port on Mac

Posted on February 09, 2011

sudo lsof -i :8080

GIT Hook Post Push

Posted on February 03, 2011

This is a practice of http://toroid.org/ams/git-website-howto

1. create a bared repo

mkdir /git/website.git
cd /git/website.git
git init --bare

#create a deploy folder for the site
mkdir /git/www

# to set hook to checkout the latest code into /git/www
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/git/www git checkout -f
chmod +x hooks/post-receive

2. create a repo

mkdir /git/website
cd /git/website
# init repo
git init

echo 'Hello, world!' > index.html
git add index.html && git commit -m 'init'

# define the mirror and add master to it
git remote add web /git/website.git
git push web +master:refs/heads/master

# turn off the receive.denyCurrentBranch
git config --bool receive.denyCurrentBranch false

cat > .git/hooks/post-receive
#!/bin/sh
git push web +master:refs/heads/master

3. clone repo

cd /git
git clone /git/website dev
cd dev

echo 'a new file' > new.html
git add new.html && git commit -m 'add new file'
git push

Note, I have not tested it with ssh.

GIT SVN

Posted on January 22, 2011

git-svn on a bare git repository

http://john.albin.net/git/convert-subversion-to-git

GIT hook pre-commit remove white space

Posted on January 22, 2011

On Mac


#
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#

if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | sed -E 's/:[0-9]+:.*//' | uniq` ; do
# Fix them!
sed -i '' -E 's/[[:space:]]*$//' "$FILE"
done

On Linux (Ubuntu)

#
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' | sed -r 's/:[0-9]+:.*//' | uniq` ; do
# Fix them!
sed -i 's/[[:space:]]*$//' "$FILE"
done

Laptop connects to Sony Bravia with HDMI

Posted on November 24, 2010

When I try to connect my macbook with my 46″ Sony Bravia by a HDMI cable, I could not get any audio.

After searching on google, I realize that only HDMI 1 support PC-in audio. None of the other HDMI port support it.

Hence, my configuration is as following:
HDMI 1 -> macbook
HDMI 2 -> blue-ray
HDMI 4 -> PS3

Here is a problem. Why does Sony put HDMI1 and HDMI4 together?

My VIMRC

Posted on May 10, 2010

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set tabstop=4
set bs=2
insert mode
set smartindent

set mousehide
set mousefocus
set mouse=a
set mousem=popup

set autowrite
set ruler
set nohlsearch
set nocompatible

set suffixes=.bak,~,.o,.h,.info,.swp,.aux,.bbl,.blg,.dvi,.lof,.log,.lot,.ps,.toc

set diffexpr=MyDiff()
function MyDiff()
let opt = ‘-a –binary ‘
if &diffopt =~ ‘icase’ | let opt = opt . ‘-i ‘ | endif
if &diffopt =~ ‘iwhite’ | let opt = opt . ‘-b ‘ | endif
let arg1 = v:fname_in
if arg1 =~ ‘ ‘ | let arg1 = ‘”‘ . arg1 . ‘”‘ | endif
let arg2 = v:fname_new
if arg2 =~ ‘ ‘ | let arg2 = ‘”‘ . arg2 . ‘”‘ | endif
let arg3 = v:fname_out
if arg3 =~ ‘ ‘ | let arg3 = ‘”‘ . arg3 . ‘”‘ | endif
let eq = ”
if $VIMRUNTIME =~ ‘ ‘
if &sh =~ ‘\ let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ‘ . arg3 . eq
endfunction

MySQL Tree Traversal

Posted on May 03, 2010

Managing Hierarchical Data in MySQL

PHP Tree Traversal

Posted on May 03, 2010

Storing Hierarchical Data in a Database

1105_numbering

Phing DbDeploy

Posted on May 02, 2010

Detail of phing, please check here

Note: in the sql file set “–{space}//”. Otherwise the target won’t run successfully

Example build.xml (see below)
<?xml version=”1.0″ ?>
<project name=”Phing” basedir=”.” default=”init”>

<!– Sets the DSTAMP, TSTAMP and TODAY properties –>
<tstamp/>

<!– Load our configuration –>
<property file=”./build.properties” />

<target name=”init” description=”Init Function”>
<echo msg=”do nothing” />
</target>

<target name=”build” description=”Default Function”>

<property name=”build.dbinit.initfile” value=”${build.dir}/db/init/000_init_db.sql” />
<exec command=”${progs.mysql} -h ${db.host} -u ${db.user} –password=${db.pass} &lt; ${build.dbinit.initfile}”
dir=”"
checkreturn=”true” />

</target>

<!– create our migration task –>
<target name=”migrate” description=”Database Migrations”>

<!– load the dbdeploy task –>
<taskdef name=”dbdeploy” classname=”phing.tasks.ext.dbdeploy.DbDeployTask”/>

<!– these two filenames will contain the generated SQL to do the deploy and roll it back–>
<property name=”build.dbdeploy.deployfile” value=”deploy/scripts/deploy-${DSTAMP}${TSTAMP}.sql” />
<property name=”build.dbdeploy.undofile” value=”deploy/scripts/undo-${DSTAMP}${TSTAMP}.sql” />

<!– generate the deployment scripts –>
<dbdeploy
url=”mysql:host=${db.host};dbname=${db.name}”
userid=”${db.user}”
password=”${db.pass}”
dir=”${build.dir}/db/deltas”
outputfile=”${build.dir}/${build.dbdeploy.deployfile}”
undooutputfile=”${build.dir}/${build.dbdeploy.undofile}” />

<!– execute the SQL – Use mysql command line to avoid trouble with large files or many statements and PDO –>
<exec
command=”${progs.mysql} -h${db.host} -u${db.user} –password=${db.pass} ${db.name} &lt; ${build.dir}/${build.dbdeploy.deployfile}”
dir=”"
checkreturn=”true” />
</target>
</project>