<?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>Christian Riesen &#187; Development</title>
	<atom:link href="http://christianriesen.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://christianriesen.com</link>
	<description>Life and work in the information and communication age</description>
	<lastBuildDate>Mon, 12 Jul 2010 10:39:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MS SQL Blob truncated</title>
		<link>http://christianriesen.com/2010/07/ms-sql-blob-truncated/</link>
		<comments>http://christianriesen.com/2010/07/ms-sql-blob-truncated/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 10:39:53 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Blob]]></category>
		<category><![CDATA[FreeTDS]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=212</guid>
		<description><![CDATA[There are times when I wish I had a third hand, just so [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when I wish I had a third hand, just so I could to a triple face palm. This is one of those times.</p>
<p>I&#8217;m accessing a blob in a MS SQL database that is pretty much nothing more than a JPG dumped straight into the field. I read them and echo them with a jpg header in PHP. All is well. The script runs and parses all the images, doing some caching magic with them. The result is that about a third of the images are broken, seemingly random. Mostly they just &#8220;stop&#8221; at a random spot over the whole set, but in one image it always stops at the same spot.</p>
<p>I suspected data corruption on input and a refresh on what inserts them in the first place worked, sometimes at least.</p>
<p>Digging down, I saw that the result I get back for the broken images is always 64512 bytes, exactly. That&#8217;s 2 to the power of 16. Can&#8217;t be a coincidence. Turns out, it isn&#8217;t.</p>
<p>I&#8217;m using freetds to access the database and there is an entry in freetds.conf that reads something like this:<br />
text size = 64512</p>
<p>Upping that number (and restarting the webserver, apache or IIS) did the trick. The images stored in the database were all around that point, so it looked like a random bug, but thankfully it wasn&#8217;t random.</p>
<p>If you don&#8217;t use freetds but the mssql extension instead, then this line would be of interest:<br />
mssql.textsize = 4096</p>
<p>Yes the default is only 4 kilobytes.</p>
<p>Maybe the desk will work as a third hand for the triple face palm.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2010/07/ms-sql-blob-truncated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming helping the writer and getting more exposure</title>
		<link>http://christianriesen.com/2010/03/programming-helping-the-writer-and-getting-more-exposure/</link>
		<comments>http://christianriesen.com/2010/03/programming-helping-the-writer-and-getting-more-exposure/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 13:37:28 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Toreas]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[XML-RPC]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[Zend_Http_Client]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=160</guid>
		<description><![CDATA[Writing is fun, but takes up a lot of time. Something t [...]]]></description>
			<content:encoded><![CDATA[<p>Writing is fun, but takes up a lot of time. Something that also takes up a lot of time is the things around writing. Those other things take time away from the more fun part of the general just writing the story. Now wouldn&#8217;t it be great if that was no longer the case?</p>
<p>Taking my little experiment Toreas, the <a href="http://toreas.com/" onclick="pageTracker._trackPageview('/outgoing/toreas.com/?referer=');">free fantasy book</a> or novel if you like, as a sample, I was in updating hell. The page itself where the book is readable from is an instance of <a href="http://www.mediawiki.org/" onclick="pageTracker._trackPageview('/outgoing/www.mediawiki.org/?referer=');">MediaWiki</a>. I chose it for the ease of adding new things, a good and stable code base, but also because I had a lot of experience in extending it. Then I wanted to add notes to each release and of course that looks like a blog. So my number one choice was simply <a href="http://wordpress.org/" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/?referer=');">WordPress</a> (which also powers this site), for a lot of the same reasons that MediaWiki was the page software. Twitter is not a software for me, but a web service as such and I wanted to add tweets as soon as there is a new chapter out (even though there probably is nobody reading those). I also have plans to include more services, like Facebook, but I have not yet come around to those.</p>
<p>So, a new chapter is out. I have to edit 4 MediaWiki pages (3 of those templates), one of them I have to calculate newly with a script I have written. So for calculating the <a href="http://toreas.com/Statistics" onclick="pageTracker._trackPageview('/outgoing/toreas.com/Statistics?referer=');">statistics</a> I have to open the template (which requires editing the main article first to get the edit link) run from a website a script that calls up each and every page already created and creates the stats out of that in wikitext. Now I copy paste this over from my script to the template and save it. Next I have to login to twitter, post the comment in the right format. And last but not least post the blog post on the page, again logging in, selecting the right category and tags and so on and so forth. All of this made it a horror to update and I frankly found myself thinking a few times to delay an update just because of this horrible (admittedly self induced) process.</p>
<p>Then I stumbled across an artifact in my memory. <a href="http://www.mediawiki.org/wiki/API" onclick="pageTracker._trackPageview('/outgoing/www.mediawiki.org/wiki/API?referer=');">MediaWiki has an API</a>. Looking at it <a href="http://en.wikipedia.org/w/api.php" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/w/api.php?referer=');">closely</a> I found that you could login, open pages and edit them. You could do pretty much anything with it, but those were my only requirements. After looking around a bit, I found a class named Snoopy that is supposed to take care of it, but it was still too much &#8220;manual labor&#8221; on my side. So A quick check on ZendFramework and in the Http Client library I found all the parts that I needed to make this work. I could define one client and use it like a browser. It would even keep the cookies for me and do all that handling.</p>
<p>So I whipped up my own MediaWiki API class, based on Zend_Http_Client. It actually uses the autoloader as well, but that&#8217;s because I&#8217;m lazy. So now I instantiate it by handing it the api url, a user name and password, and the whole thing is ready for duty. A get function gives me the content (needed for the latest changes, where I kill the last line in the box and add a new one on top) and an edit function that allows me to simply overwrite the current version. All the magic is done behind the scenes and no worries for me. Twitter of course also has an API to which Zend already has Zend_Service_Twitter. Again, three lines and the new status is posted. And lastly, WordPress has an XMLPRC interface, which has had me quiet confused for a while. Now that I understand it (or at least I think I do) I am able to post news in there by just supplying a title and description, while the tags and categories are preset (for this particular thing).</p>
<p>My 20 minutes of monkeying around with everything, plus additional time for writing a blog post if I was so inclined to do, has been reduced to copy pasting the story (then write the blog post) and hit a button. So for the last eight chapters I have lost two and a half hours of time, which no longer happens. Not only do I gain time, but the step to actually publish the next chapter has become pretty much nothing, as opposed to the big process it has been before.</p>
<p>Once I clean up the API class a little, I might even release my code for the MediaWiki class.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '756';
var flattr_url = 'http://christianriesen.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Christian Riesen';
var flattr_dsc = 'Life and work in the information and communication age';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2010/03/programming-helping-the-writer-and-getting-more-exposure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing missing translations in Zend Framework</title>
		<link>http://christianriesen.com/2009/12/testing-missing-translations-in-zend-framework/</link>
		<comments>http://christianriesen.com/2009/12/testing-missing-translations-in-zend-framework/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 10:03:29 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Zend_Translate]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=110</guid>
		<description><![CDATA[Zend_Translate is a wonderful tool to translate your pa [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Translate is a wonderful tool to translate your page. While your backends may vary, you have to ensure you call it everywhere in your code. Unfortunately, there is no easy way to spot any untranslated strings by default. But fear not, you can easy make one yourself.</p>
<p>Translate uses an adapter to actually do the heavy lifting. Translate itself is just a gateway to the adapter classes, so the magic happens there. Now my solution was to just create a new adapter and have it give back a string that&#8217;s fixed every single time. So any request to the translate method would return the same string. With this you can just look on your page, see where it doesn&#8217;t display your special string and there you have your missing spots. You could set it to be an empty string, but if you use it for links, then you wont see the link anymore.</p>
<p>Well used, you will only see the data strings, like user names, the configured replacement string and of course any string you missed.<br />
<span id="more-110"></span><br />
I use the App prefix for such very common bits of code that I can share easy between all my applications and of course with others, but there is nothing preventing you from changing this of course.</p>
<p>First create a file called Testing.php in the folder library/App/Translate/Adapter filled with the content below.</p>
<pre class="brush: php;">&lt;?php

/** Zend_Translate_Adapter */
require_once 'Zend/Translate/Adapter.php';

/**
 * @category   App
 * @package    App_Translate_Adapter_Testing
 * @copyright  Copyright (c) 2009 Christian Riesen &lt;chris.riesen@gmail.com&gt;
 * @license    Public Domain
 */
class App_Translate_Adapter_Testing extends Zend_Translate_Adapter
{
    private $_data = array();
    private $_teststring = 'XtestX';

    /**
     * Generates the adapter
     *
     * @param  array               $data     Translation data
     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
     *                                       see Zend_Locale for more information
     * @param  array               $options  OPTIONAL Options to set
     */
    public function __construct($data, $locale = null, array $options = array())
    {
        $this-&gt;_loadTranslationData($data, $locale, $options);
    }

    /**
     * Load translation data
     *
     * @param  string|array  $data
     * @param  string        $locale  Locale/Language to add data for, identical with locale identifier,
     *                                see Zend_Locale for more information
     * @param  array         $options OPTIONAL Options to use
     * @return array
     */
    protected function _loadTranslationData($data, $locale, array $options = array())
    {
        $this-&gt;_data = array();
        if (!is_null($data)) {
        	$this-&gt;_teststring = $data;
        }
        return $this-&gt;_data;
    }

    /**
     * Translates the given string
     * returns the translation
     *
     * @param  string|array       $messageId Translation string, or Array for plural translations
     * @param  string|Zend_Locale $locale    (optional) Locale/Language to use, identical with
     *                                       locale identifier, @see Zend_Locale for more information
     * @return string
     */
    public function translate($messageId, $locale = null)
    {
        return $this-&gt;_teststring;
    }

    /**
     * returns the adapters name
     *
     * @return string
     */
    public function toString()
    {
        return &quot;Testing&quot;;
    }
}</pre>
<p>So now it&#8217;s ready for use. To use it you have a line that starts something like this.</p>
<pre class="brush: php;">$translate = new Zend_Translate('array', ...</pre>
<p>Now this specific one would be for the array adapter. Just comment this line and add this line here.</p>
<pre class="brush: php;">$translate = new Zend_Translate('App_Translate_Adapter_Testing', 'XtestingX');</pre>
<p>All the rest can stay the same as you have used it before.</p>
<p>Load your application and all the translated strings will have changed to XtestingX and whatever is left over points you in the right direction. I checked and could not find anything this class would break, in case you use other functions with translate or the adapter directly. Of course some classes will not return something, like a list of all translations, but they should not break, should you attempt to call them.</p>
<p>Of course once you tested, you have to reverse this, or you could use a configuration option or a switch to enable it. Personally, I prefer to comment it and uncomment when really needed and testing is done. Test on a none live server, or your page will become useless in an instant (or at the least very confusing).</p>
<p>Feel free to use it, anyway you wish. I specified it as <a href="http://en.wikipedia.org/wiki/Public_domain" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Public_domain?referer=');">Public Domain</a> which I&#8217;m trying out as a license now for a while and see how feedback and experiences are with it. Yes I know that public domain is not a license per se, as it&#8217;s a free for all thing, but maybe that&#8217;s a &#8220;really good thing&#8221; &#8482;.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/12/testing-missing-translations-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sphinx 0.9.9-release finally out</title>
		<link>http://christianriesen.com/2009/12/sphinx-0-9-9-release-finally-out/</link>
		<comments>http://christianriesen.com/2009/12/sphinx-0-9-9-release-finally-out/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 08:39:07 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sphinx]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=108</guid>
		<description><![CDATA[What's that supposed to be, I have been asked a couple  [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s that supposed to be, I have been asked a couple of times. <a href="http://www.sphinxsearch.com/" onclick="pageTracker._trackPageview('/outgoing/www.sphinxsearch.com/?referer=');">Sphinx</a> is <strong>the</strong> solution to a very ugly and rather common problem.</p>
<p>You want one entry form a database, selected by a unique ID number. In most cases you have an index, probably even a primary index that will find your record in no time. That is the ideal case though. Now you make lists with many entries, where you already have a much larger set of data to wrangle and again indexes can be your friend, but are less well performing as when you could select them by ID. And worst of all is full text searching. You want all entries that contain a text in multiple fields. Maybe even partial matches and so on. Doing this with just a normal query involves things as LIKE and probably under MySQL the % sign. If you don&#8217;t have many entries this might even work well enough. Queue up large databases and you are completely out of luck.</p>
<p>Sphinx helps you with these scenarios.<br />
<span id="more-108"></span><br />
In Sphinx you run a indexer program that goes into the database and generates it&#8217;s own index for words and even partial words. Depending on the configuration you can teach it to not do partial matches, even match in the middle of the words or treat similar words as one and the same word (both on indexing and on search queries). Switching to Sphinx is very simple. You have to install Sphinx on your server (which is very easy), setup the configuration file to reflect your database and search preferences and then just run the indexer script periodically (depending on your content). Inside your application you change the path that leads to those LIKE queries to ask Sphinx over the supplied API. Now Sphinx does not return the results from the database, but gives you a list of id&#8217;s you can then use to query the database. Now you can run just a fast fetch for those id&#8217;s and you have your result set.</p>
<p>If you just search for all entries from category X or user Z then you are still better off just using the usual ways. But you need full text searching, then Sphinx is your perfect solution.</p>
<p>And now the <a href="http://www.sphinxsearch.com/news/40.html" onclick="pageTracker._trackPageview('/outgoing/www.sphinxsearch.com/news/40.html?referer=');">latest version is out</a>. There are a lot of bugs squished in it, but most not very important, which goes to show how well it has worked now for a long while already. My oldest installation runs for over a year now without a glitch on the Sphinx end.</p>
<p>Currently Sphinx needs to rebuild the whole index each time you want it rebuilt, or use something called delta indexing, which is more a stopgap measure. A real-time updating index is on the menu for the next version though and will make this extremely powerful tool even better.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '756';
var flattr_url = 'http://christianriesen.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Christian Riesen';
var flattr_dsc = 'Life and work in the information and communication age';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/12/sphinx-0-9-9-release-finally-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wget in php</title>
		<link>http://christianriesen.com/2009/10/wget-in-php/</link>
		<comments>http://christianriesen.com/2009/10/wget-in-php/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 13:12:16 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=92</guid>
		<description><![CDATA[Ok, this is far from what wget is capable of, but most  [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, this is far from what wget is capable of, but most people do only need one function for wget. Enter url, get content. Especially during the setup phase this is often needed and sometimes wget is not available or libraries are missing. For those that have a working php installation but no working wget, this little script does exactly that, download a file and save it locally. This little helper has done valuable services for me now a few times, so here it is for anyone to use.</p>
<pre class="brush: php;">&lt;?php
// wget substitute
if ($argc != 2) {
?&gt;
This works a bit like wget. Just run it with the url as argumnet
&lt;?php
    exit;
}

$url = $argv[1];
$filename = basename($url);

file_put_contents($filename,file_get_contents($url));

echo PHP_EOL. 'Written file ' . $filename . PHP_EOL;</pre>
<p>Usage is rather simple now:<br />
<code>php wget.php URL</code></p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/10/wget-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ant and Zend Studio</title>
		<link>http://christianriesen.com/2009/09/ant-and-zend-studio/</link>
		<comments>http://christianriesen.com/2009/09/ant-and-zend-studio/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 11:47:16 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Zend Studio]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=84</guid>
		<description><![CDATA[For whatever reason Ant has been disabled in Zend Studi [...]]]></description>
			<content:encoded><![CDATA[<p>For whatever reason Ant has been disabled in Zend Studio. Thankfully some rather nice guy by the name of Max Horvath has already stumbled upon this and solved it. <a href="http://www.maxhorvath.com/2008/08/how-to-enable-the-ant-plugin-in-zend-studio-for-eclipse.html" onclick="pageTracker._trackPageview('/outgoing/www.maxhorvath.com/2008/08/how-to-enable-the-ant-plugin-in-zend-studio-for-eclipse.html?referer=');">In his post</a>, dating back a year now, he describes how you first need to have Eclipse Java Development Tools installed. Once that is installed, you start a new &#8220;Java Project from Existing Ant Buildfile&#8221;. It will ask you if it should enable Ant, which you should say yes, and with that done, you can already cancel the wizard for this. Voila, Ant is installed.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '756';
var flattr_url = 'http://christianriesen.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Christian Riesen';
var flattr_dsc = 'Life and work in the information and communication age';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/09/ant-and-zend-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making lists easier and more beautiful</title>
		<link>http://christianriesen.com/2009/08/making-lists-easier-and-more-beautiful/</link>
		<comments>http://christianriesen.com/2009/08/making-lists-easier-and-more-beautiful/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 10:57:07 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=76</guid>
		<description><![CDATA[There is a small dilemma on how to create a neat listin [...]]]></description>
			<content:encoded><![CDATA[<p>There is a small dilemma on how to create a neat listing such as this: a, b, c, d</p>
<p>Sometimes you need it for programming reasons, SQL is often pretty unhelpful if you got an extra comma there. Sometimes you just want it that way because it looks nice. Usually you have values in an array to begin with.</p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');</pre>
<p>Now you need to do soemthing with each entry, well, that screams foreach.</p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');
$out = '';
foreach ($array as $value)
{
	$out .= $value . ', ';
}</pre>
<p>But that gives you the dangling comma and a space at the end. So you could now trim that off the end (substr) or already do it the right way in the foreach. That could look something like this.<br />
<span id="more-76"></span></p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');
$out = '';
$first = true;
foreach ($array as $value)
{
	if (true == $first)
	{
		$first = false;
	}
	else
	{
		$out .= ', ';
	}
	$out .= $value;
}</pre>
<p>Now we also need to add a link around it.</p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');
$out = '';
$first = true;
foreach ($array as $value)
{
	if (true == $first)
	{
		$first = false;
	}
	else
	{
		$out .= ', ';
	}
	$out .= '&lt;a href=&quot;/' . $value . '/&quot;&gt;' . $value . '&lt;/a&gt;';
}</pre>
<p>A lot of code and a lot of extra checks for not much gain really. Isn&#8217;t there a better way? After all there is only a need for this addition in between the parts of the array. If only there was a function that puts something between the pieces of an array. Ah but yes there is, and it&#8217;s called implode. If we had the first simple array and list this could be over rather quick like this.</p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');
$out = implode(', ', $array);</pre>
<p>But we have this extra data we need around the array, so what do we do? Well first generate a new array, then implode of course, like this.</p>
<pre class="brush: php;">$array = ('a', 'b', 'c', 'd');
$temp = array();
foreach ($array as $value)
{
	$temp[] = '&lt;a href=&quot;/' . $value . '/&quot;&gt;' . $value . '&lt;/a&gt;';
}
$out = implode(', ', $temp);
unset($temp);</pre>
<p>Much more comfortable and also much more readable now. First one round preparing, then gluing the pieces into the string. And of course, if you don&#8217;t need it anymore, unset the array or you will carry that data around the application for no reason.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/08/making-lists-easier-and-more-beautiful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparing folders over system boundaries</title>
		<link>http://christianriesen.com/2009/08/comparing-folders-over-system-boundaries/</link>
		<comments>http://christianriesen.com/2009/08/comparing-folders-over-system-boundaries/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 08:09:39 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=80</guid>
		<description><![CDATA[Following scenario: Two servers, one Linux, one windows [...]]]></description>
			<content:encoded><![CDATA[<p>Following scenario: Two servers, one Linux, one windows, and some months ago someone copied from windows to Linux a code base. As things happen, the windows server was still in use so changes were made and supposed to be ported to the Linux server as well. And again, as it happens, that did, well, not happen. Now under Linux you would have a few nice tools to do the job, but Windows, not so much.</p>
<p>So, using a windows workstation I connected to both locations and did a search in the windows explorer. Don&#8217;t worry, this insanity has a method. Since I knew the date of when the full copy was made, I could simply search for all files on the windows server that are modified after said date. Only problem now, how to get the list into something usable? I mean you can&#8217;t just copy that 6000 files list into notepad or your favorite spreadsheet.</p>
<p>For that there is a free little tool called <a href="http://www.nirsoft.net/utils/sysexp.html" onclick="pageTracker._trackPageview('/outgoing/www.nirsoft.net/utils/sysexp.html?referer=');">SysExporter</a>. It will allow you to copy not only the content of any list under windows, but also have it as a tab delimited list.</p>
<p>That saved and a second file for the Linux server in the same format (for easy comparison), now all I had to do was run a PHP script that parses both files as CSV files, using the tabulator character as delimiter and voila, you have two arrays in the same structure that you can compare. There I compared file name and the folder (after normalizing both so the beginning is the same for each). On no match, it&#8217;s written in a new file. All those entries in the new file are then my list of files I have to copy and check for needed changes. Of course it&#8217;s still the same tab delimited format so you can just import it into a spreadsheet for easier sorting and display.</p>
<p>As a small caveat, windows likes to also search in ZIP files. If you do not really need that, you should disable it. Just go to start, run, then enter this: regsvr32 /u %windir%\system32\zipfldr.dll<br />
A small box appears telling you all went well and now you no longer search for ZIP files. You should maybe get yourself some replacement like <a href="http://www.7-zip.org/" onclick="pageTracker._trackPageview('/outgoing/www.7-zip.org/?referer=');">7zip</a> while you are at it.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '756';
var flattr_url = 'http://christianriesen.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Christian Riesen';
var flattr_dsc = 'Life and work in the information and communication age';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/08/comparing-folders-over-system-boundaries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a MySQL dump in CSV format</title>
		<link>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/</link>
		<comments>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 07:33:47 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=39</guid>
		<description><![CDATA[Mostly, a dump of a db is wanted in SQL. In case of eme [...]]]></description>
			<content:encoded><![CDATA[<p>Mostly, a dump of a db is wanted in SQL. In case of emergency import file. But some people do not comprehend SQL or their SQL doesn&#8217;t like your SQL and everything goes down the drain. So there is the CSV or Comma-separated values file. As the name says, it separates the values by commas (and more if needed). Since it&#8217;s so dead simple, you will get a lot of different tools and program languages that will make life easy for you to re-import or just search in it. Microsoft Excel and Openoffice Calc both can handle the format as well, so for a quick look, this will do very nicely.</p>
<p>But there is no simple &#8211;csv switch in mysqldump, your weapon of choice for these tasks. So here the command that will allow you to do what you are after:</p>
<p><code>mysqldump -p -u USER -T DIRECTORY --fields-enclosed-by=\" --fields-terminated-by=, DATABASE</code></p>
<p>So this is the short version, and here what it all means:</p>
<ul>
<li>-p : Asks for a password, as most users have one. If you don&#8217;t specify this on a database with a user/password, it will error</li>
<li>-u USER : Replace USER with your actual username to connect to the database.</li>
<li>-T DIRECTORY : This creates a tab delimited file. Not what we wanted but it&#8217;s the base we need.</li>
<li>&#8211;fields-enclosed-by=\&#8221; : Will add &#8221; characters around the fields. This will allow CSV implementations to find everything that fits together. You will need that backslash or it wont run.</li>
<li>&#8211;fields-terminated-by=, : The so much sought after comma. This replaces the tab and puts a comma in its place, which, you guessed it, creates the CSV file.</li>
<li>DATABASE : Well you know, the thing this is all about&#8230;</li>
</ul>
<p>To actually be able to do it though, you will need the FILE privilege on this database. Armed with this, you should be able to do your CSV exports easy now.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/06/creating-a-mysql-dump-in-csv-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cycling between strings</title>
		<link>http://christianriesen.com/2009/06/cycling-between-strings/</link>
		<comments>http://christianriesen.com/2009/06/cycling-between-strings/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 07:47:36 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=29</guid>
		<description><![CDATA[I'm certain every programmer who wanted to something a  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m certain every programmer who wanted to something a bit more fancy came across this problem. You want to cycle through 2 or more values, and then start from the beginning again, but all of this easy and fast. The standard implementation I have seen so far is to define a variable, then count it up until it has reached a also predefined maximum value, and reset it to the start value. Rinse repeat.</p>
<p>Often this is paired with an array and keys to find the correct content. Sometimes a function is used as a wrapper (using static variables more often than not) and similar rather ugly things.</p>
<p>Well, what does keep a state in itself very well? A class of course.</p>
<p>On Aidan Lister&#8217;s page I cam across a very interesting piece of code that <a href="http://aidanlister.com/2004/04/cycling-between-strings-a-novel-implementation/" onclick="pageTracker._trackPageview('/outgoing/aidanlister.com/2004/04/cycling-between-strings-a-novel-implementation/?referer=');">cycles between strings</a>. You instantiate the class with the values to cycle through given to the constructor. Now from here on out all you do is use the variable, holding the object directly like it would contain the value you need directly, say an integer or a string. Through the magic method __toString() it then dispenses the current value and advances the pointer, or wraps it around to the start.</p>
<p>Very simple yet powerful and also some food for thought, as this exact method might work well on other problems.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '756';
var flattr_url = 'http://christianriesen.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Christian Riesen';
var flattr_dsc = 'Life and work in the information and communication age';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank" onclick="pageTracker._trackPageview('/outgoing/flattr.com/?referer=');"><img src="http://christianriesen.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2009/06/cycling-between-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
