Pre generate imagecache images

/**
 * Pregenerates an imagecache image.
 */
function imagecache_generate($presetname, $filepath) {
  if (!$preset = imagecache_preset_by_name($presetname)) {
    return;
  }

  $dst = imagecache_create_path($presetname, $filepath);
  if (!file_exists($dst)) {
    imagecache_build_derivative($preset['actions'], $filepath, $dst);
  }
  return $dst;
}

Increase MySQL max_allowed_packet size on Mac OS

  1. Create the following file: /etc/my.cnf
  2. Paste the following text:
    # The MySQL server
    [mysqld]
    max_allowed_packet = 128M
  3. Restart mysql and you're done!

Enabling Postfix on Mac OS 10.6

To send mail with PHP under Mac OS 10.6 (Snow Leopard), you need to enable the Postfix service. To do so, follow the following steps:

  1. Enable the mailserver:
    Open your terminal and type the following to open your hostconfig file:
    sudo vi /etc/hostconfig
    Add the following line:
    MAILSERVER=-YES-
  2. Configure Postfix:
    Open your the postfix configuration file with this command:
    sudo vi /etc/postfix/main.cf

Compiling PHP with PDO_MYSQL on Os X

First build the PDO driver:

$ pecl download pdo_mysql
$ tar xzf PDO_MYSQL-1.0.2.tgz
$ cd PDO_MYSQL-1.0.2
$ phpize
$ ./configure --with-pdo-mysql=/usr/local/mysql
$ make && sudo make install

Then configure PHP:

./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--enable-mbstring \
--with-curl=/usr/local \
--with-curlwrappers \
--enable-cli --enable-pdo \
--with-pdo-mysql=shared,/usr/local/mysql \
--with-sqlite=shared \

ls PHP

<?php
/**
* This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
* all files in that folder.
* Link : http://www.bin-co.com/php/scripts/filesystem/ls/
* Arguments : $pattern - The pattern to look out for [OPTIONAL]
* $folder - The path of the directory of which's directory list you want [OPTIONAL]
* $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]

Recursive copy dir

function recurse_copy($src, $dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}

Installing Apache+MySQL+PHP

sudo tasksel install lamp-server

Adding Users on Ubuntu

Adding a user on Ubuntu can be done this way :

adduser

It will ask you for everything needed for a user.
And makes a copy of the etc/skel user.

There is another way of creating users, but that's the geek way ;)

You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory. We’ll try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.

Installing FTP on Ubuntu

sudo apt-get install vsftpd

Change settings in this file, for welcome message ( this improves the security of your server, as the version info is not shown when connecting to the ftpserver )

/etc/vsftpd.conf

When you've changed something in this config file, you should restart the service with this command :

sudo /etc/init.d/vsftpd restart

or with:

restart vsftpd

--------------------
Changing the default ftp directory

$ cheat git

Setup
-----

git clone
clone the repository specified by ; this is similar to "checkout" in
some other version control systems such as Subversion and CVS

Add colors to your ~/.gitconfig file:

[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan

Highlight whitespace in diffs

[color]
ui = true