<?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>Patrick&#039;s playground</title>
	<atom:link href="http://www.vankouteren.eu/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vankouteren.eu/blog</link>
	<description>Random thoughts, problems and solutions</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP SPL data structure: SplFixedArray</title>
		<link>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/</link>
		<comments>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 14:51:31 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[SplFixedArray]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=267</guid>
		<description><![CDATA[PHP 5.3 introduced some new data structures. The talk of Jurriën Stutterheim on PFCongres 2011 on SPL structures and their performance triggered me to have a closer look at the performance of these structures. I was kind of fooled by two comments on the PHP.net page, so it was time to find out myself. For [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
<p>PHP 5.3 introduced some new data structures. The talk of Jurriën Stutterheim on<a title="PFCongres" href="http://www.pfcongres.nl/"> PFCongres 2011</a> on SPL structures and their performance triggered me to have a closer look at the performance of these structures. I was kind of fooled by two comments on the <a title="SplFixedArray PHP.net page" href="http://www.php.net/manual/en/class.splfixedarray.php">PHP.net page</a>, so it was time to find out myself.</p>
<p><span id="more-267"></span>For people familiar with Java the SplFixedArray is not a strange structure as they are common structures in this language. PHP only used arrays in the past.</p>
<p>The common array structure may contain all kind of keys (one can use strings, integers and even combine them) and under the hood PHP uses a hashing algorithm to create a unique array index for these keys. So actually under the hood these arrays are comparable to Java HashMaps. Like a database can create indexes on keys, PHP creates an index on the hashed indexes to speed up item retrieval from the array. However: hashing does not guarantee a unique output for every unique input. It may well be that two completely different keys result in a same hashed value. A hashing algorithm can sort this out in its own way (there are various way to do this, but I think this is out of the scope of this post right now), so there's another level of complexity here.</p>
<p>The new SplFixedArray has a pre-defined size and can only contain integer keys. As the size is limited this saves memory and the indexing is done more efficient. It does away with all hashing related issues which saves time. Now the question is: how much time does it save me?</p>
<p><strong>Hey: we're running PHP, not Java.. I didn't have to bother with memory usage, why would I do that now all of a sudden?</strong></p>
<p>You don't have to if you don't like to, but there may be a lot to gain for you. Especially when you are using a lot of arrays of which you know the size beforehand as well as the positions of items. In an environment which often is under heavy load the benefits of SplFixedArray may come in handy for you. (And updating software is cheaper than updating hardware..)</p>
<p><strong>Numbers</strong></p>
<p>As I said I was fooled at first by two comments on the <a title="PHP.net SplFixedArray" href="http://www.php.net/manual/en/class.splfixedarray.php">PHP.net manual</a>: <a title="SplFixedArray test 1" href="http://www.php.net/manual/en/class.splfixedarray.php#92214">this one</a> and <a title="SplFixedArray test 2" href="http://www.php.net/manual/en/class.splfixedarray.php#94179">this one</a>.</p>
<p>The first one tests the speed of insertions in the regular array and the speed of insertions in the SplFixedArray and returns all positives for the SplFixedArray.</p>
<p>The latter one claims to be more realistic, but results in a fatal error directly because the author is trying to insert items on positions outside the range of the SplFixedArray (index out of bounds exception, also common in Java). If this is a realistic example I would reconsider using PHP <img src='http://www.vankouteren.eu/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I've compiled a simple script to test the speeds and memory sizes of array vs SplFixedArray. To (kind of) prevent small background processes influencing the results these tests are done multiple times and averaged. The results are shown below. Please note that these results may vary every time you execute the script. However: the larger the size of the array, the less variance occurs and the more reliable the numbers are.</p>
<p><em>script:</em></p>
<p><pre class="brush: php">&lt;?php

$maxSize = (int) $_GET['size'];
$times = (int) $_GET['times'];

set_time_limit(0);

echo &quot;&lt;h2&gt;Number of repeated tests: &quot; . $times . &quot;&lt;/h2&gt;&quot;;
echo &quot;&lt;table border='1'&gt;&quot;;
echo &quot;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Items&lt;/th&gt;&lt;th&gt;Time Array&lt;/th&gt;&lt;th&gt;Memory Array&lt;/th&gt;&lt;th&gt;SplFixedArray&lt;/th&gt;&lt;th&gt;Memory SplFixedArray&lt;/th&gt;&lt;th&gt;Array/SplFixedArray ratio&lt;/th&gt;&lt;th&gt;Speed increase by SplFixedArray&lt;/th&gt;&lt;th&gt;Memory reduction by SplFixedArray&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot;;
echo &quot;&lt;tbody&gt;&quot;;

for($size = 1000; $size &lt; $maxSize; $size *= 2) {
	
	echo &quot;&lt;tr&gt;&lt;td align='right'&gt;&quot; . $size . &quot;&lt;/td&gt;&quot;;
	
	$arrTotal = 0;
	$arrMemUsage = 0;
	for($time = 0; $time &lt; $times; $time++){
		$mStart = memory_get_usage();
		$container1 = array();
		for($s = microtime(true), $i = 0; $i &lt; $size; $i++) {
			$container1[$i] = 1;
		}
		
		$arrMemUsage += (memory_get_usage() - $mStart);
		$arrTime = (microtime(true) - $s);
		$arrTotal += $arrTime;
	}
	
	$avgArrMem = ($arrMemUsage / $times);
	$avgArr = ($arrTotal / $times);
	echo &quot;&lt;td align='right'&gt;&quot; . $avgArr  . &quot;&lt;/td&gt;&quot;;
	echo &quot;&lt;td align='right'&gt;&quot; . $avgArrMem . &quot;&lt;/td&gt;&quot;;
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($arrTotal);
	unset($arrMemUsage);
	unset($container1);
	
	$splFixedArrTotal = 0;
	$splFixedArrMemUsage = 0;
	for($time = 0; $time &lt; $times; $time++){
		$mStart = memory_get_usage();
		$container2 = new SplFixedArray($size);
		for($s = microtime(true), $i = 0; $i &lt; $size; $i++) {
			$container2[$i] = 1;
		}
		
		$splFixedArrMemUsage += (memory_get_usage() - $mStart);
		$splFixedArrTime = (microtime(true) - $s);
		$splFixedArrTotal += $splFixedArrTime;
	}
	
	$avgSplFixedArrMem = ($splFixedArrMemUsage / $times);
	$avgSplFixedArr = ($splFixedArrTotal / $times);
	echo &quot;&lt;td align='right'&gt;&quot; . $avgSplFixedArr . &quot;&lt;/td&gt;&quot;;
	echo &quot;&lt;td align='right'&gt;&quot; . $avgSplFixedArrMem . &quot;&lt;/td&gt;&quot;;
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($splFixedArrTotal);
	unset($splFixedArrMemUsage);
	unset($container2);
	
	// Calculate ratio
	echo &quot;&lt;td align='right'&gt;&quot; . ($avgArr / $avgSplFixedArr) . &quot;&lt;/td&gt;&quot;;
	// Calculate speed increase percentage
	echo &quot;&lt;td align='right'&gt;&quot; . number_format(((($avgSplFixedArr - $avgArr) / $avgArr) * -100), 4) . &quot; %&lt;/td&gt;&quot;;
	// Calculated memory reduction percentage
	if ($avgArrMem == 0){
		echo &quot;&lt;td align='right'&gt;NaN&lt;/td&gt;&lt;/tr&gt;&quot;;
	}
	else {
		echo &quot;&lt;td align='right'&gt;&quot; . number_format(((($avgSplFixedArrMem - $avgArrMem) / $avgArrMem) * -100), 4) . &quot; %&lt;/td&gt;&lt;/tr&gt;&quot;;
	}
	
	// Cleanup to REDUCE the influence of memory blocks on the result
	unset($avgArr);
	unset($avgSplFixedArr);

}

echo &quot;&lt;/tbody&gt;&lt;/table&gt;&quot;;

?&gt;</pre></p>
<p><em>results:</em></p>
<p><a href="http://www.vankouteren.eu/blog/wp-content/uploads/2011/09/arrayvssplfixedarrayresult.jpg">Results (regular table didn't fit the page)</a></p>
<p><strong>So what does it say?</strong></p>
<p><strong></strong>Well regarding the memory the usage has been decreased by around 58% in this case. This, of course, is due to the fact that the SplFixedArray has a limited size and therefor a (pre-defined) limited space in the memory reserved. There is some gain in speed as well.</p>
<p><strong>So is it better to use?</strong></p>
<p>That really depends. The SplFixedArray has some advantages, but also some drawbacks compared to the common array. It should be used where it fits: if you need an array of a size which can be pre-defined and where you need integer keys. It's also a good (at least, I think.. but I started with Java..) habit to use the appropriate data structures.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/09/php-spl-data-structure-splfixedarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SimpleAdapter for populating simple_list_item_2 with Strings</title>
		<link>http://www.vankouteren.eu/blog/2011/09/using-simpleadapter-for-populating-simple_list_item_2-with-strings/</link>
		<comments>http://www.vankouteren.eu/blog/2011/09/using-simpleadapter-for-populating-simple_list_item_2-with-strings/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 06:29:00 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[simpe_list_item_row_2]]></category>
		<category><![CDATA[SimpleAdapter]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=264</guid>
		<description><![CDATA[I don't know it it's my searching skills which are fading or the lack of examples, but I wasn't able to find a simple example on how to use the simple_list_item_2 which is built into Android. I've used some custom layouts to establish the same result, and sometimes some extras (display an icon on the [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
<p>I don't know it it's my searching skills which are fading or the lack of examples, but I wasn't able to find a simple example on how to use the simple_list_item_2 which is built into Android. I've used some custom layouts to establish the same result, and sometimes some extras (display an icon on the right for example). However, now I wanted to use the built-in feature, but had to search quite some time. If you experience the same, hopefully this post will save you time.</p>
<p><span id="more-264"></span>I know: it's basic, but I'm still learning Android, so I think I may behave like a n00b at the moment <img src='http://www.vankouteren.eu/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>So, what do we need for setting up the list:</p>
<ul>
<li>screen layout</li>
<li>activity</li>
<li>list content</li>
</ul>
<p>Let's go! First create a layout:</p>
<p><pre class="brush: xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout
	android:id=&quot;@+id/screen_about_layout&quot;
	android:layout_width=&quot;fill_parent&quot;
	android:layout_height=&quot;fill_parent&quot;
	android:orientation=&quot;vertical&quot;
	xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
&gt;
	&lt;RelativeLayout
		android:id=&quot;@+id/screen_title_bar&quot;
		android:layout_width=&quot;fill_parent&quot;
		android:layout_height=&quot;60px&quot;
		android:layout_alignParentTop=&quot;true&quot;
		android:layout_alignParentLeft=&quot;true&quot;
		android:background=&quot;@drawable/title_bar&quot;
	&gt;
		&lt;TextView
			android:id=&quot;@+id/screen_top_title&quot;
			android:layout_width=&quot;wrap_content&quot;
			android:layout_height=&quot;wrap_content&quot;
			android:text=&quot;@string/screen_more_title&quot;
			android:layout_centerVertical=&quot;true&quot;
			android:layout_alignParentLeft=&quot;true&quot;
			android:textSize=&quot;18sp&quot; 
			android:textColor=&quot;@color/white&quot;
			android:paddingLeft=&quot;10px&quot;
		&gt;
		&lt;/TextView&gt;
		&lt;ImageButton
			android:id=&quot;@+id/screen_top_info&quot;
			android:layout_width=&quot;wrap_content&quot;
			android:layout_height=&quot;wrap_content&quot;
			android:src=&quot;@drawable/icon_info&quot;
			android:layout_centerVertical=&quot;true&quot;
			android:layout_alignParentRight=&quot;true&quot;
			android:paddingRight=&quot;10px&quot;
			android:background=&quot;@null&quot;
		&gt;
		&lt;/ImageButton&gt;	
	&lt;/RelativeLayout&gt; 

&lt;!-- Set height to 0, and let the weight param expand it --&gt;
    &lt;!-- Note the use of the default ID! This lets us use a 
         ListActivity still! --&gt;
    &lt;ListView android:id=&quot;@android:id/list&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:layout_height=&quot;0dip&quot;
        android:layout_weight=&quot;1&quot; 
         /&gt; 

&lt;/LinearLayout&gt;</pre></p>
<p>Note that the list has an id called '@android:id/list'. This enables us to directly use the list in the Activity as it's going to extend ListActivity.</p>
<p>In the Activity itself we define an ArrayList containing HashMaps from String to String. Basically this means that we create a list which will contain key, value pairs which we are going to control (This is similar to associative arrays in PHP). We will use the key 'line1' for the upper line and 'line2' for the lower line. With the variables from and to we map the values of the keys we supply (this is the from variable) to the TextViews of the simple_list_item_row_2 (the to variable). These are called text1 and text2.</p>
<p><pre class="brush: java">package com.example.sampleapp;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

public class MoreScreen extends ListActivity {

	ArrayList&lt;HashMap&lt;String, String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(
			2);

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_more);

		HashMap&lt;String, String&gt; map;

		map = new HashMap&lt;String, String&gt;();
		map.put(&quot;line1&quot;, &quot;Foo&quot;);
		map.put(&quot;line2&quot;, &quot;Bar&quot;);
		list.add(map);

		map = new HashMap&lt;String, String&gt;();
		map.put(&quot;line1&quot;, &quot;Hi&quot;);
		map.put(&quot;line2&quot;, &quot;Bye&quot;);
		list.add(map);

		// the from array specifies which keys from the map
		// we want to view in our ListView
		String[] from = { &quot;line1&quot;, &quot;line2&quot; };

		// the to array specifies the TextViews from the xml layout
		// on which we want to display the values defined in the from array
		int[] to = { android.R.id.text1, android.R.id.text2 };

		// create the adapter and assign it to the listview
		SimpleAdapter adapter = new SimpleAdapter(this, list,
				android.R.layout.simple_list_item_2, from, to);
		setListAdapter(adapter);

	}

}</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/09/using-simpleadapter-for-populating-simple_list_item_2-with-strings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom checkboxes for CheckBoxPreferences on Android</title>
		<link>http://www.vankouteren.eu/blog/2011/09/custom-checkboxes-for-checkboxpreferences-on-android/</link>
		<comments>http://www.vankouteren.eu/blog/2011/09/custom-checkboxes-for-checkboxpreferences-on-android/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 22:10:39 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[JAVA]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=261</guid>
		<description><![CDATA[For an App I'm writing I need to use custom checkboxes in a PreferenceScreen. I want to use the CheckboxPreferences as it's designed for that. Many searches lead to StackOverflow, but caused me a stack overflow as well as they didn't work. In this (short) post I outline my findings and provide a working solution [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
<p>For an App I'm writing I need to use custom checkboxes in a PreferenceScreen. I want to use the CheckboxPreferences as it's designed for that. Many searches lead to StackOverflow, but caused me a stack overflow as well as they didn't work. In this (short) post I outline my findings and provide a working solution step by step.<span id="more-261"></span></p>
<p><strong>Step 1</strong></p>
<p>You need a custom checkbox. This can be defined in a drawable. In this case I've called the file checkbox.xml and placed it in the drawable folder. The code defines the images for two states: if the checkbox is enabled and when it's disabled. For this file looks like this:</p>
<p><pre class="brush: xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &lt;item android:state_checked=&quot;true&quot;
          android:drawable=&quot;@drawable/checkbox_checked&quot; /&gt; &lt;!-- checked --&gt;
    &lt;item android:state_checked=&quot;false&quot; 
    	android:drawable=&quot;@drawable/checkbox_unchecked&quot; /&gt; &lt;!-- default --&gt;
&lt;/selector&gt;</pre></p>
<p><strong>Step 2</strong></p>
<p>We need a layout for customized preferences. This layout defines the same stuff as the ' regular'  preference does (text, summary etc.). Note the last part in the following file (called checkbox_preference.xml and placed in the layout folder). It loads our custom checkbox!</p>
<p><pre class="brush: xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!-- Copyright (C) 2006 The Android Open Source Project Licensed under the 
    Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except 
    in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
    Unless required by applicable law or agreed to in writing, software distributed 
    under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES 
    OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
    the specific language governing permissions and limitations under the License. --&gt;

&lt;!-- Layout for a Preference in a PreferenceActivity. The Preference is able 
    to place a specific widget for its particular type in the &quot;widget_frame&quot; 
    layout. --&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot;
    android:minHeight=&quot;?android:attr/listPreferredItemHeight&quot;
    android:gravity=&quot;center_vertical&quot; android:paddingRight=&quot;?android:attr/scrollbarSize&quot;&gt;

    &lt;RelativeLayout android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot; android:layout_marginLeft=&quot;15dip&quot;
        android:layout_marginRight=&quot;6dip&quot; android:layout_marginTop=&quot;6dip&quot;
        android:layout_marginBottom=&quot;6dip&quot; android:layout_weight=&quot;1&quot;&gt;

        &lt;TextView android:id=&quot;@+android:id/title&quot;
            android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;
            android:singleLine=&quot;true&quot; android:textAppearance=&quot;?android:attr/textAppearanceLarge&quot;
            android:ellipsize=&quot;marquee&quot; android:fadingEdge=&quot;horizontal&quot; /&gt;

        &lt;TextView android:id=&quot;@+android:id/summary&quot;
            android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;
            android:layout_below=&quot;@android:id/title&quot; android:layout_alignLeft=&quot;@android:id/title&quot;
            android:textAppearance=&quot;?android:attr/textAppearanceSmall&quot;
            android:maxLines=&quot;4&quot; /&gt;

    &lt;/RelativeLayout&gt;

&lt;CheckBox android:id=&quot;@+android:id/checkbox&quot;
		android:layout_width=&quot;wrap_content&quot;
		android:layout_height=&quot;wrap_content&quot;
		android:button=&quot;@drawable/checkbox&quot; /&gt;

&lt;/LinearLayout&gt;</pre></p>
<p><strong>Step 3</strong></p>
<p>Now the code below is the actual layout which you inflate with your SharedPreferences in your Activity. The layout attribute is used to put the custom layout with the custom checkbox as an item in there.</p>
<p><pre class="brush: xml"> &lt;PreferenceScreen xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;

	&lt;PreferenceCategory
		android:title=&quot;@string/category_title&quot;&gt;
		
	&lt;CheckBoxPreference
	android:key=&quot;preferenceKey&quot;
	android:title=&quot;@string/preferenceTitle&quot;
	android:defaultValue=&quot;false&quot;
	android:layout=&quot;@layout/checkbox_preference&quot;
	/&gt;
	&lt;/PreferenceCategory&gt;
&lt;/PreferenceScreen&gt;</pre></p>
<p><strong>Step 4</strong></p>
<p>There is no step 4. You're done! It shouldn't be that hard to find and use these things. Unfortunately many same questions, but more different (and often not / not completely working replies / solutions) are posed on sites like StackOverflow which makes it harder to find the real solution. Hopefully this post is a worthy addition to the interwebs and a valuable resource for Android designers facing the same problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/09/custom-checkboxes-for-checkboxpreferences-on-android/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Propel and the zero date issue</title>
		<link>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/</link>
		<comments>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 11:58:47 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[0000-00-00]]></category>
		<category><![CDATA[Propel 1.5.4]]></category>
		<category><![CDATA[Propel 1.6.0]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=255</guid>
		<description><![CDATA[Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL ('0000-00-00') and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
<p>Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL ('0000-00-00') and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what I did to solve it.<span id="more-255"></span><br />
So what's all the fuzz about? It's about a query like this:<br />
<pre class="brush: php">$contractObjectCollection = ContractQuery::create()
            -&gt;filterByOrderId($this-&gt;getID())
            -&gt;condition('contractToAfterNow', 'Contract.ContractTo &gt; ?', date('Y-m-d'))
            -&gt;condition('contractToIsNul', 'Contract.ContractTo = ?', '0000-00-00')
            -&gt;combine(array('contractToAfterNow', 'contractToIsNul'), 'or', 'contractToCondition')
            -&gt;condition('contractFromIsFilledIn', 'Contract.ContractFrom &lt;= ?', date('Y-m-d'))
            -&gt;combine(array('contractToCondition', 'contractFromIsFilledIn'))
            -&gt;orderByContractFrom('asc')
            -&gt;orderByContractId('asc')
            -&gt;find();</pre></p>
<p>This query gathers contracts which are active (e.g. valid, started and not ended) at this moment.<br />
In Propel 1.5.4 this code translates to the following query:<br />
<pre class="brush: sql">SELECT contract.* FROM `contract` WHERE contract.ORDER_ID='1' AND ((contract.CONTRACT_TO &gt; '2011-06-07' OR contract.CONTRACT_TO = '0000-00-00') AND contract.CONTRACT_FROM &lt;= '2011-06-07') ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC</pre></p>
<p>However, in Propel 1.6.0 the code translates to:<br />
<pre class="brush: sql">SELECT contract.* FROM `contract` WHERE contract.ORDER_ID='1' AND ((contract.CONTRACT_TO &gt; '2011-06-07' OR contract.CONTRACT_TO = '-0001-11-30') AND contract.CONTRACT_FROM &lt;= '2011-06-07') ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC</pre></p>
<p>Instead of putting 0000-00-00 in the query, the date is translated to -0001-30-11. (Should I read this as 30th of November 1969?)<br />
As my code relies heavily on the outcome of the query, I had to find a quick solution. After some informing on IRC I learned that there seems to be an issue concerning these zero dates (Propel prefers using NULL instead of 0000-00-00, but my application is a legacy application).<br />
The actual solution comes down to writing the query by hand, using the (Debug)PDO instance for querying and using the PropelObjectFormatter to hydrate the results back into the objects you want to be working with.</p>
<p><pre class="brush: php">$query = &quot;SELECT contract.*
        FROM `contract` WHERE contract.ORDER_ID=1&quot;
             AND ((contract.CONTRACT_TO &gt; '&quot; . date('Y-m-d') .
            &quot;' OR contract.CONTRACT_TO = '0000-00-00') AND contract.CONTRACT_FROM &lt;= '&quot; . date('Y-m-d') . &quot;')
            ORDER BY contract.CONTRACT_FROM ASC,contract.CONTRACT_ID ASC&quot;;

        $con = Propel::getConnection();
        $stmt = $con-&gt;prepare($query);
        $stmt-&gt;execute();

        $formatter = new PropelObjectFormatter();
        $formatter-&gt;setClass('Contract');
        $contractObjectCollection = $formatter-&gt;format($stmt);</pre></p>
<p>And that's it. It cost me a little time to figure this out, but my deployment was saved.</p>
<p><strong>Slight note</strong><br />
Please note that Propel normally puts all fields separately in the SELECT statement, but that I've shortened it by putting down the * sign</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/06/propel-and-the-zero-date-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your Plesk Watchdog in 2011</title>
		<link>http://www.vankouteren.eu/blog/2011/01/your-plesk-watchdog-in-2011/</link>
		<comments>http://www.vankouteren.eu/blog/2011/01/your-plesk-watchdog-in-2011/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 07:55:17 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Webhosting]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[Watchdog]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=235</guid>
		<description><![CDATA[Plesk users (version 8.x up to 10.x as far as I've heared) are getting errors from the Watchdog module. Parallels is coming out with an update for this error in the future, but they can't tell when (yet). These errors occur on daily basis and are actually pretty easy to fix. You might have two [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
<p>Plesk users (version 8.x up to 10.x as far as I've heared) are getting errors from the Watchdog module. Parallels is coming out with an update for this error in the future, but they can't tell when (yet). These errors occur on daily basis and are actually pretty easy to fix. You might have two errors (after each other), but this fix will solve them <a href="http://forum.parallels.com/showpost.php?p=435312&amp;postcount=73" target="_blank">both</a>.</p>
<p><span id="more-235"></span></p>
<p>The first error which occurs since the first of January 2011 is the following one:</p>
<p><pre class="brush: sql">ERROR: WDExc

Error occurred while processing database query: 'MySQL query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group by service_id, type, round(unix_timestamp(time) / 200, 0) having count(val' at line 3'

0: wdlib.php:1089

wd__db_query(string 'select service_id, type, unix_timestamp(min(time)) as min_time, unix_timestamp(max(time)) as max_time, avg(value) as avg

from module_watchdog_sys_stat where

group by service_id, type, round(unix_timestamp(time) / 200, 0) having count(value) &gt; 1 limit 10000;')

1: pack-sysstats:63

pack_statistics(integer '200', boolean  false, boolean  false)

2: pack-sysstats:44</pre></p>
<p>At the time being I was running Plesk 9.5.2. As Plesk 10 was out, I thought that would fix the problem. It kind of did, as I got a different error message:</p>
<p><pre class="brush: php">/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats: line 1: ?php: No such file or directory

/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats: line 2: syntax error near unexpected token `&quot;The file {$_SERVER['SCRIPT_FILENAME']} is part of Plesk 9 distribution. It cannot be run outside of Plesk 9 environment.\n&quot;'

/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats: line 2: `    die(&quot;The file {$_SERVER['SCRIPT_FILENAME']} is part of Plesk 9 distribution. It cannot be run outside of Plesk 9 environment.\n&quot;);'</pre></p>
<p>Fortunately I got some help through Twitter (@ParallelsPanel) and the Parallels Forum. The fix can be found <a title="Watchdog 2011 fix" href="http://forum.parallels.com/showpost.php?p=434456&amp;postcount=42" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2011/01/your-plesk-watchdog-in-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing packages on Synology NAS through ipkg</title>
		<link>http://www.vankouteren.eu/blog/2010/09/installing-packages-on-synology-nas-through-ipkg/</link>
		<comments>http://www.vankouteren.eu/blog/2010/09/installing-packages-on-synology-nas-through-ipkg/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 10:01:00 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[ipkg]]></category>
		<category><![CDATA[nas]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[synology]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=231</guid>
		<description><![CDATA[Recently I bought a Synology DS210j NAS. This is a linux-based NAS with an ARM processor. As this basically is a full linux server, there are some interesting options for geeks familiar with the command-line. As I am a developer, I would like to be able to use version control for my projects. The NAS [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>Recently I bought a Synology DS210j NAS. This is a linux-based NAS with an ARM processor. As this basically is a full linux server, there are some interesting options for geeks familiar with the command-line.<span id="more-231"></span><br />
As I am a developer, I would like to be able to use version control for my projects. The NAS offers the possibility to install Subversion. The Synology wiki is excellent regarding instructions for installing the package manager (ipkg), Subversion. I prefer vim over vi. Vi is already installed on the NAS, but vim isn't. This can be easily installed through ipkg as well.<br />
This post will not fully describe the steps of installing all the mentioned stuff (this is well documented at the wiki), but it will describe some items to notice when installing.</p>
<ol>
<li>First enable the command-line to be available. This can be done through the administration panel (go to <em>Network Services &gt; Terminal</em>). You can choose between Telnet or SSH. (<a href="http://forum.synology.com/wiki/index.php/Overview:_What_is_CLI,_how_do_I_access_it,_SSH_or_Telnet%3F" target="_blank">Source</a>). Don't forget to enable the port (23 or 22 respectively) in the firewall so you can access the command-line.</li>
<li>Create a shared folder through the administration panel (<em>Privileges &gt; Shared Folder</em>). Call it anything you want. I called it plain 'svn'.</li>
<li>Create an SVN user through the administration panel (<em>Privileges &gt; User</em>) and give this user Read/write privileges through the Privileges setup tab. You will need this user later on.</li>
<li>Although the NAS is linux-based, it doesn't have a package manager yet. Although it isn't necessary to have this, it makes life easier for you. You can install the ipkg bootstrap. After that you can use the ipkg package manager to install packages easily. For installing the right bootstrap, you first need to know what kind of processor is present in your NAS. You can check that <a title="What kind of CPU does my NAS have" href="http://forum.synology.com/wiki/index.php/What_kind_of_CPU_does_my_NAS_have" target="_blank">here</a>. After that, you can install the ipkg bootstrap by following the instructions at the bootstrap section on <a title="installing ipkg bootstrap" href="http://forum.synology.com/wiki/index.php/Overview_on_modifying_the_Synology_Server,_bootstrap,_ipkg_etc" target="_blank">this page</a>.</li>
<li>After that, you can use the <em>ipkg install</em> command. To install vim, you can type 'ipkg install vim'. When using vim the arrow keys may not work. To fix this hit the Esc key and type :set term=builtin_ansi then hit enter.  If you don’t want to have to keep entering that command each time you start vim then you can create a configuration file called .vimrc and place it in your home folder: <em>vim /home/root/.vimrc</em> Put the following two lines in the file:<br />
<pre class="brush: cpp">:set term=builtin_ansi
:set ruler</pre><br />
The :set ruler will enable the line and column number your cursor is on when editing a text file. (<a href="http://www.jedge.com/docs/configure%20ipaq%20for%20use.pdf" target="_blank">source</a>)</li>
<li>The above steps weren't all 100% clear to me. To install Subversion, proceed to follow <a href="http://forum.synology.com/wiki/index.php/Step-by-step_guide_to_installing_Subversion#Install_Subversion_Package" target="_blank">this wiki entry</a> beginning at the 'Installing Subversion Package' section. You've performed the first couple of steps already.</li>
</ol>
<p>&nbsp;</p>
<p><strong>Upgrading PEAR to 1.9.4: out of memory</strong></p>
<p>When I was trying to upgrade PEAR from version 1.9.1 to 1.9.4 I encountered two problems.</p>
<p>Two packages could not be found. This was not 100% clear from the error message (the packages could not be initialized, error on line 0). Fortunately ipkg could install the two packages (bzip and xslt) and the problem was solved.</p>
<p>When upgrading pear ('pear upgrade pear'), the installer used too much memory resources. As pear runs on PHP itself, this problem can be solved by opening the php ini file (location: /opt/etc/php.ini) and raising the default memory_limit (in my case memory_limit = 8M) to a higher value. After that PEAR upgrades just fine.</p>
<p>&nbsp;</p>
<p><strong>Thanks</strong></p>
<p>Thumbs up for Synology for not only creating a great (and stable) product, but also for the good documentation on a lot of subjects you can come up with!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/09/installing-packages-on-synology-nas-through-ipkg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Starting a CLI script from PHP</title>
		<link>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/</link>
		<comments>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 10:05:45 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[background process]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[ignore_user_abort]]></category>
		<category><![CDATA[passthru]]></category>
		<category><![CDATA[pcntl]]></category>
		<category><![CDATA[shell_exec]]></category>
		<category><![CDATA[system]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=205</guid>
		<description><![CDATA[For quite some time I've searched for a way to start a command line script from within a page in PHP without using the crontab. Basically I just wanted to start a script which does some processing in the background. The solution is pretty simple, but it took me some time to find it.We all [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>For quite some time I've searched for a way to start a command line script from within a page in PHP without using the crontab. Basically I just wanted to start a script which does some processing in the background. The solution is pretty simple, but it took me some time to find it.<span id="more-205"></span>We all know the crontab: it can execute a script at a particular moment for you, based on what you define to be the moment. But what if you want to execute a background at the moment you would like to?</p>
<p>PHP defines four methods which can execute commands: <a title="exec" href="http://www.php.net/manual/en/function.exec.php" target="_blank">exec</a>, <a title="passthru" href="http://www.php.net/manual/en/function.passthru.php" target="_blank">passthru</a>, <a title="shell_exec" href="http://www.php.net/manual/en/function.shell-exec.php" target="_blank">shell_exec</a> and <a title="system" href="http://www.php.net/manual/en/function.system.php" target="_blank">system</a>. These methods wait for the script to finish and collect the output generated by that script. However, when a user leaves the page, closes his browser or stops the script, the background script which is executed is also stopped. To prevent this, people tend to use other options like <a title="pcntl" href="http://php.net/manual/en/book.pcntl.php" target="_blank">pcnt</a>l or <a title="cURL" href="http://www.php.net/manual/en/book.curl.php" target="_blank">cURL</a>. Using these extensions might offer a solution, but for simply starting a script they are much too verbose.</p>
<p>The solution presented is applicable in the situation where you just need to start a script and you don't want users to be able to stop the script after starting. And the solution is....</p>
<p>The function <a title="ignore_user_abort" href="http://www.php.net/manual/en/function.ignore-user-abort.php" target="_blank">ignore_user_abort()</a>.</p>
<p>By putting this function in front of a shell_exec execution, the script still starts the script executed by shell_exec. However, it doesn't care any more if the user aborts the calling script. In my situation, the CLI script updates a status file and a progress file. When running, the status file contains an integer which denotes that the CLI script is running. This prevents the script from being run again while it's already running. Furthermore, the progress file is updated so the progress can be checked by other scripts.</p>
<p><strong>Source</strong></p>
<p><strong><a href="http://stackoverflow.com/questions/265073/php-background-processes">http://stackoverflow.com/questions/265073/php-background-processes</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/06/starting-a-cli-script-from-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP multidimensional array to plain text tree structure</title>
		<link>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/</link>
		<comments>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 12:33:05 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[multidimensional array]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=197</guid>
		<description><![CDATA[Not for the first time I've searched for a way to visualize a multidimensional array in a tree view in my web browser without directly using echo or print. I wasn't able to find a concrete solution for this previously. However, this time I was put on the right track by a post of Kevin [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>Not for the first time I've searched for a way to visualize a multidimensional array in a tree view in my web browser without directly using echo or print. I wasn't able to find a concrete solution for this previously. However, this time I was put on the right track by a post of <a href="http://kevin.vanzonneveld.net/techblog/article/convert_anything_to_tree_structures_in_php/" title="Convert anything to Tree Structures in PHP">Kevin van Zonneveld</a>. <span id="more-197"></span>I've given it my own (quick and dirty as can be seen from the code) twist to get it to work. By just calling:</p>
<p><pre class="brush: php">print implode(ArrayFunctions::toString($array));</pre></p>
<p>The array is shown as a tree structure on the screen.<br />
The implementation is as follows:</p>
<p><pre class="brush: php">&lt;?php
class ArrayFunctions {
  public static function toString($array){
    $result = array();
    $depth = 0;
    foreach($array as $k =&gt; $v) {
            $show_val = ( is_array($v) ? &quot;&quot; : $v );
 
            // show the indents
            $result []= str_repeat(&quot;  &quot;, $depth);
            if($depth == 0) {
                // this is a root node. no parents
                $result []= &quot;O &quot;;
            } elseif(is_array($v)) {
                // this is a normal node. parents and children
                $result []= &quot;+ &quot;;
            } else {
                // this is a leaf node. no children
                $result []= &quot;- &quot;;
            }
 
            // show the actual node
            if ($show_val == &quot;&quot;) {
                $result []= &quot;&lt;strong&gt;{$k}&lt;/strong&gt;:
&quot;;
            }
            else {
                $result []= $k . &quot; (&quot;.$show_val.&quot;)&quot;.&quot;
&quot;;
            }
 
            if(is_array($v)) {
                // this is what makes it recursive, rerun for childs
                $temp = self::toTree($v, ($depth+1));
                foreach($temp as $t) {
                    $result []= $t;
                }
            }
        }
        return implode($result);
    }
 
    private static function showtype($show_val) {
        // convert bools to text and quote 'text bools'!
        if (is_string($show_val) &amp;&amp;
           ($show_val == &quot;true&quot; || $show_val == &quot;false&quot;)) {
            return &quot;\&quot;{$show_val}\&quot;&quot;;
        }
        elseif (is_bool($show_val) &amp;&amp; $show_val === true) {
            return &quot;true&quot;;
        }
        elseif (is_bool($show_val) &amp;&amp; $show_val === false) {
            return &quot;false&quot;;
        }
        elseif (is_null($show_val)) {
            return &quot;null&quot;;
        }
        else {
            return $show_val;
        }
    }
 
    private static function toTree($pieces, $depth = 0) {
        foreach($pieces as $k =&gt; $v) {
            // skip the baseval thingy. Not a real node.
            //if($k == &quot;__base_val&quot;) continue;
            // determine the real value of this node.
            $show_val = ( is_array($v) ? &quot;&quot; : $v );
 
            $show_val = self::showtype($show_val);
 
            // show the indents
            $result []= str_repeat(&quot;  &quot;, $depth);
            if($depth == 0) {
                // this is a root node. no parents
                $result []= &quot;O &quot;;
            } elseif(is_array($v)) {
                // this is a normal node. parents and children
                $result []= &quot;+ &quot;;
            } else {
                // this is a leaf node. no children
                $result []= &quot;- &quot;;
            }
 
            // show the actual node
            if ($show_val == &quot;&quot;) {
                $result []= &quot;&lt;strong&gt;{$k}&lt;/strong&gt;:
&quot;;
            }
            else {
                $result []= $k . &quot;: &lt;i&gt;{$show_val}&lt;/i&gt;
&quot;;
            }
 
            if(is_array($v)) {
                // this is what makes it recursive, rerun for childs
                $temp = self::toTree($v, ($depth+1));
                if (is_array($temp)) {
                    foreach($temp as $t) {
                        $result []= $t;
                    }
                }
                else {
                    $result []= $t;
                }
            }
        }
        return $result;
    }
}
?&gt;</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/04/php-multidimensional-array-to-plain-text-tree-structure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>K Means clustering and Histogram equalization source code</title>
		<link>http://www.vankouteren.eu/blog/2010/03/k-means-clustering-and-histogram-equalization-source-code/</link>
		<comments>http://www.vankouteren.eu/blog/2010/03/k-means-clustering-and-histogram-equalization-source-code/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 06:41:54 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Histogram equalization]]></category>
		<category><![CDATA[k-means]]></category>
		<category><![CDATA[K-means clustering]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=195</guid>
		<description><![CDATA[As there was some interest in source code in two earlier posts (post 1, post 2) I've posted the source code here. It's also available through the download page. Please note that the code itself is at least 4 years old and there are far better ways to solve some things. I therefore suggest that [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>As there was some interest in source code in two earlier posts (<a href="http://www.vankouteren.eu/blog/2009/09/k-means-clustering-in-java-code-found/" target="_blank">post 1</a>, <a href="http://www.vankouteren.eu/blog/2007/10/k-means-clustering-implementation-in-java/" target="_blank">post 2</a>) I've posted the source code <a href="http://www.vankouteren.eu/downloads/Ispe-dev.zip" target="_blank">here</a>.</p>
<p>It's also available through the <a href="http://www.vankouteren.eu/blog/downloads/" target="_blank">download page</a>.</p>
<p>Please note that the code itself is at least 4 years old and there are far better ways to solve some things. I therefore suggest that it is used for studying purposes only. Comments and improvments are very much appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/03/k-means-clustering-and-histogram-equalization-source-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting YUM to work on CentOS</title>
		<link>http://www.vankouteren.eu/blog/2010/02/getting-yum-to-work-on-centos/</link>
		<comments>http://www.vankouteren.eu/blog/2010/02/getting-yum-to-work-on-centos/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 13:39:33 +0000</pubDate>
		<dc:creator>Patrick van Kouteren</dc:creator>
				<category><![CDATA[Webhosting]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[install yum]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://www.vankouteren.eu/blog/?p=190</guid>
		<description><![CDATA[One of my servers is running CentOS. As I wanted to upgrade PHP, I was looking how to do that. I've found the YUM command to be useful (yum upgrade php). However, for being able to upgrade this way, one needs yum to be installed. I was 'fortunate' it wasn't so another task was born: [...]]]></description>
			<content:encoded><![CDATA[            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushPhp.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushXml.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushJava.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushSql.js"></script>
            <script type="text/javascript" src="http://www.vankouteren.eu/blog/wp-content/plugins/wordpress-code-snippet/scripts/shBrushCpp.js"></script>
<p>One of my servers is running CentOS. As I wanted to upgrade PHP, I was looking how to do that. I've found the YUM command to be useful (yum upgrade php). However, for being able to upgrade this way, one needs yum to be installed.</p>
<p>I was 'fortunate' it wasn't so another task was born: installing YUM on CentOS.<span id="more-190"></span>For installing, I've found <a href="http://wiki.openvz.org/Install_yum" target="_blank">this</a> source to be quite useful. However, I got some warnings because of dependencies. To resolve these dependencies I've upgraded the rpm packages which were denoted by the installer by hand, but the command suggested at the last post in <a href="http://forums.fedoraforum.org/archive/index.php/t-173341.html" target="_blank">this thread</a> might also work directly.</p>
<p>The names of the most recent rpm packages are listed <a href="http://mirror.centos.org/centos-5/5/os/i386/CentOS/" target="_blank">here</a>. As the rpm packages have circular dependencies one of the packages has to be installed with the --nodeps argument so these dependencies are not taken into account.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vankouteren.eu/blog/2010/02/getting-yum-to-work-on-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

