Diff properties files

Do you want to find updates in properties files after a new release of an alfresco-like java application? Just see following example script to diff two properties files and show differences…

list_missing_properties.php:

/**
 * Quick sample code to diff two properties files after update
 * see more @ http://louise.hu
 * 
 * Usage:
 * 	php list_missing_properties.php "file1.properties" "file2.properties" 
 * 
 * 
 * @author LouiSe@louise.hu
 */

$ppp = null;

$diff = propertiesDiff($argv[1], $argv[2]);
echo "Properties missing in \"".$argv[2]."\":\n\n";
foreach ($diff as $key => $value){
	echo $value."=".$ppp[$value]."\n";
}
echo "\n\n";

$diff = propertiesDiff($argv[2], $argv[1]);
echo "Properties missing in \"".$argv[1]."\":\n\n";
foreach ($diff as $key => $value){
	echo $value."=".$ppp[$value]."\n";
}
echo "\n";

function getAllPropertyNames($propArray) {
	
	$propertyNames = array();
	
	for($i=0;$i

PHP fork example

A simple example to create multi-threaded PHP application with pcntl-fork function.

Default PHP installation on OSX (Tiger and Leopard desktop and server too) missing pcntl modules, but Entropy version already contains it.

PHP source code for fork_example.php:

/**
 * PHP fork example by LouiSe@louise.hu
 */
$NUMBER_OF_THREADS = 5;

if(!function_exists('pcntl_fork')) {
	printf('Missing function pcntl_fork, compile php with "--enable-pcntl" option'."\n");
	exit();
}

$PIDs = array();

for($thread=0; $thread<$NUMBER_OF_THREADS; $thread++)
{
	$PID = pcntl_fork();
	if($PID == -1) {
	
		die('Unable to fork');
	
	} else if ($PID) {
		
		// the PARENT thread
		$PIDs[] = $PID;
	
	} else {
	
		// a CHILD thread
		echo "Thread:".$thread." PID:".getmypid()." - "; 
		
		// example function to print some text
		for($i=1;$i<10;$i++) {
			echo $i." ";
		}
		echo "\n";
		
		// exit from thread
		exit();
	}
}

// handling of normal child exit, avoid to create zombie processes
foreach($PIDs as $PID) {
	pcntl_waitpid($PID, $status);
}

Output on console:

server:~ louise$ /usr/local/php5/bin/php fork_example.php 
Thread:0 PID:31307 - 1 2 3 4 5 6 7 8 9 
Thread:1 PID:31308 - 1 2 3 4 5 6 7 8 9 
Thread:2 PID:31309 - 1 2 3 4 5 6 7 8 9 
Thread:3 PID:31310 - 1 2 3 4 5 6 7 8 9 
Thread:4 PID:31311 - 1 2 3 4 5 6 7 8 9 

SquirrelMail workaround for Mac OS X Server 10.5

Just small pieces of workarounds to avoid PHP warning messages in default webmail in Mac OS X Server 10.5 server.

The Webmail software is based on SquirrelMail (v1.4.9a), which is a collection of open source scripts run by the Apache server. For more information about SquirrelMail, see www.squirrelmail.org.

Squirrelmail as included with Mac OS X Server lets you remotely access your Inbox via a web-browser. It also automatically creates sub-folders to store drafts, sent, and trashed emails as done during a Squirrelmail session.

/private/etc/squirrelmail/config, line: 118

$domain = @getenv(SERVER_NAME);

/private/etc/squirrelmail/config, line: 1049

$provider_name = "SquirrelMail";                                                
$prefs_user_field = "user";                                                     
$prefs_key_field = "prefkey";                                                   
$prefs_val_field = "prefval";
$allow_charset_search = true;                                                   
$uid_support = true;                                                            
$default_use_mdn = true;                                                        
$pop_before_smtp = false;
$optional_delimiter = "detect";

/usr/share/squirrelmail/class/deliver/Deliver.class.php, line: 459

if (@strtolower($default_charset) == 'iso-2022-jp' && mb_detect_encoding($rfc822_header->subject) == 'JIS') {
  $header[] = 'Subject: ' . mb_convert_encoding($rfc822_header->subject, 'JIS') . $rn;
} else {
  $header[] = 'Subject: ' . encodeHeader($rfc822_header->subject) . $rn;
}

Picture box

Ma sehogy sem állt rá a kezem a kódolásra, ezért kódoltam egy kicsit… Pontosabban mást kódoltam, mint amit kellett volna, erre valahogy ráállt. Fura szerzet az ember keze, főleg ha egy fafejű, makrancos, akaratos agy irányítja.

Az eredmény egy képdoboz lett, ami pár CSS trükkel élvezetessé teszi a benne rejtőzködő kép előnézetét. Hogy cifrázzuk egy kicsit a dolgot, az engine ezeket a képeket véletlenszerűen választja ki egy könyvtárból, majd csap hozzá egy idézetet is.

Az eredmény a képre kattintva mutatkozik meg teljes valójában:

picture_box.png