Pear Code
Using INSERT IGNORE with MySQL to prevent duplicate key errors

INSERT IGNORE INTO mytable
    (primaryKey, field1, field2)
VALUES
    ('abc', 1, 2),
    ('def', 3, 4),
    ('ghi', 5, 6);

Colorized tail

tailcolor() {
    tail -f -n5000 $1 | perl -pe "s/$2/\e[1;31;43m$&\e[0m/g"
}

Display available memory on Linux / Ubuntu

cat /proc/meminfo

Compare Directories using Diff in Linux

Use this command:

diff -qr --exclude=.svn dir1 dir2|sort

-q = print result only where files are different

-r = recursive

—exclude = use it if something has to be excluded

How to trim non-breaking space in PHP

Use this snippet:

$trim = trim($text, " \xC2\xA0\n\t\r\0\x0B");

\xC2\xA0 is non-breaking space (alt+space in mac os x)

How to create *.tar.gz and *.tar.bz2 files

tar.gz:

$ tar -zcvf archive_name.tar.gz directory_to_compress

tar.bz2:

$ tar -jcvf archive_name.tar.bz2 directory_to_compress
How to exclude dir in grep

Add parameter —exclude-dir to the grep command:

grep -R --exclude-dir=example_dir "something" *
How To Clone or Copy a VirtualBox Virtual Disk

VBoxManage clonehd "DiskToClone.vdi" "ClonedDisk.vdi"
or
VBoxManage internalcommands setvdiuuid "CopiedDisk.vdi"

Terminal colors in Python

It depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here is some python code:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

    def disable(self):
        self.HEADER = ''
        self.OKBLUE = ''
        self.OKGREEN = ''
        self.WARNING = ''
        self.FAIL = ''
        self.ENDC = ''

To use code like this, you can do something like:

print bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC
Source: http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python
Python pretty print

Simply “print” show objects in ugly format. If you want to see object nice formatted use instruction below:

from pprint import pprint

data = data = [(1, {'a':'A', 'b':'B', 'c':'C', 'd':'D'}), (2, {'e':'E', 'f':'F', 'g':'G', 'h':'H', 'i':'I', 'j':'J', 'k':'K', 'l':'L'})]
pprint(data, indent=4, depth=3)
[   (1, {   'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),
    (   2,
        {   'e': 'E',
            'f': 'F',
            'g': 'G',
            'h': 'H',
            'i': 'I',
            'j': 'J',
            'k': 'K',
            'l': 'L'})]

The amount of indentation added for each recursive level is specified by indent; the default is one.

The number of levels which may be printed is controlled by depth. By default, there is no constraint on the depth of the objects being formatted.