"; */ ?>


08
Sep 10

Convert String to Map in PHP

Let’s say I would like to have a PHP line:

image( "src => images/logo.png", "class => right", "alt => Company Logo" );

to generate a full blown HTML <img> tag:

<img src="http://www.dotkam.com/images/company-logo.png" class="right" alt="Company Logo">

For this I would need to translate these three function parameters:

"src => images/logo.png", "class => right", "alt => Company Logo"

into a MAP ( yes, PHP calls it an array, but it is in fact a MAP ):

imageTag (
    'src' => 'images/logo.png'
    'class' => 'right'
    'alt' => 'Company Logo'
)

Here is how it is done:

function image( ) {
 
    $validAttributes = array( 'src', 'class', 'alt' );
 
    foreach ( func_get_args() as $attr ) {
    	$attrMap = explode( ' => ', $attr ); 
    	if ( in_array( $attrMap[0], $validAttributes ) ) {
    		$imageAttrMap[ $attrMap[0] ] = $attrMap[1];
    	}
    	else {
    	    die( 'Configuration Problem: ['.$attrMap[0].'] is not a valid &lt;img&gt; attribute.' );
    	}
    }
 
    // .... validate 'src' is there, append imgTag string with all the attrs, echo it...
}

26
Aug 10

Cannot Start Microsoft Outlook. Cannot Open the Outlook Window

Sometimes I have to work on Windows boxes… Here is the fix:

C:\Program Files\Microsoft Office\Office12>outlook.exe /resetnavpane

26
Aug 10

Tomcat: Add Memory

sudo vi /usr/share/tomcat6/bin/catalina.sh

At the beginning of the file, after initial comment block add:

# setting JAVA_OPTS to perform
JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=384m -Xss128k"

Restart tomcat:

sudo service tomcat6 restart

26
Aug 10

Clean Hudson Workspace Before Build

In order to clean/delete the workspace before the build, “Add Build Step”, select “Execute Shell”, and use Hudson $WORKSPACE variable to delete the target directory:

rm -rf $WORKSPACE/target/*

Here is what it will look like:

clean hudson workspace before build

built-in support is on the way: HUDSON-3966


22
Aug 10

Gitolite: Does Not Appear to be a Git Repository

Have a user, whose public key was successfully added under “gitolite-admin/keydir” and whose rights were successfully configured under “gitolite-admin/conf/gitolite.conf”.

When this very user is cloning an existing, correctly configured repository, his/her identity ( public key ) is not being passed correclty => hence notice a password prompt:

$ git clone git@yourgitserver.com:your-project
Cloning into your-project...
git@yourgitserver.com's password: 
fatal: 'your=project' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

Here is the way to help out git / gitolite to understand which identity ( key ) to use:

$ vi ~/.ssh/config
host gitolite
     user git
     hostname yourgitserver.com
     identityfile ~/.ssh/mypubkey

Now changing “git@yourgitserver.com” to “gitolite” does the trick:

$ git clone gitolite:your-project
Cloning into your-project...
remote: Counting objects: 83, done.
remote: Compressing objects: 100% (77/77), done.
remote: Total 83 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (83/83), 156.45 KiB | 49 KiB/s, done.
Resolving deltas: 100% (3/3), done.

Notice, public key was successfully accepted => hence there was no password prompt, and the clone was successful.