Thursday, August 12, 2010

Fixing blurry screenshots on Mac OS X

defaults write com.apple.screencapture type png
killall SystemUIServer

Saturday, May 29, 2010

Sending PHP otput to a file

function ob_callback($buffer) {
global $ob_file;
fwrite($ob_file, $buffer);
}

$ob_file = fopen('test.txt','w');
ob_start("ob_callback");

/* Here goes content. */

ob_end_flush();

Sunday, May 16, 2010

Thursday, May 13, 2010

Copying selected record from one MySQL table to another

In the case of existing table with the same structure:
INSERT table2 SELECT * FROM table1 WHERE [conditions]

Alternative syntax for a table with different structure:
INSERT table2 (columnA, columnB) SELECT column1, column2 FROM table1 WHERE [conditions]

Saturday, May 8, 2010

print_r() output to a file

ob_start();
print_r($array);
$output = ob_get_clean();
file_put_contents("log.txt", $output);

Saturday, May 1, 2010

Converting a date from MySQL to human readable format

date("M j, Y", strtotime($MySQLDate))

MySQL random integer in the range

To obtain a random integer R in the range i <= R < j, use the expression FLOOR(i + RAND() * (j – i)).

Friday, March 19, 2010

Installing GD Library on Mac OS X 10.5


— Open Terminal

  • sudo mv /usr/local/php5 ~/Desktop/php5.old
  • curl -O http://www2.entropy.ch/download/php5-5.2.5-6-beta.tar.gz
  • tar -xzf php5-*-beta.tar.gz
  • sudo mv php5 /usr/local/
  • sudo ln -sf /usr/local/php5/entropy-php.conf /etc/apache2/other/+entropy-php.conf
  • sudo apachectl restart
— Comment “#LoadModule php5_module libexec/apache2/libphp5.so in private/etc/apache2/httpd.conf

— Dump
php5.old folder from desktop

php.ini on MacOS X 10.5 (Leopard)


usr/local/php5/lib/php.ini

Monday, March 15, 2010

Reset MySQL auto increment value


ALTER TABLE tablename AUTO_INCREMENT = 1


This will reset the next auto increment value to current largest value in the auto increment column + 1.