<?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>code-diesel &#187; tools</title>
	<atom:link href="http://www.codediesel.com/category/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Taking screenshots of websites in PHP</title>
		<link>http://www.codediesel.com/php/taking-screenshots-of-websites-in-php/</link>
		<comments>http://www.codediesel.com/php/taking-screenshots-of-websites-in-php/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 04:40:48 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[libraries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2835</guid>
		<description><![CDATA[Taking screenshos of websites is not a frequent requirement for developers but can come handy on many occasions. Although there are some nice solutions on the web, a particular one I found very good is wkhtmltoimage. wkhtmltoimage is a simple shell utility which can be used to convert html to images using the webkit rendering [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2011/06/snapshot2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/06/snapshot2.gif" alt="" title="snapshot2" width="192" height="163" class="alignleft size-full wp-image-2838" /></a>Taking screenshos of websites is not a frequent requirement for developers but can come handy on many occasions. Although there are some nice solutions on the web, a particular one  I found very good is <a href="http://code.google.com/p/wkhtmltopdf/" rel="nofollow" target="_blank" >wkhtmltoimage</a>.  </p>
<p>wkhtmltoimage is a simple shell utility which can be used to convert html to images using the <a href="http://www.webkit.org/" rel="nofollow" target="_blank" >webkit </a>rendering engine, and <a href="http://qt.nokia.com/" rel="nofollow" target="_blank" >qt</a>.<br />
<span id="more-2835"></span></p>
<h4>Installation</h4>
<p>To get started we need to first download and install the shell program <a href="http://code.google.com/p/wkhtmltopdf/" rel="nofollow" target="_blank" >wkhtmltoimage</a>. Select the appropriate binaries for your platform. As I&#8217;m using Ubuntu 10, I downloaded the complied binary &#8216;wkhtmltoimage-0.10.0_rc2-static-i386.tar.bz2&#8242;. Extract it to a appropriate folder and you are ready to go.</p>
<h4>Getting your first snapshot</h4>
<p>The simplest way to get a snapshot of a url is through the following:</p>

<div class="wp_codebox"><table><tr id="p283510"><td class="code" id="p2835code10"><pre class="text" style="font-family:monospace;">wkhtmltoimage http://www.bbc.com bbc.jpg</pre></td></tr></table></div>

<p>This will fetch the www.bbc.com index page and save it as a jpg image. Below are a few  websites rendered using the wkhtmltoimage  tool.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/06/screenshots.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/06/screenshots.gif" alt="" title="screenshots" width="495" height="418" class="aligncenter size-full wp-image-2837" /></a></p>
<h4>Customizing the output</h4>
<p>wkhtmltoimage   comes with a plethora of options, a few are shown below, more options can be found in the <a href="http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltoimage_0.10.0_rc2-doc.html" rel="nofollow" target="_blank" >documentation</a>.</p>
<p>The default output quality of the program is set to &#8217;94&#8242; which can make the size of some images a lot bigger, but you can change it to your liking using the below option.</p>

<div class="wp_codebox"><table><tr id="p283511"><td class="code" id="p2835code11"><pre class="bash" style="font-family:monospace;">wkhtmltoimage <span style="color: #660033;">--quality</span> <span style="color: #000000;">50</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.bbc.com bbc.jpg</pre></td></tr></table></div>

<p>Also by default all the images on a page are rendered in the final image, but you can disable images in the final screen-shot using the following:</p>

<div class="wp_codebox"><table><tr id="p283512"><td class="code" id="p2835code12"><pre class="bash" style="font-family:monospace;">wkhtmltoimage <span style="color: #660033;">--no-images</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.bbc.com bbc.jpg</pre></td></tr></table></div>

<p>You can also set the output height and width of the image (in pixels) as below.</p>

<div class="wp_codebox"><table><tr id="p283513"><td class="code" id="p2835code13"><pre class="bash" style="font-family:monospace;">wkhtmltoimage <span style="color: #660033;">--height</span> <span style="color: #000000;">600</span> <span style="color: #660033;">--width</span> <span style="color: #000000;">1800</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.bbc.com bbc.jpg</pre></td></tr></table></div>

<p>or crop the image to a specified size;</p>

<div class="wp_codebox"><table><tr id="p283514"><td class="code" id="p2835code14"><pre class="bash" style="font-family:monospace;">wkhtmltoimage <span style="color: #660033;">--crop-h</span> <span style="color: #000000;">300</span> <span style="color: #660033;">--crop-w</span> <span style="color: #000000;">300</span> <span style="color: #660033;">--crop-x</span> <span style="color: #000000;">0</span> <span style="color: #660033;">--crop-y</span> <span style="color: #000000;">0</span> 
       www.bbc.com bbc.jpg</pre></td></tr></table></div>

<p>Sometimes the JavaScript on the webpage you are rendering can cause problems during rendering, preventing the program from saving the screenshot or causing a huge delay. In such cases you can ask wkhtmltoimage to not run JavaScript on the page while rendering.</p>

<div class="wp_codebox"><table><tr id="p283515"><td class="code" id="p2835code15"><pre class="bash" style="font-family:monospace;">wkhtmltoimage <span style="color: #660033;">--disable-javascript</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.bbc.com bbc.jpg</pre></td></tr></table></div>

<h4>Using with PHP</h4>
<p>Although this is not a pure PHP solution for taking screen shots, you can wrap the final command in a <strong>shell_exec</strong> function or download the &#8216;snappy&#8217; PHP5 wrapper from below. The original library is located <a href="https://github.com/knplabs/snappy" rel="nofollow" target="_blank" >here</a>, but as the source keeps changing the examples given here do not work, so use the library given below.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/snappy" rel="nofollow" >Download Snappy</a><br />
<span>Downloads : 840  / File size : 4.2 kB</span>
</div>

<div class="wp_codebox"><table><tr id="p283516"><td class="code" id="p2835code16"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">shell_exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wkhtmltoimage --quality 50 http://www.bbc.com bbc.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Below is a short code using &#8216;snappy&#8217; to take a screen-shot of bbc.com.</p>

<div class="wp_codebox"><table><tr id="p283517"><td class="code" id="p2835code17"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Tested on Ubuntu 10.0.4, requires PHP 5.3  */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> Knplabs\Snappy<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Knplabs/Snappy/Media.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Knplabs/Snappy/Image.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* 'wkhtmltoimage' executable  is located in the current directory */</span>
<span style="color: #000088;">$snap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wkhtmltoimage'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Displays the bbc.com website index page screen-shot in the browser */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: image/jpeg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$snap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.bbc.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>and with a few options added&#8230;</p>

<div class="wp_codebox"><table><tr id="p283518"><td class="code" id="p2835code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Tested on Ubuntu 10.0.4, requires PHP 5.3  */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> Knplabs\Snappy<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Knplabs/Snappy/Media.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Knplabs/Snappy/Image.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zoom'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">0.5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'no-images'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* 'wkhtmltoimage' executable  is located in the current directory */</span>
<span style="color: #000088;">$snap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wkhtmltoimage-i386'</span><span style="color: #339933;">,</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Displays the bbc.com website index page screen-shot in the browser */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: image/jpeg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$snap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.bbc.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In my opinion you should play with the shell program first till you get to know the complete options and only than use the &#8216;snappy&#8217; PHP wrapper.</p>
<p>In closing here is the snapshot of my site ,rendered at 50% quality (click to zoom).</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/06/codediesel-snapshot.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2011/06/codediesel-snapshot-89x300.jpg" alt="" title="codediesel-snapshot" width="89" height="300" class="aligncenter size-medium wp-image-2839" /></a></p>
<p>Happy rendering!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/taking-screenshots-of-websites-in-php/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Convert Adobe Flash FLA files into HTML</title>
		<link>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/</link>
		<comments>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 10:27:44 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Wallaby]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2802</guid>
		<description><![CDATA[With Adobe Flash not being natively supported by Apple iOS, there have been some attempts from programmers to convert Flash files to HTML, such as SmokeScreen and Gordon; which will help developers easily port existing Flash content to iOS devices (iPad, iPhone). Not to be left behind on its own turf, Adobe has come up [...]]]></description>
			<content:encoded><![CDATA[<p>With Adobe Flash not being natively supported by Apple iOS, there have been some attempts from programmers to convert Flash files to HTML, such as <a href="http://smokescreen.us/" rel="nofollow" target="_blank" >SmokeScreen</a> and <a href="https://github.com/tobeytailor/gordon/" rel="nofollow" target="_blank" >Gordon</a>; which will help developers easily port existing Flash content to iOS devices (iPad, iPhone). Not to be left behind on its own turf, Adobe has come up with its own conversion tool, &#8220;Wallaby&#8221;.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/03/flash_converter.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/03/flash_converter.gif" alt="" title="flash_converter" width="330" height="214" class="aligncenter size-full wp-image-2804" /></a></p>
<p>&#8220;Wallaby&#8221; is the codename for an experimental technology that converts Flash content (FLA files) into HTML 5. This allows you to reuse existing Flash content on devices that do not support Flash. Once converted to HTML, you can easily edit them using Adobe Dreamweaver or any other editing tools.<br />
<span id="more-2802"></span><br />
Wallaby comes as a desktop <a href="http://www.adobe.com/products/air/" rel="nofollow" target="_blank" >Adobe Air</a> application so you will need the <a href="http://get.adobe.com/air/" rel="nofollow" target="_blank" >AIR runtime</a> installed on your system to run the application.</p>
<p>Wallaby uses SVG instead of Canvas to recreate the output because SVG is rendered natively by the browser while Canvas is drawn with JavaScript, which tends to slow down the rendering. According to experiments carried out by Adobe, Canvas was a lot slower than SVG on portable devices. Another point cited by Adobe for favoring SVG is that of readability. Using Canvas lowers the readability of the HTML since the output becomes a program instead of markup as in SVG.</p>
<p>Note that as of now not all Flash Professional features are supported in the HTML5 format, so Flash files above average complexity will not be rendered properly. I tried converting a few FLA files but met with a few conversion errors, mainly that of incompatible file format. As Adobe is desperate to make its presence felt in the portable devices market, expect a more complete working product by 2011 end.</p>
<p>You can download Wallaby from <a href="http://labs.adobe.com/downloads/wallaby.html" rel="nofollow" target="_blank" >Adobe Labs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peeking inside FireFox using MozRepl</title>
		<link>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/</link>
		<comments>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 13:06:43 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2655</guid>
		<description><![CDATA[I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools [...]]]></description>
			<content:encoded><![CDATA[<p>I usually use Selenium for testing web applications or some quick screen scraping jobs. It is more than adequate for my purpose as most of the time I work on the back-end code. But if you spend most of your time working on Ajax, scraping and other JavaScript jobs, then you need more powerful tools at your disposal. The one I think you will find useful is MozRepl. With it you can connect to Firefox and other Mozilla apps, explore and modify them from the inside, execute Javascript, peek into HTML pages, examine functions and variables, all while FireFox is running.<br />
<span id="more-2655"></span><br />
<a href="https://github.com/bard/mozrepl/wiki#Emacs" rel="nofollow" target="_blank" >MozRepl</a> &#8211; a read-eval-print loop for Firefox &#8211; is a Firefox extension that acts like a TCP/IP socket server within Firefox. You can then connect to the socket using any client application and send commands to Firefox. Each command you send to Firefox using MozRepl is executed as if it was run from the browser, which gives you the ability to do anything that you would normally do using Javascript.</p>
<h4>Installing MozRepl</h4>
<p>Before proceeding you need to first install MozRepl which comes as a Firefox extension.  Head over to <a href="https://github.com/bard/mozrepl/wiki/" rel="nofollow" target="_blank" >github</a> to download and install. Once you have installed it, go to Firefox Tools menu and select MozLab → Start MozRepl. MozRepl will now be listening for connections on the default port 4242.</p>
<h4>Connecting to MozRepl</h4>
<p>Now that we have MozRepl up and running we can easily connect to it using Telnet. By default MozRepl listens on port 4242, which however you can change to your liking from the MozRepl menu.</p>

<div class="wp_codebox"><table><tr id="p265528"><td class="code" id="p2655code28"><pre class="text" style="font-family:monospace;">C:\&gt; telnet localhost 4242</pre></td></tr></table></div>

<p>You will get the following response if you are correctly connected to MozRepl.</p>

<div class="wp_codebox"><table><tr id="p265529"><td class="code" id="p2655code29"><pre class="text" style="font-family:monospace;">Welcome to MozRepl.
 - If you get stuck at the &quot;...&gt;&quot; prompt, enter a semicolon (;) 
at the beginning of the line to force evaluation.
 - If you get errors after every character you type, see http://github.c
om/bard/mozrepl/wikis/troubleshooting (short version: stop using 
Microsoft telnet, use netcat or putty instead)
Current working context: chrome://browser/content/browser.xul
Current input mode: syntax
&nbsp;
repl&gt;</pre></td></tr></table></div>

<p>If you have trouble connecting using Windows telnet or encounter some inconsistent behavior,  you can use <a href="http://www.putty.org/" rel="nofollow" >Putty</a> instead. A typical putty connection setup is shown below, note the &#8216;telnet&#8217; radio selection:</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png"><img src="http://www.codediesel.com/wp-content/uploads/2010/05/putty.png" alt="" title="putty" width="453" height="440" class="aligncenter size-full wp-image-2657" /></a></p>
<p>Also make sure you check the &#8216;Implicit CR in every LF&#8217; check box.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/12/putty-config.gif" alt="" title="putty-config" width="455" height="441" class="aligncenter size-full wp-image-2770" /></a></p>
<p>Once you are connected to the server you will be presented with the following prompt:</p>

<div class="wp_codebox"><table><tr id="p265530"><td class="code" id="p2655code30"><pre class="text" style="font-family:monospace;">repl&gt;</pre></td></tr></table></div>

<p>Lets try a standard greeting.</p>

<div class="wp_codebox"><table><tr id="p265531"><td class="code" id="p2655code31"><pre class="text" style="font-family:monospace;">repl&gt; window.alert(&quot;Hello World!&quot;)</pre></td></tr></table></div>

<p>MozRepl is now ready to accepts your commands. Lets try a simple one given below. The first line is the command we send to MozRepl to get the title of the current open Firefox window, while the second line is the response.</p>

<div class="wp_codebox"><table><tr id="p265532"><td class="code" id="p2655code32"><pre class="text" style="font-family:monospace;">repl&gt; document.title
&quot;Tutorial - mozrepl - GitHub - Mozilla Firefox&quot;</pre></td></tr></table></div>

<p>Lets try changing the document title of the current Firefox window:</p>

<div class="wp_codebox"><table><tr id="p265533"><td class="code" id="p2655code33"><pre class="text" style="font-family:monospace;">repl&gt; document.title = &quot;hello&quot;</pre></td></tr></table></div>

<p>Use the following to get all the function and variables in Firefox:</p>

<div class="wp_codebox"><table><tr id="p265534"><td class="code" id="p2655code34"><pre class="text" style="font-family:monospace;">repl&gt; repl.look()</pre></td></tr></table></div>

<p>This is just a sampler, you can do a whole lot of things using MozRepl, check this <a href="http://www.youtube.com/watch?v=5RSnHN6S52c" rel="nofollow" target="_blank" >video</a> for some more examples.</p>
<h4>Connecting to MozRepl with PHP</h4>
<p>As MozRepl creates a server on port 4242, we can easily connect to it via PHP and send commands to it. A small example is given below which you will need to run from the command line. The following code sends 3 commands to the MozRepl server and prints the responses. It uses the <em>socketHelper</em> class to do the dirty work of socket processing.</p>

<div class="wp_codebox"><table><tr id="p265535"><td class="code" id="p2655code35"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'socketHelper.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Commands to send to  MozRepl */</span>
&nbsp;
<span style="color: #000088;">$commands</span><span style="color: #339933;">=</span><span style="color: #009933; font-style: italic;">&lt;&lt;&lt;EOD
repl.whereAmI()
content.location.href = 'http://google.com'
repl.quit()
EOD</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$firefox_socket</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketHelper<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$commands</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//Skip blank lines</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$firefox_socket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send_command</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Code for <em>socketHelper</em> class</p>

<div class="wp_codebox"><table><tr id="p265536"><td class="code" id="p2655code36"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* socketHelper.php */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SocketHelper
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$port</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4242&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$socket</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_create</span><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span>SOCK_STREAM<span style="color: #339933;">,</span>SOL_TCP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">socket_strerror</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">socket_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/** Send a command to MozRepl */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> send_command<span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$command</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">socket_write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #000088;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #009933; font-style: italic;">/* 
        Read from the Socket until we get a &quot;repl&gt;&quot; prompt, 
        or loop forever.
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> read<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$chunk</span> <span style="color: #339933;">=</span> <span style="color: #990000;">socket_read</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">65536</span><span style="color: #339933;">,</span>PHP_BINARY_READ<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Error reading from socket<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chunk</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009933; font-style: italic;">//No more data</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|^(.*)\s*repl\d*&gt;\s*$|s'</span><span style="color: #339933;">,</span><span style="color: #000088;">$chunk</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$response</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$chunk</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Security Warning</h4>
<p>Because MozRepl can directly poke inside FireFox it can practically work with anything &#8211; your bookmarks, cookies, cache etc, so security should be your prime concern. So do not ever allow outside connections in MozRepl (Tools menu → MozLab → Allow outside connections), unless you are sure what you are doing.</p>
<p>I&#8217;m still investigating the things I can do with MozRepl. If you have done some cool things of your own using it, please post your ideas here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/peeking-inside-firefox-using-mozrepl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Increase your MySQL productivity with Toad</title>
		<link>http://www.codediesel.com/mysql/increase-your-mysql-productivity-with-toad/</link>
		<comments>http://www.codediesel.com/mysql/increase-your-mysql-productivity-with-toad/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 06:07:18 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2736</guid>
		<description><![CDATA[Recently my favorite MySQL Swiss Army Knife has to be Toad for MySQL. Not only does it have a plethora of tools and interesting features, it is free. A few days back I’d to compare database schemas of different versions of a application to see if some table fields had changed between versions. Comparing a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2010/10/toad-for-mysql.jpg"><img style="border: 1px solid #c0c0c0;" src="http://www.codediesel.com/wp-content/uploads/2010/10/toad-for-mysql-300x205.jpg" alt="" title="toad-for-mysql" width="300" height="205" class="alignleft size-medium wp-image-2737" /></a>Recently my favorite MySQL Swiss Army Knife has to be <a href="http://www.toadworld.com/DOWNLOADS/Freeware/ToadforMySQLFreeware/tabid/561/Default.aspx" rel="nofollow" target="_blank" >Toad for MySQL</a>. Not only does it have a plethora of tools and interesting features, it is free. A few days back I’d to compare database schemas of different versions of a application to see if some table fields had changed between versions. Comparing a database schema containing above 200 tables can be a time consuming job if you do not have the right tools. Toad makes the work easier with its schema and data compare feature, which lets you easily compare schema and also the data  from two different databases. You can even synchronize the two schemas or the data therein so both the databases contain the same schema and data.</p>
<p>Besides these it has a nice query builder, somewhat like the one in Microsoft Access. Toad also can manage your Amazon EC2 instances with its built-in tool, which I&#8217;ve yet to try. Other than these it has the other regular features &#8211; a database explorer, table builder, database diagram creator etc. Toad is now my favorite tool for managing MySQL data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/mysql/increase-your-mysql-productivity-with-toad/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Templating with Haml</title>
		<link>http://www.codediesel.com/tools/templating-with-haml/</link>
		<comments>http://www.codediesel.com/tools/templating-with-haml/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 13:06:40 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2694</guid>
		<description><![CDATA[It has been a while since I&#8217;ve used a template engine during development, the last one I used was Smarty. Now there are a plethora of template systems, but most are a rehash of Smarty. Readers may beg to differ, but Smarty gets the work done, which is all that matters. The one that I [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I&#8217;ve used a template engine during development, the last one I used was <a href="http://www.smarty.net/" rel="nofollow" target="_blank" >Smarty</a>. Now there are a plethora of template systems, but most are a rehash of Smarty. Readers may beg to differ, but Smarty gets the work done, which is all that matters. The one that I found really interesting is <a href="http://haml-lang.com/" rel="nofollow" target="_blank" >Haml</a>.<br />
<span id="more-2694"></span></p>
<h4>Haml</h4>
<p>Haml (HTML  Abstraction Markup Language) is a lightweight markup language (or a meta markup language) which lets you create views for your Rails applications. But it can also be quite helpful for generating xhtml pages when used outside Rails. As I&#8217;m not a ROR developer my sole interest in Haml lies in using it to quickly create well formatted HTML files. Below is a short haml markup and its output. Haml comes with a standalone tool that lets you quickly convert haml markup to xhtml.</p>

<div class="wp_codebox"><table><tr id="p269447"><td class="code" id="p2694code47"><pre class="text" style="font-family:monospace;">!!!
%html
   %head
      %title codediesel
   %body</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p269448"><td class="code" id="p2694code48"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> 
<span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>codediesel<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>A more involved example using a bit of Ruby code.</p>

<div class="wp_codebox"><table><tr id="p269449"><td class="code" id="p2694code49"><pre class="text" style="font-family:monospace;">!!!
%html
   %head
      %title codediesel
   %body
      %h1 HAML
      / Demo of haml
      %div#main Lots of paragraphs
      %div#paras.list
         - (1...5).each do |i|
            %p= i
&nbsp;
      / Lots of classes
      %div.myclasses
         - (1...4).each do |i|
            %div{:class =&gt; i}
&nbsp;
      / a select element
      %select#color
         - ['red', 'blue', 'yellow', 'green'].each do |i|
            %option{:value =&gt; i}= i</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p269450"><td class="code" id="p2694code50"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> 
<span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>codediesel<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>HAML<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> Demo of haml <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">'main'</span><span style="color: #339933;">&gt;</span>Lots of paragraphs<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'list'</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">'paras'</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> Lots of classes <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'myclasses'</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'2'</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'3'</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;!--</span> a select element <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #0000ff;">'color'</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">'red'</span><span style="color: #339933;">&gt;</span>red<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">'blue'</span><span style="color: #339933;">&gt;</span>blue<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">'yellow'</span><span style="color: #339933;">&gt;</span>yellow<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">'green'</span><span style="color: #339933;">&gt;</span>green<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>The useful thing about Haml for me is that I can use it to quickly generate xhtml skeleton files using a few haml markup files and a dash of shell scripting. Editing the haml markup is easier and quicker then editing the xhtml file, especially if the html happens to be a big one. Note that indenting is extremely important in the haml markup, so if you are just trying out haml, be prepared to encounter a bit of errors in the beginning. If you are new to Ruby and are interested in trying haml, I suggest you install the <a href="http://rubyinstaller.org/" rel="nofollow" target="_blank" >rubyinstaller</a> environment. It works right of the box with many other required components pre-installed.</p>
<h4>phpHaml</h4>
<p>If you get interested in haml there is a php port of of the same called <a href="http://phphaml.sourceforge.net/" rel="nofollow" target="_blank" >phpHaml</a> and <a href="http://code.google.com/p/phamlp/" rel="nofollow" target="_blank" >phamlp</a>. Here we will take a look at phpHaml. phpHaml has nearly the same syntax as haml. So if you are tired of verbose templating codes then phphaml can be an interesting solution for php users. So instead of writing something like the following ( I always hated mixing markup and php):</p>

<div class="wp_codebox"><table><tr id="p269451"><td class="code" id="p2694code51"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>table <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;config list&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>ID<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>Name<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>Value<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000000; font-weight: bold;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
          <span style="color: #339933;">&lt;</span>tr <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo (<span style="color: #006699; font-weight: bold;">$class</span> = forClassName(<span style="color: #006699; font-weight: bold;">$c</span>)); ?&gt;&quot;</span>
                 id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo &quot;</span><span style="color: #000088;">$class_</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#125;</span><span style="color: #0000ff;">&quot;; ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>You can write it in phphaml as below. Now that&#8217;s really some clean code. Not perfect, but better than the above.</p>

<div class="wp_codebox"><table><tr id="p269452"><td class="code" id="p2694code52"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">#content
</span>      <span style="color: #339933;">%</span>table<span style="color: #339933;">.</span>config<span style="color: #339933;">.</span><span style="color: #990000;">list</span>
        <span style="color: #339933;">%</span>tr
          <span style="color: #339933;">%</span>th ID
          <span style="color: #339933;">%</span>th Name
          <span style="color: #339933;">%</span>th Value
        <span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">%</span>tr<span style="color: #009900;">&#91;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#93;</span>
            <span style="color: #339933;">%</span>td<span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span>
            <span style="color: #339933;">%</span>td<span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span>
            <span style="color: #339933;">%</span>td<span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span></pre></td></tr></table></div>

<h4>An example</h4>
<p>Below is a short example on using the phpHaml template. First we define the phpHaml markup. Let us call the file markup.haml and store it in a &#8216;tpl&#8217; directory. <em>Note: Make sure you keep the indentation at 2 spaces.</em></p>

<div class="wp_codebox"><table><tr id="p269453"><td class="code" id="p2694code53"><pre class="text" style="font-family:monospace;">!!!
%html
  %head
    %title= $title
  %body
    %h1= $title
    %p= $text
    %select#colors.general
      - foreach ($colors as $c)
        %option{:value =&gt; $c}= $c</pre></td></tr></table></div>

<p><em>Update: 27th Jan 2011</em><br />
If you need to select a particular element in the drop-down you can use the code below.</p>

<div class="wp_codebox"><table><tr id="p269454"><td class="code" id="p2694code54"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">!!!</span>
<span style="color: #339933;">%</span>html
  <span style="color: #339933;">%</span>head
    <span style="color: #339933;">%</span>title<span style="color: #339933;">=</span> <span style="color: #000088;">$title</span>
  <span style="color: #339933;">%</span>body
    <span style="color: #339933;">%</span>h1<span style="color: #339933;">=</span> <span style="color: #000088;">$title</span>
    <span style="color: #339933;">%</span>p<span style="color: #339933;">=</span> <span style="color: #000088;">$text</span>
    <span style="color: #339933;">%</span>select<span style="color: #009933; font-style: italic;">#colors.general
</span>      <span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$colors</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">%</span>option<span style="color: #009900;">&#123;</span><span style="color: #339933;">:</span>value <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #339933;">:</span>selected <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'selected'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span> <span style="color: #000088;">$c</span>
        <span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">else</span>
          <span style="color: #339933;">%</span>option<span style="color: #009900;">&#123;</span><span style="color: #339933;">:</span>value <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span> <span style="color: #000088;">$c</span></pre></td></tr></table></div>

<p>We then call the above template from our php code, passing along some variables.</p>

<div class="wp_codebox"><table><tr id="p269455"><td class="code" id="p2694code55"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'./includes/haml/HamlParser.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'phpHaml Demo'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">'A short example of the markup'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$colors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blue&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;red&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;green&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
display_haml<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./tpl/example3.haml'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The following is what we get after rendering.</p>

<div class="wp_codebox"><table><tr id="p269456"><td class="code" id="p2694code56"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.1//EN&quot;</span> 
<span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>phpHaml Demo<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>phpHaml Demo<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>A short example of the markup<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>select <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;general&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;colors&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;blue&quot;</span><span style="color: #339933;">&gt;</span>blue<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;red&quot;</span><span style="color: #339933;">&gt;</span>red<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;green&quot;</span><span style="color: #339933;">&gt;</span>green<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Although it looks good, there are some major drawbacks. First, the stringent rules for indention, mess that up and it can be quite frustrating to indent everything back again, and second the inability to easily breakup the markup into multiple files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/templating-with-haml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Scanning web pages for malicious scripts</title>
		<link>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/</link>
		<comments>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 05:30:18 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[malware]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2117</guid>
		<description><![CDATA[Auto scanning of selected web pages for malicious scripts]]></description>
			<content:encoded><![CDATA[<p>With the recent surge of malicious JavaScript injections on web, it has become necessary to regularly check for malicious code injections on your web sites. I created a small php script that checks a list of urls for malicious Javascript code. This can come handy if you have many client websites under your control.</p>
<p>The PHP script reads two text files &#8211; &#8216;malicious.txt and &#8216;urls.txt&#8217; : the first containing a list of web pages to be scanned and the other containing malicious script signatures. The script scans the urls for malicious scripts and if any infections are found it saves the result in the &#8216;infected.txt&#8217; file. The script needs to be run from the command line as you can easily see the progress of the scan if you are scanning a large number of urls.<br />
<span id="more-2117"></span></p>

<div class="wp_codebox"><table><tr id="p211757"><td class="code" id="p2117code57"><pre class="dos" style="font-family:monospace;">D:\localhost\test\scan&gt;php url_scan.php</pre></td></tr></table></div>

<p>A sample output of a scan is show below:</p>

<div class="wp_codebox"><table><tr id="p211758"><td class="code" id="p2117code58"><pre class="text" style="font-family:monospace;">&nbsp;
D:\localhost\test\scan&gt;php url_scan.php
&nbsp;
Checking 3 sites for malicious scripts.
3 malicious signatures in file.
---------------------------------------------------------
&nbsp;
Now scanning :http://www.amazon.com/
[OK]
---------------------------------------------------------
&nbsp;
Now scanning :http://www.google.com/
[OK]
---------------------------------------------------------
&nbsp;
Now scanning :http://www.example.com/admin.php
[OK]
---------------------------------------------------------
&nbsp;
Total 0 sites infected of 3</pre></td></tr></table></div>

<p>Note that the script only scans the url path given and not the complete web site. So if given a url like &#8216;http://www.example.com&#8217; it will only scan the index file of the site. It may happen that the index file may not be infected but some other file in a sub-directory is, in that case the malicious code will not be found. But a larger percentage of malicious script injections are usually inflicted on the index page.</p>
<h4>Setting a cron for automatic scanning</h4>
<p>The best way to regularly check for any infections is to setup the script as a cron job. This can help you in checking malicious script on a regular interval, the cron job can then send the &#8216;infected.txt&#8217; file via a email if any infections are found.</p>
<h4>Updating your malicious.txt file</h4>
<p>You cannot fight new code injections if your &#8216;malicious.txt&#8217; file is not updated. So if you find some new malicious Javascript code, then it is essential that you include a new signature in the file. Well I know I&#8217;m putting the cart before the horse but you can find various new information about infections at <a href="http://www.malware.com.br/" rel="nofollow" >malware.com.br</a> or <a href="http://www.malwaredomainlist.com/mdl.php" rel="nofollow" >malwaredomainlist</a>.</p>
<h4>Other ways to check malicious code injections</h4>
<p>One main problem with the script is that if some new infection occurs and the signature is not in the &#8216;malicious.txt&#8217; database then that particular infection will be missed. One other solution is to check the filesize of the particular url you are checking. The filesize needs to be added to the &#8216;urls.txt&#8217; file, so the script can check to see if the filesize of the url scanned is the same as the one given. But for that we will need to use the ftp functions of php but we will leave that to another post.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/urlscan" rel="nofollow" >Download Source</a><br />
<span>Downloads : 1434  / File size : 1.4 kB</span>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/scanning-web-pages-for-malicious-scripts-in-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Debugging HTTP traffic using Fiddler</title>
		<link>http://www.codediesel.com/microsoft/debugging-http-traffic-using-fiddler/</link>
		<comments>http://www.codediesel.com/microsoft/debugging-http-traffic-using-fiddler/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 11:23:45 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[microsoft]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1636</guid>
		<description><![CDATA[debugging http traffic using Microsoft fiddler]]></description>
			<content:encoded><![CDATA[<p>Microsoft <a href="http://www.fiddler2.com/fiddler2/" rel="nofollow" target="_blank" >Fiddler</a> is a HTTP debugging proxy that lets you log all HTTP traffic between your computer and the internet. Fiddler lets you to inspect all HTTP traffic, set breakpoints, and &#8220;fiddle&#8221; with incoming or outgoing HTTP data. To run Fiddler you require a Windows machine with .NET 1.1 framework installed.<br />
<span id="more-1636"></span></p>
<h4>How Fiddler works</h4>
<p>The proxy bascially sits between the Windows WinINET interface and the internet. WinInet is high level API to work with HTTP, FTP, and Gopher protocols.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/fiddler-archi.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/fiddler-archi.gif" alt="fiddler-archi" title="fiddler-archi" width="408" height="156" class="aligncenter size-full wp-image-1639" /></a></p>
<h4>Installing Fiddler</h4>
<p>Fiddler is an HTTP Proxy running on port 8888 on your local PC. You can configure any application which accepts a HTTP Proxy to run through Fiddler so you can debug the particular applications traffic. WinINET-based applications (E.g. Microsoft Office, Internet Explorer, etc) should automatically use Fiddler while it&#8217;s running and the &#8220;Capture Traffic&#8221; box is checked on the Fiddler File menu. </p>
<p>Current versions of Internet Explorer, Google Chrome, Apple Safari, and Opera all automatically use Fiddler when Fiddler is configured to Capture Traffic. </p>
<p>If your browser does not automatically use a proxy then you can configure it to point to address: 127.0.0.1, port: 8888.</p>
<h4>Logging with Fiddler</h4>
<p>You can easily log HTTP traffic using Fiddler to track down bugs from your browser or website and save it to a file. This can be quite handy if you need to send the logs to the testing team.</p>
<h4>Transfer timelines</h4>
<p>Like many other browser addons, Fiddler also supports transfer timelines.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/fiddler-timeline.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/fiddler-timeline.gif" alt="fiddler-timeline" title="fiddler-timeline" width="431" height="275" class="aligncenter size-full wp-image-1646" /></a></p>
<h4>Extending Fiddler Using Rules</h4>
<p>Fiddler lets you modify its HTTP request or response by using the JScript.NET scripting language. You can also write your own plugins to change Fiddlers behavior in any .NET language. Sadly being from the php camp I do not have much experience there.</p>
<h4>Text Encode/Decode Wizard</h4>
<p>I specially like the &#8216;Text Wizard&#8217; which lets you process text in a variety of formats. You can encode/decode data using: Base64, URLEncode, HexEncode, JS string, HTML Encode, UTF-7, Deflated SAML.</p>
<h4>HTTP Performance tuning</h4>
<p>The author of Fiddler, Eric Lawrence, has an excellent <a href="http://msdn.microsoft.com/en-us/library/bb250442(VS.85).aspx" rel="nofollow" target="_blank" >article</a> that goes into the details on HTTP performance tuning.</p>
<h4>Fiddler in a Nutshell</h4>
<p>Fiddler is an excellent tool for both troubleshooting client/server applications and tweaking the performance of web applications. There are many more things you can do with Fiddler for which this post cannot do justice. Fiddler gives you an inside view into the mechanics of HTTP requests and responses, allowing you to understand what your application is doing. With that knowledge under your belt, you can write better, faster, and lighter applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/microsoft/debugging-http-traffic-using-fiddler/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visualizing application structure with nWire</title>
		<link>http://www.codediesel.com/php/visualizing-application-structure-with-nwire/</link>
		<comments>http://www.codediesel.com/php/visualizing-application-structure-with-nwire/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 11:17:10 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[visualization]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1748</guid>
		<description><![CDATA[visualize application structure with nwire]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.nwiresoftware.com/products/nwire-php" rel="nofollow" target="_blank" >nWire</a> is a plugin for Eclipse that helps you understand the various components and their relationships in your application. Due to various complex PHP applications being developed &#8211; like Magento, Joomla and a wide variety of frameworks, developers finds it hard to understand the underlying architecture and relationships between various components within the application.<br />
<span id="more-1748"></span><br />
nWire lets you bring order to that complexity. Just as a map lets you visualize the relationships between various geographical elements  : cities, rivers, roads etc. nWire lets you understand the structure and relationships between various components of the given application. nWire is currently available for Zend Studio 7.0 and Eclipse 3.5 with PDT 2.1.</p>
<p>Currently the software includes three tools:<br />
a. Visualizer : Helps to browse components and associations using one simple unified view.<br />
b. Navigator : Interactive visual representation of all code associations.<br />
c. Search : Incremental search for any type of component, including classes and methods.</p>
<h4>Visualizer</h4>
<p>The visualizer presents the application components and associations in a graphical representation. Each component of the application appears as a node and associations appear as edges, with the association name given on the edges. When there are many associations of a given type, the associations are grouped into a sub-node. The graph can be traversed: expanding nodes to reveal associated components while the layout automatically adjusts.</p>
<p>The following is a visualization of the <a href="http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/">Amazon API class</a> I had posted about earlier.<br />
<a href="http://www.codediesel.com/wp-content/uploads/2009/10/amazon_api_class_php.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/amazon_api_class_php.png" alt="amazon_api_class_php" title="amazon_api_class_php" width="459" height="651" class="aligncenter size-full wp-image-1752" /></a></p>
<p>Another visualization of WordPress 2.8, centered on index.php.<br />
(<em>Click image to view a larger version</em>)<br />
<a href="http://www.codediesel.com/wp-content/uploads/2009/10/index_php.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/index_php-300x263.png" alt="index_php" title="index_php" width="300" height="263" class="aligncenter size-medium wp-image-1757" /></a></p>
<h4>Navigator</h4>
<p>The navigator presents the components and associations of the application which were discovered by the analyzer. It starts from a given selected component and shows all associated components. This includes inbound and outbound associations. The following figure shows the navigator with the WordPress &#8216;wp_meta()&#8217; function selected.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/nwire_navi1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/nwire_navi1.gif" alt="nwire_navi1" title="nwire_navi1" width="512" height="184" class="aligncenter size-full wp-image-1763" /></a></p>
<h4>Search</h4>
<p>The search feature lets you search for components by name or a partial name using wild cards.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/nwire_search.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/nwire_search.gif" alt="nwire_search" title="nwire_search" width="347" height="450" class="aligncenter size-full wp-image-1767" /></a></p>
<h4>Price</h4>
<p>nWire is not OpenSource, but a 30-day trial is available. Single user license will cost you $59. If you are dealing with plethora of heavy applications, than the price is worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/visualizing-application-structure-with-nwire/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Local email testing of applications</title>
		<link>http://www.codediesel.com/tools/local-email-testing-of-applications/</link>
		<comments>http://www.codediesel.com/tools/local-email-testing-of-applications/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 04:41:25 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1697</guid>
		<description><![CDATA[local testing of email applications]]></description>
			<content:encoded><![CDATA[<p>E-mails are a pervasive element of most web applications. But many times testing and debugging emails can become a hassle when many of them are involved. Most of the time you just want to be sure that the email part of your application is working fine, without flooding your mail account with test mails.<br />
<span id="more-1697"></span><br />
<a href="http://invalidlogic.com/papercut/" rel="nofollow" target="_blank" >Papercut</a> is a simplified SMTP server designed to help you receive emails from your local applications but without sending them out. It doesn&#8217;t even care if the email address you sent is valid or not. It just takes the email you sent and displays and logs it in a window for you to see if it is correct. It can be quite useful if you just need to make sure that the email part of your applications is working fine.</p>
<h4>Installation</h4>
<p>Papercut is a Windows application requiring .NET Framework 3.5 . Thankfully no installation is required as the application can be run directly. Upon activation it sits in the system tray and pops a message when a email is received from a local web application.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/papercut1.png"><img style="border:1px solid #000;" src="http://www.codediesel.com/wp-content/uploads/2009/10/papercut1.png" alt="papercut1" title="papercut1" width="238" height="62" class="aligncenter size-full wp-image-1701" /></a></p>
<p>The messages can then be viewed in the Papercut window.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/10/papercut2.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/10/papercut2.png" alt="papercut2" title="papercut2" width="490" height="282" class="aligncenter size-full wp-image-1705" /></a></p>
<p>In all a simple and useful tool for any web developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/local-email-testing-of-applications/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Beautifying XML documents</title>
		<link>http://www.codediesel.com/pear/beautifying-xml-documents/</link>
		<comments>http://www.codediesel.com/pear/beautifying-xml-documents/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 04:48:52 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1590</guid>
		<description><![CDATA[how to beautify and format xml documents]]></description>
			<content:encoded><![CDATA[<p>I frequently write php code to access various web services and the most common response data I encounter is in xml, which most of the time is not formatted. I use <a href="http://www.wmhelp.com/" rel="nofollow" target="_blank" >xmlPad</a> to format and analyze xml documents, but many times I need to format xml documents on the production server wherein xmlPad is of no use. What one needs is a library that would allow you to beautify your untidy xml documents within your php code. <a href="http://pear.php.net/manual/en/package.xml.xml-beautifier.php" rel="nofollow" target="_blank" >XML_Beautifier</a> provides that solution.<br />
<span id="more-1590"></span></p>
<h4>Installation</h4>
<p>XML_Beautifier being a Pear package we will use the Pear installer as below. I recommend to always use the Pear installer to download packages rather than dowloading it manually as the Pear installer automatically downloads any dependent packages.</p>

<div class="wp_codebox"><table><tr id="p159059"><td class="code" id="p1590code59"><pre class="text" style="font-family:monospace;">pear install XML_Beautifier</pre></td></tr></table></div>

<h4>Usage</h4>
<p>You can beautify a xml file or a on-the-fly generated xml string. The following will nicely format a untidy xml file. The input file must be a valid xml document or the parser will flag an error.</p>

<div class="wp_codebox"><table><tr id="p159060"><td class="code" id="p1590code60"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">&quot;XML/Beautifier.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XML_Beautifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'unformated.xml'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'beautified.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>PEAR<span style="color: #339933;">::</span><span style="color: #004000;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Done&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Formatting a xml string is quite as simple.</p>

<div class="wp_codebox"><table><tr id="p159061"><td class="code" id="p1590code61"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">&quot;XML/Beautifier.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Unformatted xml string */</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;rootNode&gt;&lt;foo   bar = &quot;pear&quot;&gt;hello world!&lt;/foo&gt;&lt;/rootNode&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XML_Beautifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$fmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatString</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Formatted xml string.</p>

<div class="wp_codebox"><table><tr id="p159062"><td class="code" id="p1590code62"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rootNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;foo</span> <span style="color: #000066;">bar</span>=<span style="color: #ff0000;">&quot;pear&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>hello world!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/foo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rootNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>If you frequently need to format xml documents than it would be better to have a command line access to the beautifier as below.</p>

<div class="wp_codebox"><table><tr id="p159063"><td class="code" id="p1590code63"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** xmlformat.php
 *  usage: php xmlformat.php untidy.xml beautified.xml
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$argc</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Usage: <span style="color: #006699; font-weight: bold;">$argv[0]</span> unformatted.xml formatted.xml<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">&quot;XML/Beautifier.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Formatting <span style="color: #006699; font-weight: bold;">{$argv[1]}</span>...&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XML_Beautifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatFile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>PEAR<span style="color: #339933;">::</span><span style="color: #004000;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Done&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Options</h4>
<p>The <em>XML_Beautifier</em> class also accepts a array of options which you can pass to the constructor during initialization. The details of the options can be found <a href="http://pear.php.net/manual/en/package.xml.xml-beautifier.options.php" rel="nofollow" target="_blank" >here</a>.</p>

<div class="wp_codebox"><table><tr id="p159064"><td class="code" id="p1590code64"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">&quot;caseFolding&quot;</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;caseFoldingTo&quot;</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;uppercase&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">&quot;normalizeComments&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XML_Beautifier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">.</span>
<span style="color: #339933;">.</span></pre></td></tr></table></div>

<p>One thing to note in closing is that the formatting of big xml documents can take some time depending on your machine configuration, so if you plan on formatting documents on a live server you need to take that into account.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/pear/beautifying-xml-documents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

