Running bash script at background

# append & will run the script into background
./myscript &
# jobs will list background jobs
[1]+  Running ./myscript &
# fg [job number] will bring the job to foreground
fg 1
# Ctrl + z on a running script will suspend the job
# hit Ctrl + z
[1]+  Stopped ./myscript &
# To resume the job into background again
bg 1
# To completely terminate the job
# first back it to fg
fg 1
# then Ctrl + c

Trouble with Magento Extension Install? Try manual approach

Sometimes Magento refuse to install extension via Magento Connect. But you can always try to convert the extension to actual package and overwrite your existing installation. Of course, use with caution.

BTW so far I don’t like Magento.

Extend your jQuery selector



### Select everything that has ID on the tag ###
    hasId: function(el)
        return $(el).attr('id') !== undefined && $(el).attr('id') !== '';
$("#container :hasId");

### Select everything that's current in "view" ###
    inView: function(el)
        var offset = $(el).offset();

        return !(
            ( > $(window).height() + $(document).scrollTop()) || 
            ( + $(el).height() < $(document).scrollTop()) || 
            (offset.left > $(window).width() + $(document).scrollLeft()) || 
            (offset.left + $(el).width() < $(document).scrollLeft())
$("#container :inView");

Tighten up security

A list of things you can do to improve your (ubuntu) server security.

Install mod_evasive and mod_security

apt-get install libapache2-mod-evasive libapache-mod-security
mv /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf

Tweak php.ini (/etc/php5/apache2/php.ini)

# append those to disable_functions
# system,show_source,symlink,exec,dl,shell_exec,passthru,phpinfo,escapeshellarg,escapeshellcmd

allow_url_fopen = Off

open_basedir = /home/www-data/

Install curl so you can still grab remote files after fopen turned off

apt-get install curl php5-curl

Install fail2ban

apt-get install fail2ban

Let unattended upgrades

apt-get install unattended-upgrades
dpkg-reconfigure unattended-upgrades

Install PostgreSQL on Mac Lion via Homebrew

First install homebrew if you haven’t already:

Now install postgresql via homebrew

brew update && brew upgrade
brew install postgresql

Wait for everything to finish.

Create postgreSQL database:

initdb /usr/local/var/postgres

Fix conflict from Mac’s own postgreSQL:

BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
for i in `ls $BREW_POSTGRES_DIR`
    if [ -f $LION_POSTGRES_DIR/$i ]
        sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
    if [ -f $LION_PSQL_DIR/$i ]
        sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i

Also, make sure /usr/local/bin comes first in your /etc/paths. Run “brew doctor” to check if there is any path issue.

You need to fix those issues before install bundled stuff such as rails pg gem (if not, use “gem uninstall pg && gem install pg” to reinstall pg gem).

Start service:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

To stop service:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

To make postgreSQL auto start:

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To remove this auto start:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To upgrade from old version of this auto start (first remove auto start see previous section):

cp /usr/local/Cellar/postgresql/NEW.VERSION.ID/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To Install adminpack (so pgAdmin stop complaining):

psql -d postgres

Also, download pgAdmin: