Project: Allspark

Posted: May 11th, 2012 | Author: | Filed under: System | No Comments »

Case: Fractal Design Define Mini $129
CPU: Intel I7-3770T $280
Motherboard: ASRock Z77 Extreme4-M $139
PSU: PicoPSU-160-XT & EA11803A-120 $60 (2nd hand)
Memory: GSkill ARES F3-1600C10D-16GAO 2x8GB $129
HDD: 2TB Samsung HD204UI $110 (2nd hand)
SSD: Kingston SSDNOW S50 16GB $45
Misc: Various HDD cables $45


Find file created or modified within certain time range

Posted: April 14th, 2012 | Author: | Filed under: Linux | No Comments »
# ctime search in created at time
# mtime search in modified at time
# -1 in this example is 1 day
find . -type f -ctime -1 -exec ls -al {} \;
find . -type f -mtime -1 -exec ls -al {} \;
# this line search in between time
# this example search all file changed on 1st of Oct 2010
find . -type f -newermt 2010-10-01 ! -newermt 2010-10-02

Optimizing server running Magento

Posted: April 11th, 2012 | Author: | Filed under: PHP | No Comments »

Obviously the actual value depends on your hardware and website. These settings are for 3g RAM server. Might tweak further with more statistics coming in.

my.cnf of mysql

[mysqld]
key_buffer = 256M
max_allowed_packet = 32M
myisam_sort_buffer_size = 32M
tmp_table_size = 64M
table_cache = 512
sort_buffer_size = 4M
read_buffer_size = 4M
read_rnd_buffer_size = 2M
query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M
thread_cache_size = 8
innodb_buffer_pool_size = 128M
innodb_thread_concurrency = 6

apache.conf

KeepAlive on
KeepAliveTimeout 2
MaxKeepAliveRequests 100

Note: setting innodb_buffer_pool_size will cause innodb to fail


Git checkout previous deleted content

Posted: April 4th, 2012 | Author: | Filed under: Development | No Comments »
#Find the last commit that affected the given path. As the file isn't in the HEAD commit, this commit must have deleted it.
git rev-list -n 1 HEAD -- <file_path>

#Then checkout the version at the commit before.
git checkout <deleting_commit>^ -- <file_path>

#Or in one command, if $file is the file in question.
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

Source: http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo


Vagrantup worth look into

Posted: April 3rd, 2012 | Author: | Filed under: Development | No Comments »

http://vagrantup.com/


OSX Dotfile

Posted: April 1st, 2012 | Author: | Filed under: OS X | No Comments »

This looks good for devs on OSX.
https://github.com/mathiasbynens/dotfiles/blob/master/.osx


Running bash script at background

Posted: March 30th, 2012 | Author: | Filed under: Linux | No Comments »
# append & will run the script into background
./myscript &
# jobs will list background jobs
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

Add PPA repository to Ubuntu

Posted: March 30th, 2012 | Author: | Filed under: Linux | No Comments »
# need this to get add-apt-repository
apt-get install python-software-properties
# now add your ppa key
add-apt-repository ppa:whateverpackage/ppa

Trouble with Magento Extension Install? Try manual approach

Posted: March 28th, 2012 | Author: | Filed under: PHP | No Comments »

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.

http://freegento.com/ddl-magento-extension.php

http://miragedesign.net/tools/download-magento-extension/

BTW so far I don’t like Magento.


Some WordPress Resources

Posted: March 28th, 2012 | Author: | Filed under: PHP | No Comments »

http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

http://wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress/

http://wp.smashingmagazine.com/2011/11/17/wordpress-multisite-practical-functions-methods/

http://www.wpfunction.me/

http://wp-snippets.com/

http://perishablepress.com/code-snippets/


Server memory troubleshooting

Posted: March 25th, 2012 | Author: | Filed under: Linux | No Comments »
top
ps aux
ps auxw
pmap
vmstat
ps -A --sort -rss -o comm,pmem | head -n 11
free -m

NFS server on Mac

Posted: March 19th, 2012 | Author: | Filed under: OS X | No Comments »

http://ivanvillareal.com/osx/nfs-mac-osx-lion/
http://support.apple.com/kb/HT4745


Tunnel

Posted: March 16th, 2012 | Author: | Filed under: OS X, System | No Comments »

First establish the tunnel:

ssh -D 8080 -fCqN user@server.com

Then Mac System Preferences > Network > Advanced > Proxies
Tick “SOCKS Proxy”: localhost:8080


Bootstrap related websites

Posted: March 14th, 2012 | Author: | Filed under: PHP | No Comments »

http://wrapbootstrap.com/
http://bootswatch.com/


WordPress Template Hierarchy

Posted: March 13th, 2012 | Author: | Filed under: Development, PHP | No Comments »


Extend your jQuery selector

Posted: March 13th, 2012 | Author: | Filed under: JavaScript | No Comments »

Source: http://www.websanova.com/tutorials/jquery/12-awesome-jquery-selector-extensions

Example:

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

### Select everything that's current in "view" ###
$.extend($.expr[':'],
{
    inView: function(el)
    {
        var offset = $(el).offset();

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

Tighten up security

Posted: March 12th, 2012 | Author: | Filed under: Linux | No Comments »

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

Posted: March 7th, 2012 | Author: | Filed under: Development, OS X | No Comments »

First install homebrew if you haven’t already:
https://github.com/mxcl/homebrew/wiki/installation

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:
source: http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

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`
do
    if [ -f $LION_POSTGRES_DIR/$i ]
    then
        sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
    fi

    if [ -f $LION_PSQL_DIR/$i ]
    then
        sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
        sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i
    fi
done

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
CREATE EXTENSION adminpack;

Also, download pgAdmin:
http://www.pgadmin.org/download/macosx.php


Normalize.css

Posted: February 29th, 2012 | Author: | Filed under: CSS | No Comments »

https://github.com/necolas/normalize.css


Page Scroller plugin

Posted: February 22nd, 2012 | Author: | Filed under: JavaScript | No Comments »

http://pagescroller.com/