<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>plasmid.co.uk &#187; Hacks</title>
	<atom:link href="http://plasmid.co.uk/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://plasmid.co.uk</link>
	<description>because life is faster in reverse ...</description>
	<lastBuildDate>Thu, 20 May 2010 23:07:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://plasmid.co.uk</link>
  <url>http://plasmid.co.uk/wp/favicon.ico</url>
  <title>plasmid.co.uk</title>
</image>
		<item>
		<title>Emulating *nix Shell with Windows Command Prompt</title>
		<link>http://plasmid.co.uk/2009/12/03/emulating-nix-shell-with-windows-command-prompt/</link>
		<comments>http://plasmid.co.uk/2009/12/03/emulating-nix-shell-with-windows-command-prompt/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 23:04:36 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[auto-complete]]></category>
		<category><![CDATA[autorun]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[CoreUtils]]></category>
		<category><![CDATA[doskey]]></category>
		<category><![CDATA[GnuWin32]]></category>
		<category><![CDATA[nix]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/?p=202</guid>
		<description><![CDATA[Ever tried to ls or rm under Windows?
With just a few minor adjustments the Windows Command Prompt (cmd.exe) can emulate the behaviour of your favourite *nix shell. Please note, this isn't a full emulation method - the existing Windows commands are being manipulated to appear as their *nix shell counterparts.
Note: This is for systems where [...]]]></description>
			<content:encoded><![CDATA[<p>Ever tried to <strong>ls</strong> or <strong>rm</strong> under Windows?</p>
<p>With just a few minor adjustments the Windows Command Prompt (cmd.exe) can emulate the behaviour of your favourite *nix shell. Please note, this isn't a full emulation method - the existing Windows commands are being manipulated to appear as their *nix shell counterparts.</p>
<p><ins datetime="2010-05-20T23:02:03+00:00">Note: This is for systems where unauthorized software is not permitted. If you administrate your own system, I highly recommend checking the <a href="http://gnuwin32.sourceforge.net/">GnuWin32</a>, in particular the <a href="http://gnuwin32.sourceforge.net/packages/coreutils.htm">CoreUtils package</a>.</ins><br />
<span id="more-202"></span><br />
<strong>Background</strong></p>
<p>This method involves simple implementation of the <a href="http://en.wikipedia.org/wiki/DOSKey">doskey macro utility</a>. For convenience, a Windows batch file (*.bat) will be used to wrap calls to doskey. Some small adjustments to the registry are necessary, so it is <strong>strongly advised that the registry is backed up</strong> before reading further.</p>
<p><strong>Create a Command List Batch File</strong></p>
<ol>
<li>Open a text editor of your choice (e.g. notepad).</li>
<li>The following are some examples of how to add a *nix command, with the Windows Command Prompt equivalent:<br />
<code>@ECHO OFF<br />
doskey sudo=runas /user:administrator $*<br />
doskey alias=doskey $*<br />
doskey ls=dir $*<br />
doskey rm=del $*<br />
doskey cp=copy $*<br />
doskey mv=move $*<br />
doskey clear=cls<br />
doskey reboot=echo The system is going down for reboot NOW!$T shutdown -r<br />
doskey restart=reboot<br />
doskey top=tasklist<br />
doskey traceroute=tracert $*<br />
doskey kill=taskkill /F /IM $*<br />
echo [%USERNAME%@%COMPUTERNAME%]$ *nix commands added<br />
</code></li>
<li>Save as a batch file somewhere on your system, <strong>e.g. C:\nix-cmd.bat</strong></li>
</ol>
<p>Please note: Not all commands will behave exactly like their counterpart, however these are some examples from my batch file.</p>
<p><strong>Enabling Batch File and Tab-key Auto-complete</strong></p>
<ol>
<li>Start->Run->regedit</li>
<li>To add auto-complete for...<br />
		... <strong>just your username</strong>:<br /><em>HKEY_CURRENT_USER\Software\Microsoft\Command Processor</em><br />
		... <strong>all system users</strong>:<br /><em>HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor</em>
	</li>
<li>Modify the key entries to reflect your system settings, although they should appear somewhat similar to the below:<br />
<div id="attachment_211" class="wp-caption aligncenter" style="width: 310px"><a href="http://plasmid.co.uk/wp/wp-content/uploads/2009/12/nix-cmd_registry.png"><img src="http://plasmid.co.uk/wp/wp-content/uploads/2009/12/nix-cmd_registry-300x71.png" alt="*nix cmd registry screen capture" title="nix-cmd_registry" width="300" height="71" class="size-medium wp-image-211" /></a><p class="wp-caption-text">*nix cmd registry screen capture</p></div></li>
</ol>
<p>If you want to use a different key for auto-complete (i.e. not tab), then change the CompletionChar and PathCompletionChar values to the desired hexadecimal character code.</p>
<p><strong>Footnote</strong></p>
<p>That is all there is to it! I mostly make do with the commands above - its just a nice little tweak to make the command prompt a bit more usable.</p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2009/12/03/emulating-nix-shell-with-windows-command-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List PHP extensions with functions</title>
		<link>http://plasmid.co.uk/2008/08/11/list-php-extensions-with-functions/</link>
		<comments>http://plasmid.co.uk/2008/08/11/list-php-extensions-with-functions/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 15:31:25 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Extension functions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP extensions]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/?p=58</guid>
		<description><![CDATA[This is a quickie I thought I'd put up on my break. Although it isn't exactly complex or ground-breaking, its nice to have it at hand if you wanted to see which extensions provide particular functions (without having to refer to php.net of course!)

	$exts = get_loaded_extensions();

	foreach($exts as $ext) {
		$flist[$ext] = get_extension_funcs($ext);
	}

	print_r($flist);

This is a nice starting [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quickie I thought I'd put up on my break. Although it isn't exactly complex or ground-breaking, its nice to have it at hand if you wanted to see <strong>which extensions provide particular functions</strong> (without having to refer to <a href="http://php.net">php.net</a> of course!)</p>
<pre lang="code" class="php">
	$exts = get_loaded_extensions();

	foreach($exts as $ext) {
		$flist[$ext] = get_extension_funcs($ext);
	}

	print_r($flist);
</pre>
<p>This is a nice <strong>starting point</strong> if you wanted to write a script that determines whether the server you're installing onto has the necessary PHP extensions loaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/08/11/list-php-extensions-with-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP GUID Exposure</title>
		<link>http://plasmid.co.uk/2008/08/06/php-guid-exposure/</link>
		<comments>http://plasmid.co.uk/2008/08/06/php-guid-exposure/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 14:15:29 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[easteregg]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP detection]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/?p=56</guid>
		<description><![CDATA[There's a neat little tutorial on how to access various PHP easteregg images at 0php. The author also describes how to prevent your server from displaying this image (to prevent outside users from being able to determine whether or not your server is running PHP).
I thought I'd make a little script that takes advantage of [...]]]></description>
			<content:encoded><![CDATA[<p>There's a <a href="http://www.0php.com/php_easter_egg.php">neat little tutorial</a> on how to access various <strong>PHP easteregg images</strong> at <a href="http://www.0php.com/">0php</a>. The author also describes how to prevent your server from displaying this image (to prevent outside users from being able to determine whether or not your server is running PHP).</p>
<p>I thought I'd make a little script that takes advantage of this easteregg and the inherent format of GIF image files to <strong>determine whether PHP is running</strong> on a remote server.</p>
<pre lang="code" class="php">
&lt;?php

	// Configuration.
	$url = 'http://www.example.com/'; // Replace with whichever URL.

	// Open the connection.
	$handle = @fopen($url.'?=PHPE9568F36-D428-11d2-A769-00AA001ACF42', 'r');
	if($handle)
		echo("Handle active...\n"); else
		die("Error creating handle!\n");

	// Import data into buffer.
	$buffer = fgets($handle, 4);
	if($buffer == 'GIF') // &lt;- part of the binary header for GIF files.
		echo("This server is using PHP!\n"); else
		echo("This server is <strong>NOT</strong> using PHP!\n");

	// Close up, clean up.
	$ret = fclose($handle);
	$handle = NULL;
	if($ret)
		echo('Success!'); else
		die('Failed to close handle!');

?&gt;
</pre>
<p>Don't forget to replace <code>$url</code> with the server address before using this script.</p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/08/06/php-guid-exposure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP 5.2.x __toString() Support</title>
		<link>http://plasmid.co.uk/2008/07/28/php-52x-__tostring-support/</link>
		<comments>http://plasmid.co.uk/2008/07/28/php-52x-__tostring-support/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 17:52:16 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[toString]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/?p=41</guid>
		<description><![CDATA[Since updating to PHP version 5.2.2 (which has been superseded yet again since this post) the default behavior of class objects is to raise an error when cast to a string (usually a 'Catchable Fatal Error', citing that the object could not be converted to string!).
This is quite irritating, as previously the default behavior would [...]]]></description>
			<content:encoded><![CDATA[<p>Since updating to PHP version 5.2.2 (which has been superseded yet again since this post) the default behavior of class objects is to <strong>raise an error when cast to a string</strong> (usually a 'Catchable Fatal Error', citing that the object could not be converted to string!).</p>
<p>This is quite irritating, as previously the default behavior would be to <strong>return a unique object identifier</strong>. However, there is a quick workaround for this problem should your script rely upon object string casting / this unique object identifier.</p>
<p><strong>The Fix</strong></p>
<p>When creating your class, add in __toString() as a function. This so-called '<em>magic function</em>' is called when trying to cast an object to string, such as <code>(string) $someObject</code>. The following combines this function with a call to <strong>spl_object_hash()</strong>, which provides an identifier hash for the object:</p>
<pre lang="code" class="php">
&lt;?php

class SomeClass {
	function __toString() {
		return spl_object_hash($this);
	}
}

$someObject = new SomeClass;
echo $someObject;

?&gt;
</pre>
<p>The above code is fairly self-explanatory and it saves you from at least a few of minutes banging your head on the table :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/07/28/php-52x-__tostring-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A faster object in_array() for PHP 5</title>
		<link>http://plasmid.co.uk/2008/03/30/a-faster-object-in_array-for-php-5/</link>
		<comments>http://plasmid.co.uk/2008/03/30/a-faster-object-in_array-for-php-5/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 22:02:56 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[casting]]></category>
		<category><![CDATA[in_array]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/2008/03/30/a-faster-object-in_array-for-php-5/</guid>
		<description><![CDATA[This is a fast and effective way of find an object in an array.
As of PHP v5.2.2 objects do not have a default response to being cast to (string). To make this tutorial work with newer PHP builds, use spl_object_hash() in place of string casting.
Introduction
When a new object is created in PHP it is assigned [...]]]></description>
			<content:encoded><![CDATA[<p>This is a fast and effective way of find an object in an array.</p>
<p><ins datetime="2008-04-12T19:24:25+00:00">As of PHP v5.2.2 objects do not have a default response to being cast to (string). To make this tutorial work with newer PHP builds, use <strong>spl_object_hash()</strong> in place of string casting.</ins></p>
<p><strong>Introduction</strong></p>
<p>When a new object is created in PHP it is assigned an internal numeric id value. The only way to destroy an object (thereby deleting its internal id) is to <strong>unset()</strong> or nullify (<strong>=NULL</strong>) all references to the object from within the script. It follows that when an object is destroyed, PHP will fill the lowest id available for the next object. For example: if objects with ids 4, 5 and 6 exist -  by destroying 5, the next two objects created in PHP will have id 5 and then id 7!</p>
<p><em>These rules can be exploited to provide a much faster object in_array()</em>!</p>
<p><strong>Theory</strong></p>
<p>Comparison of multidimensional objects will almost always be more processor intensive than string comparison. It occurred to me that a great deal of time could be saved by identifying objects in an array as strings. However, conventional approaches using serialize() tend to exacerbate the problem further as the function itself is quite slow. The following is the proposed function with a demo on how it could be implemented.</p>
<pre lang="code" class="php">

/***
	The proposed object_in_array function.
	***/
	function object_in_array($needle, $haystack) {
		/***
		Arguments:
			(object) $needle - The object being searched for.
			(array) $haystack - The array containing objects.
		***/
		$stringArray = array_map(create_function('$in','return (string)$in;'),$haystack);
		$objectString = (string)$needle;
		return in_array($objectString,$stringArray,TRUE);

	}

	/***
	Prepare an object needle.
	***/
	$needleObject = new stdClass;

	/***
	Prepare a sample array including the
	needleObject.
	***/
	$objectArray = array(
		new stdClass,
		new stdClass,
		new stdClass,
		$needleObject
	); 

	/***
	Uncomment the block  below to perform
	an analysis of a much larger array.
	***/

	/*
	for($i=0;$i &lt; 50000;$i++) {
		$objectArray[] = new stdClass;
	}
	$objectArray[] = $needleObject;
	*/

	/***
	Start time-stamp
	***/
	$timeStamp = get_micro_time();

	/***
	NOTE: The print() function is included
	in the time analysis as it doesn't contribute
	much to the overal time required.
	***/
	print(object_in_array($needleObject,$objectArray) ? "Found!\n" : "Not found!\n");

	/***
	End time-stamp and display.
	***/
	$timeStamp = round(get_micro_time() - $timeStamp,6);
	print("Search duration: $timeStamp ms");

	/***
	Auxillary timing function. Sorry,
	I can't remember where I got this function
	from or I would credit the author! Google it :-p
	***/
	function get_micro_time() {
		list($microSec, $sec) = explode(" ", microtime());
		return ((float)$microSec + (float)$sec);
	}
</pre>
<p>The above can be further optimised (clean-up the temporary array, etc.) but serves to show how the array can be <strong>copied</strong>, <strong>recast</strong> and used as <strong>a search reference</strong> for objects. Modification of the above to use the conventional in_array() or foreach() looping drastically increases the duration of the search! With very little modification to the code, the function could even return the object directly and retain the same array processing speed.</p>
<p><strong>A footnote...</strong></p>
<p>I had previously toyed with the idea of using a single array, casting the objects to strings and storing these as the key for each item (then using array_key_exists() ). If you're not too worried about using the array keys / don't use them to store useful data, this latter method can be ten-fold faster than the above example!</p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/03/30/a-faster-object-in_array-for-php-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Syntax Highlighter background-colour bugfix</title>
		<link>http://plasmid.co.uk/2008/03/27/google-syntax-highlighter-background-colour-bugfix/</link>
		<comments>http://plasmid.co.uk/2008/03/27/google-syntax-highlighter-background-colour-bugfix/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 01:50:01 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[Google Syntax Highlighter]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/2008/03/27/google-syntax-highlighter-background-colour-bugfix/</guid>
		<description><![CDATA[I found the background for each line of code wasn't expanding to fit the scroll-area properly when a wide piece of code was being viewed. This has been declared as an official bug and the workaround suggested by brucknerite works nicely.
I have made a few tweaks to his fix so that it displays properly on [...]]]></description>
			<content:encoded><![CDATA[<p>I found the background for each line of code wasn't expanding to fit the scroll-area properly when a wide piece of code was being viewed. This has been declared as an <a href="http://code.google.com/p/syntaxhighlighter/issues/detail?id=1">official bug</a> and the workaround suggested by <a href="http://code.google.com/u/brucknerite/">brucknerite</a> works nicely.<br />
I have made a few tweaks to his fix so that it displays properly on Wordpress. I've attached the culprit files to the end of this post.</p>
<p><strong>Download files</strong></p>
<p><a href='http://plasmid.co.uk/wp/wp-content/uploads/2008/03/shcore.js' title='shcore.js'>shcore.js</a> - upload to /scripts<br />
<a href='http://plasmid.co.uk/wp/wp-content/uploads/2008/03/syntaxhighlighter.css' title='syntaxhighlighter.css'>syntaxhighlighter.css</a> - upload to /styles</p>
<p><strong>* Having troubling getting shCore.js to compress using <a href="http://dean.edwards.name/packer/">DEP</a>. It's probably just a simple syntax niggle, so I will investigate this when I'm less busy!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/03/27/google-syntax-highlighter-background-colour-bugfix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Google Syntax Highlighter for WordPress</title>
		<link>http://plasmid.co.uk/2008/03/10/fixing-google-syntax-highlighter-for-wordpress/</link>
		<comments>http://plasmid.co.uk/2008/03/10/fixing-google-syntax-highlighter-for-wordpress/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 01:54:51 +0000</pubDate>
		<dc:creator>plasmid</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Syntax Highlighter]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://plasmid.co.uk/2008/03/10/fixing-google-syntax-highlighter-for-wordpress/</guid>
		<description><![CDATA[After installing the aforementioned plugin, I soon discovered the CSS was not being implemented correctly! It turned out that in my particular version of Wordpress, the default style.css file contained 'more specific' CSS properties than the plugin. This lead to the highlighted code looking weirdness... so I fixed it!
This is a 30 second hack - [...]]]></description>
			<content:encoded><![CDATA[<p>After installing the aforementioned plugin, I soon discovered the CSS was not being implemented correctly! It turned out that in my particular version of Wordpress, the default style.css file contained 'more specific' CSS properties than the plugin. This lead to the highlighted code looking weirdness... so I fixed it!</p>
<p>This is a 30 second hack - open the default style.css file and search: <code>html&gt;body .entry ul</code> and <code>html&gt;body .entry li </code>removing the <code>html&gt;body</code> part from each.</p>
<p>Open the 'SyntaxHighlighter.css' file for the plugin and change the the <code>.dp-highlighter ol li.alt</code> entry to look like this:</p>
<pre lang="code" class="css">
.dp-highlighter ol li.alt
{
	background-color: #fff;
	border-top: 0px;
	border-bottom: 0px;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://plasmid.co.uk/2008/03/10/fixing-google-syntax-highlighter-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.273 seconds -->
