<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>code-diesel</title>
	
	<link>http://www.codediesel.com</link>
	<description>/* PHP &amp; MySQL Journal */</description>
	<pubDate>Sun, 08 Nov 2009 12:39:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Code-diesel" type="application/rss+xml" /><feedburner:emailServiceId>Code-diesel</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Programming puzzle #2</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/znohL_pNNJQ/</link>
		<comments>http://www.codediesel.com/puzzles/programming-puzzle-2/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 11:03:33 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1884</guid>
		<description><![CDATA[The last programming problem, though not difficult, was interesting for the variety of ways readers tried to solve it. Here goes the second one:


Using a standard deck of playing cards we can display the first n digits of the constant PI. For example using a single deck of cards, you can display the following digits [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.codediesel.com/puzzles/programming-challenges/">last</a> programming problem, though not difficult, was interesting for the variety of ways readers tried to solve it. Here goes the second one:<br />
<span id="more-1884"></span></p>
<blockquote><p>
Using a standard deck of playing cards we can display the first <em>n</em> digits of the constant PI. For example using a single deck of cards, you can display the following digits of PI:</p>
<p>3.14159265358979323846264</p>
<p>In the above example we cannot display the next digit, which happens to be a &#8216;3&#8242;, because we have already used 4 cards of the number &#8216;3&#8242; from a single deck.</p>
<p>Write a function that takes d - the number of card decks; and returns the number of digits of PI you can display using the cards. So for d(deck) = 1, the function should return 24 (the number of starting digits of PI). </p>
<p>Take &#8216;Ace&#8217; as the digit &#8216;1&#8242; and &#8216;10&#8242; as the digit &#8216;0&#8242;. A list of the million digits of PI can be found <a target="_blank" href="http://www.exploratorium.edu/pi/Pi10-6.html">here</a>.
</p></blockquote>
<p>Preferably the solution should be in PHP, but other languages are welcome.</p>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/znohL_pNNJQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/puzzles/programming-puzzle-2/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/puzzles/programming-puzzle-2/</feedburner:origLink></item>
		<item>
		<title>Simulating Packages in PHP</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/v3ZBGs2NT_I/</link>
		<comments>http://www.codediesel.com/php/simulating-packages-in-php/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 06:36:15 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[php]]></category>

		<category><![CDATA[software]]></category>

		<category><![CDATA[tip]]></category>

		<category><![CDATA[oop]]></category>

		<category><![CDATA[package]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1842</guid>
		<description><![CDATA[Most modern languages have a concept of packages, wherein related classes are stored together. PHP sadly doesn&#8217;t have a similar concept. For example in Java we can use the following line to imports all classes from the java.awt.event package.

import java.awt.event.*;


But in the spirit of &#8216;programming into the language&#8217;, what we can do is try to [...]]]></description>
			<content:encoded><![CDATA[<p>Most modern languages have a concept of packages, wherein related classes are stored together. PHP sadly doesn&#8217;t have a similar concept. For example in Java we can use the following line to imports all classes from the java.awt.event package.</p>

<div class="wp_codebox"><table width="100%" ><tr id="18425"><td class="code" id="1842code5"><pre class="java"><span style="color: #a1a100;">import java.awt.event.*;</span></pre></td></tr></table></div>

<p><span id="more-1842"></span><br />
But in the spirit of &#8216;programming into the language&#8217;, what we can do is try to simulate a &#8216;package-like&#8217; concept in PHP. Take the following directory structure.<br />
<a href="http://www.codediesel.com/wp-content/uploads/2009/11/package_dir_struct1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/package_dir_struct1.gif" alt="package_dir_struct1" title="package_dir_struct1" width="273" height="180" class="aligncenter size-full wp-image-1849" /></a></p>
<p>So now if we want to import the &#8216;login.php&#8217; file in our code we must be able to do the following with a newly created &#8216;import&#8217; function:</p>

<div class="wp_codebox"><table width="100%" ><tr id="18426"><td class="code" id="1842code6"><pre class="php">import<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.codediesel.Security.login&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>This will include the &#8216;login.php&#8217; file from the &#8216;com/codediesel/Security&#8217; directory. To include all the files from the &#8216;Security&#8217; directory we can do the following:</p>

<div class="wp_codebox"><table width="100%" ><tr id="18427"><td class="code" id="1842code7"><pre class="php">import<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.codediesel.Security.*);</span></pre></td></tr></table></div>

<p> As you can see that this is actually quite different from what the actual package concept implies, which is to import <em>related classes</em>. </p>
<p>Anyways, taking it as a conceptual idea only the code for the import function is shown below:</p>

<div class="wp_codebox"><table width="100%" ><tr id="18428"><td class="code" id="1842code8"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #0000ff;">$basePath</span> = <span style="color: #ff0000;">&quot;./&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> import<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$classPath</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">global</span> <span style="color: #0000ff;">$basePath</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* If the path ends with a '.*' then include
       all the files in the last given directory.
    */</span>
    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">preg_match</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/(<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\*</span>)$/'</span>, <span style="color: #0000ff;">$classPath</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$importFilePath</span> = <span style="color: #000066;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$classPath</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000066;">strlen</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$classPath</span><span style="color: #66cc66;">&#41;</span> - <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$importFilePath</span> = <span style="color: #000066;">str_replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #ff0000;">&quot;/&quot;</span>, <span style="color: #0000ff;">$importFilePath</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$d</span>= <span style="color: #000066;">dir</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$basePath</span> . <span style="color: #0000ff;">$importFilePath</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span> !== <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span> = <span style="color: #0000ff;">$d</span>-&gt;<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">/* Reject parent, current directories and sub directories */</span>
            <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span> == <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span>  ||
               <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span> == <span style="color: #ff0000;">'..'</span><span style="color: #66cc66;">&#41;</span> ||
               <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">is_dir</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$d</span>-&gt;<span style="color: #006600;">path</span> . <span style="color: #ff0000;">&quot;/&quot;</span> . <span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">continue</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$basePath</span> . <span style="color: #0000ff;">$importFilePath</span> . <span style="color: #ff0000;">&quot;/&quot;</span> . <span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">/* If a single file is specified */</span>
        <span style="color: #0000ff;">$importFile</span> = <span style="color: #000066;">str_replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span>, <span style="color: #ff0000;">&quot;/&quot;</span>, <span style="color: #0000ff;">$classPath</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">&quot;.php&quot;</span>;
    	<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$basePath</span> . <span style="color: #0000ff;">$importFile</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Please note that this is just an idea. Detailed error handling is not included to keep the code conceptually simple to understand. It would be fun if readers could bounce around some thoughts.</p>
<h4>Now the Problems</h4>
<p>The first main problem is that this is not exactly what the package concept implies. What we are essentially doing is dressing-up the &#8216;include&#8217; concept in new clothes.</p>
<p>The second is that for multiple file inclusion as shown above, we cannot predict in which sequence the files will be included, which can raise some dependency issues.</p>
<p>Including a large number of files can incur a small performance hit. This can be better handled if developed as a PECL extension.</p>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/v3ZBGs2NT_I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/simulating-packages-in-php/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/php/simulating-packages-in-php/</feedburner:origLink></item>
		<item>
		<title>Test data generation for MySQL</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/8NBcusuknzE/</link>
		<comments>http://www.codediesel.com/data/test-data-generation-for-mysql/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 09:28:16 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[data]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1833</guid>
		<description><![CDATA[One of the most time consuming steps in developing a database based application is test data generation. Imagine you have created a shopping cart application for your client, containing dozens of tables and hundreds of fields. Everything is ready for testing, but the problem is your database is empty. You at least require a modicum [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most time consuming steps in developing a database based application is test data generation. Imagine you have created a shopping cart application for your client, containing dozens of tables and hundreds of fields. Everything is ready for testing, but the problem is your database is empty. You at least require a modicum of test data in the database to proceed with the testing. You can choose to manually enter a small set of random data into the database, but you lose a couple of precious days in the process. What you require is a data generator that automatically generates test data for your database.<br />
<span id="more-1833"></span><br />
There are a couple of data generators available for free on the web, but they are only suitable if your database schema is small, with no more than three to four tables and total number of fields not exceeding  a dozen or so.  While browsing I came across <a target="_blank" href="http://www.upscene.com/products.adg.index.php">Advanced Data Generator (ADG)</a>, a test data generator for MySQL. ADG allows you to generate a random test data for dates, URLS, E-mail addresses, cities, names, countries and more. </p>
<h4>Data Generation</h4>
<p>Once you connect ADG to your MySQL server and register a database, you are ready to go. Generating the test data is quite simple. First you create a project for your data generation work. Once done, you select the table and fields you want to generate data for, select the type of test data to generate – dates, urls, names etc. Set the total number of records to generate and then run the project. This will create the test data for your database project. The test data can be saved directly to the connected database or you can save it as a separate SQL script, YAML or CSV file.  Below is a sample screenshot of a data generation project.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg1-300x267.gif" alt="adg1" title="adg1" width="300" height="267" class="aligncenter size-medium wp-image-1832" /></a></p>
<p>The Advanced Data Generator comes with a very useful repository of real-life like data, in order to generate meaningful test-data for the database. You can also use custom SQL scripts or Macros to generate custom string data.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg2-295x300.gif" alt="adg2" title="adg2" width="295" height="300" class="aligncenter size-medium wp-image-1838" /></a></p>
<h4>In closing</h4>
<p>Although not free, its a small price to pay for the excellent automation it provides during database creation.</p>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/8NBcusuknzE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/test-data-generation-for-mysql/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/data/test-data-generation-for-mysql/</feedburner:origLink></item>
		<item>
		<title>Programming challenges</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/e4M6oci2k0o/</link>
		<comments>http://www.codediesel.com/puzzles/programming-challenges/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 12:35:20 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1823</guid>
		<description><![CDATA[Programming is about solving problems. To be precise, solving problems using a computing device. I love solving puzzles as do most programmers.  Solving a challenging puzzle or a programming problem gives one a wonderful sense of satisfaction. Starting with this post I’ll be presenting a programming problem every week that will help readers take [...]]]></description>
			<content:encoded><![CDATA[<p>Programming is about solving problems. To be precise, solving problems using a computing device. I love solving puzzles as do most programmers.  Solving a challenging puzzle or a programming problem gives one a wonderful sense of satisfaction. Starting with this post I’ll be presenting a programming problem every week that will help readers take some time out from their routine work and have some additional fun working on challenging problems. Below is a small problem to kickstart the series:<br />
<span id="more-1823"></span></p>
<blockquote><p>
Write a program which finds a four digit number AABB which is a perfect square. A and B represent different digits.
</p></blockquote>
<p>If you are posting solutions, then please make them in php, as this is what this blog is related around, but if would like to submit in any other language you are welcome, as requested by Evans in the comments.</p>
<p>I invite readers to send me problems you find interesting which can be incorporated in future posts. Just ensure that problems are not too easy or too hard. An easy problem doesn’t challenge you, while a hard one destroys the motivation to solve it. You can mail problems to me at metapix[at]gmail.com with the subject ‘problems’. Don&#8217;t forget to include your name.</p>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/e4M6oci2k0o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/puzzles/programming-challenges/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/puzzles/programming-challenges/</feedburner:origLink></item>
		<item>
		<title>Debugging HTTP traffic using Fiddler</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/cL4GvcUhA5c/</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[Microsoft Fiddler 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.

How Fiddler works
The proxy bascially [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft <a target="_blank" href="http://www.fiddler2.com/fiddler2/">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 target="_blank" href="http://msdn.microsoft.com/en-us/library/bb250442(VS.85).aspx">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>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/cL4GvcUhA5c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/microsoft/debugging-http-traffic-using-fiddler/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/microsoft/debugging-http-traffic-using-fiddler/</feedburner:origLink></item>
		<item>
		<title>Visualizing application structure with nWire</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/lW3cyCm2COQ/</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[nWire 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 - 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.

nWire lets [...]]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.nwiresoftware.com/products/nwire-php">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 - 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>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/lW3cyCm2COQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/visualizing-application-structure-with-nwire/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/php/visualizing-application-structure-with-nwire/</feedburner:origLink></item>
		<item>
		<title>Local email testing of applications</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/fuXk0DEzZBA/</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[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.

Papercut is [...]]]></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 target="_blank" href="http://invalidlogic.com/papercut/">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>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/fuXk0DEzZBA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/local-email-testing-of-applications/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/tools/local-email-testing-of-applications/</feedburner:origLink></item>
		<item>
		<title>Detecting user agents in php</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/KYC8J6QB0s4/</link>
		<comments>http://www.codediesel.com/pear/detecting-user-agents-in-php/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 13:48:29 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[browser]]></category>

		<category><![CDATA[pear]]></category>

		<category><![CDATA[agents]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1660</guid>
		<description><![CDATA[Every time you use your browser to access a website a User-Agent header is sent to the respective server.
Detecting user agents on the server can be useful for many reasons. 
1. Browsers Quirks – Despite the standardization in browsers, there will remain some quirks in various browsers that you will need to iron out on [...]]]></description>
			<content:encoded><![CDATA[<p>Every time you use your browser to access a website a User-Agent header is sent to the respective server.<br />
Detecting user agents on the server can be useful for many reasons. </p>
<p>1. Browsers Quirks – Despite the standardization in browsers, there will remain some quirks in various browsers that you will need to iron out on a regular basis.<br />
2. Personalize Content – It may be required to deliver different type of content depending on the browser type (although it is usually not recommended); whether mobile or otherwise.<br />
3. Illegal Access – Prevent bandwidth hogging bots and poorly programmed clients from downloading your content.<br />
<span id="more-1660"></span><br />
Below is a sample header for my site when using Firefox.</p>

<div class="wp_codebox"><table width="100%" ><tr id="166016"><td class="code" id="1660code16"><pre class="text">http://www.codediesel.com/
&nbsp;
GET / HTTP/1.1
Host: www.codediesel.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6)
Gecko/2009011913 Firefox/3.0.6 FirePHP/0.2.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive</pre></td></tr></table></div>

<p>PHP already has a builtin function - <a target="_blank" href="http://us2.php.net/manual/en/function.get-browser.php">get_browser()</a> that lets you determine the capabilities of the user&#8217;s browser, but it requires a browscap.ini to be installed, which sadly is not bundled with PHP, and also the function can slow down your php script. The other way to get a user agent is to use php server variables like below,</p>

<div class="wp_codebox"><table width="100%" ><tr id="166017"><td class="code" id="1660code17"><pre class="php"><span style="color: #000066;">echo</span> <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_USER_AGENT'</span><span style="color: #66cc66;">&#93;</span>;</pre></td></tr></table></div>

<p>In this post we will use the <a target="_blank" href="http://pear.php.net/package/net_useragent_detect/redirected">Net_UserAgent_Detect</a> Pear package to determine user agents.</p>
<h4>Installation</h4>
<p>Net_UserAgent_Detect 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 downloading it manually as the Pear installer automatically downloads any dependent packages.</p>

<div class="wp_codebox"><table width="100%" ><tr id="166018"><td class="code" id="1660code18"><pre class="text">pear install Net_UserAgent_Detect-2.5.1</pre></td></tr></table></div>

<h4>Usage</h4>
<p>Usage is quite simple. For example the following code:</p>

<div class="wp_codebox"><table width="100%" ><tr id="166019"><td class="code" id="1660code19"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Net/UserAgent/Detect.php'</span>;
&nbsp;
<span style="color: #000066;">echo</span> Net_UserAgent_Detect::<span style="color: #006600;">getUserAgent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>will return the following string on Firefox 3.0.6: This can be quite useful if you need to log the users browser or OS type.</p>

<div class="wp_codebox"><table width="100%" ><tr id="166020"><td class="code" id="1660code20"><pre class="text">Mozilla/5.0 (Windows; U; Windows NT 5.1; 
en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 FirePHP/0.2.4</pre></td></tr></table></div>

<p>getUserAgent() is only one of the many methods available in the class.</p>

<div class="wp_codebox"><table width="100%" ><tr id="166021"><td class="code" id="1660code21"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">'Net/UserAgent/Detect.php'</span>;
&nbsp;
<span style="color: #000066;">echo</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Browser String: '</span>.Net_UserAgent_Detect::<span style="color: #006600;">getBrowserString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;&lt;br&gt;&quot;</span>;
<span style="color: #000066;">echo</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'OS String: '</span>.Net_UserAgent_Detect::<span style="color: #006600;">getOSString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;&lt;br&gt;&quot;</span>;
<span style="color: #000066;">echo</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Javascript: '</span>.Net_UserAgent_Detect::<span style="color: #006600;">getFeature</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'javascript'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Some other useful functions to directly test the type of browser are:<br />
isIE()<br />
isNavigator( )<br />
isNetscape( )</p>
<p>So to detect if the user is running Firefox:</p>

<div class="wp_codebox"><table width="100%" ><tr id="166022"><td class="code" id="1660code22"><pre class="php"><span style="color: #0000ff;">$browser</span> = Net_UserAgent_Detect::<span style="color: #006600;">isNetscape</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/KYC8J6QB0s4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/pear/detecting-user-agents-in-php/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/pear/detecting-user-agents-in-php/</feedburner:origLink></item>
		<item>
		<title>Codediesel gets a new color scheme</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/EUMKmhZWTPA/</link>
		<comments>http://www.codediesel.com/general/codediesel-gets-a-new-color-scheme/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 12:38:57 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[general]]></category>

		<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1619</guid>
		<description><![CDATA[Hello readers! The blog now has been updated with a new color scheme. The new and the previous one are shown below for comparision. Not that everyone will like it as each has his own favorite color palette. Basically I wanted to give the blog something  of a red or maroon finish, but after [...]]]></description>
			<content:encoded><![CDATA[<p>Hello readers! The blog now has been updated with a new color scheme. The new and the previous one are shown below for comparision. Not that everyone will like it as each has his own favorite color palette. Basically I wanted to give the blog something  of a red or maroon finish, but after tinkering a while I decided to settle around earth tones.<br />
<span id="more-1619"></span><br />
<a target="_blank" href="http://kuler.adobe.com/#">Adobe Kuler</a> was pivotal in selection of the color scheme. After searching for some time I settled on the combination of <a target="_blank" href="http://kuler.adobe.com/#themeID/572284">&#8216;backwards&#8217;</a> and <a target="_blank" href="http://kuler.adobe.com/#themeID/580742">Citrus Grove</a> themes.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/colortheme.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/colortheme.png" alt="colortheme" title="colortheme" width="182" height="41" class="aligncenter size-full wp-image-1634" /></a></p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/scheme11.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/scheme11.png" alt="scheme11" title="scheme11" width="587" height="586" class="aligncenter size-full wp-image-1622" /></a></p>
<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/EUMKmhZWTPA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/general/codediesel-gets-a-new-color-scheme/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/general/codediesel-gets-a-new-color-scheme/</feedburner:origLink></item>
		<item>
		<title>Generating UPC check digit</title>
		<link>http://feedproxy.google.com/~r/Code-diesel/~3/0sHfAOJ7FGA/</link>
		<comments>http://www.codediesel.com/php/generating-upc-check-digit/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 06:10:58 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
		
		<category><![CDATA[algorithms]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[upc]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1610</guid>
		<description><![CDATA[The following small code generates check digit for UPC-A codes. You can use it for example to generate random UPC-A codes.
Check digit calculation
The check digit is calculated as follows:
1. Add the digits in the odd-numbered positions together and multiply by three.
2. Add the digits in the even-numbered positions to the above result.
3. Find the result [...]]]></description>
			<content:encoded><![CDATA[<p>The following small code generates check digit for UPC-A codes. You can use it for example to generate random UPC-A codes.</p>
<h4>Check digit calculation</h4>
<p>The check digit is calculated as follows:<br />
1. Add the digits in the odd-numbered positions together and multiply by three.<br />
2. Add the digits in the even-numbered positions to the above result.<br />
3. Find the result modulo 10 (i.e. the remainder when the result is divided by 10).<br />
4. If the result is not zero, subtract the result from ten.<br />
<span id="more-1610"></span></p>
<h4>Code</h4>

<div class="wp_codebox"><table width="100%" ><tr id="161024"><td class="code" id="1610code24"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> generate_upc_checkdigit<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$upc_code</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$odd_total</span>  = <span style="color: #cc66cc;">0</span>;
    <span style="color: #0000ff;">$even_total</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
    <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>=<span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span>&lt;<span style="color: #cc66cc;">11</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span><span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">/* Sum even digits */</span>
            <span style="color: #0000ff;">$even_total</span> += <span style="color: #0000ff;">$upc_code</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #808080; font-style: italic;">/* Sum odd digits */</span>
            <span style="color: #0000ff;">$odd_total</span> += <span style="color: #0000ff;">$upc_code</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$sum</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span> * <span style="color: #0000ff;">$odd_total</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0000ff;">$even_total</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Get the remainder MOD 10*/</span>
    <span style="color: #0000ff;">$check_digit</span> = <span style="color: #0000ff;">$sum</span> % <span style="color: #cc66cc;">10</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/* If the result is not zero, subtract the result from ten. */</span>
    <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$check_digit</span> &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #cc66cc;">10</span> - <span style="color: #0000ff;">$check_digit</span> : <span style="color: #0000ff;">$check_digit</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000066;">echo</span> generate_upc_checkdigit<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;72438451112&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Code-diesel/~4/0sHfAOJ7FGA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/generating-upc-check-digit/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.codediesel.com/php/generating-upc-check-digit/</feedburner:origLink></item>
	</channel>
</rss>
