<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Joseph Ssenyange</title>
	<atom:link href="http://zenu.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenu.wordpress.com</link>
	<description>Windows, Linux, Networking, Development + Fun</description>
	<lastBuildDate>Wed, 25 Jan 2012 06:55:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='zenu.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Joseph Ssenyange</title>
		<link>http://zenu.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://zenu.wordpress.com/osd.xml" title="Joseph Ssenyange" />
	<atom:link rel='hub' href='http://zenu.wordpress.com/?pushpress=hub'/>
		<item>
		<title>AES 128bit Cross Platform (Java and C#) Encryption Compatibility</title>
		<link>http://zenu.wordpress.com/2011/09/21/aes-128bit-cross-platform-java-and-c-encryption-compatibility/</link>
		<comments>http://zenu.wordpress.com/2011/09/21/aes-128bit-cross-platform-java-and-c-encryption-compatibility/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 09:45:22 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=521</guid>
		<description><![CDATA[It seems quite a minor issue but doing cross platform encryption and decryption specifically AES was a bit a challenge for me. When you  get it working it just seems like no big change to the original code you where working on but you wasted fruitless hours debugging. Just sharing so that another person doesn&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=521&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It seems quite a minor issue but doing cross platform encryption and decryption specifically <a href="http://zenu.files.wordpress.com/2011/09/worksforme.png"><img class="size-full wp-image-529 alignright" title="worksforme" src="http://zenu.files.wordpress.com/2011/09/worksforme.png?w=600" alt=""   /></a><a title="Advanced Encryption Standard process" href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard_process" target="_blank">AES</a> was a bit a challenge for me. When you  get it working it just seems like no big change to the original code you where working on but you wasted fruitless hours debugging. Just sharing so that another person doesn&#8217;t have to waste time wondering why same settings produce a different cipher and going through a number of unhelpful posts where it &#8221; works on my machine&#8221;.</p>
<p>I initially used <strong><a title="Byte Padding" href="http://en.wikipedia.org/wiki/Padding_(cryptography)#Byte_padding" target="_blank">ISO 10126 padding</a></strong>, but that seemed to produce a different cipher in C# and Java. I decided to go with no padding which leads me to the  cryptographic exception: <em>Length</em> of the <em>data</em> to <em>decrypt is invalid. </em>After some head banging I settled with <strong><a title="Byte Padding" href="http://en.wikipedia.org/wiki/Padding_(cryptography)#Byte_padding" target="_blank">PKCS7</a>. </strong></p>
<p>Same encoding of strings has to be used in java and c#, other wise you will end up having different ciphers in java and c#.</p>
<p>The java code below uses a base64 util class from android SDK but you can replace it like with one from <a title="Apache Commons Codec Base64" href="http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java?view=markup" target="_blank">apache commons</a></p>
<p>C# encryption utility</p>
<p><pre class="brush: java;">
public RijndaelManaged GetRijndaelManaged(String secretKey)
        {
            var keyBytes = new byte[16];
            var secretKeyBytes = Encoding.UTF8.GetBytes(secretKey);
            Array.Copy(secretKeyBytes, keyBytes, Math.Min(keyBytes.Length, secretKeyBytes.Length));
            return new RijndaelManaged
            {
                Mode = CipherMode.CBC,
                Padding = PaddingMode.PKCS7,
                KeySize = 128,
                BlockSize = 128,
                Key = keyBytes,
                IV = keyBytes
            };
        }

        public byte[] Encrypt(byte[] plainBytes, RijndaelManaged rijndaelManaged)
        {
            return rijndaelManaged.CreateEncryptor()
                .TransformFinalBlock(plainBytes, 0, plainBytes.Length);
        }

        public byte[] Decrypt(byte[] encryptedData, RijndaelManaged rijndaelManaged)
        {
            return rijndaelManaged.CreateDecryptor()
                .TransformFinalBlock(encryptedData, 0, encryptedData.Length);
        }

        /// &lt;summary&gt;
        /// Encrypts plaintext using AES 128bit key and a Chain Block Cipher and returns a base64 encoded string
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;plainText&quot;&gt;Plain text to encrypt&lt;/param&gt;
        /// &lt;param name=&quot;key&quot;&gt;Secret key&lt;/param&gt;
        /// &lt;returns&gt;Base64 encoded string&lt;/returns&gt;
        public String Encrypt(String plainText, String key)
        {
            var plainBytes = Encoding.UTF8.GetBytes(plainText);
            return Convert.ToBase64String(Encrypt(plainBytes, GetRijndaelManaged(key)));
        }

        /// &lt;summary&gt;
        /// Decrypts a base64 encoded string using the given key (AES 128bit key and a Chain Block Cipher)
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;encryptedText&quot;&gt;Base64 Encoded String&lt;/param&gt;
        /// &lt;param name=&quot;key&quot;&gt;Secret Key&lt;/param&gt;
        /// &lt;returns&gt;Decrypted String&lt;/returns&gt;
        public String Decrypt(String encryptedText, String key)
        {
            var encryptedBytes = Convert.FromBase64String(encryptedText);
            return Encoding.UTF8.GetString(Decrypt(encryptedBytes, GetRijndaelManaged(key)));
        }
</pre></p>
<p>Java Encryption Utility</p>
<p><pre class="brush: java;">
private final String characterEncoding = &quot;UTF-8&quot;;
	private final String cipherTransformation = &quot;AES/CBC/PKCS5Padding&quot;;
	private final String aesEncryptionAlgorithm = &quot;AES&quot;;

	public  byte[] decrypt(byte[] cipherText, byte[] key, byte [] initialVector) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
	{
		Cipher cipher = Cipher.getInstance(cipherTransformation);
		SecretKeySpec secretKeySpecy = new SecretKeySpec(key, aesEncryptionAlgorithm);
		IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVector);
		cipher.init(Cipher.DECRYPT_MODE, secretKeySpecy, ivParameterSpec);
		cipherText = cipher.doFinal(cipherText);
		return cipherText;
	}

	public byte[] encrypt(byte[] plainText, byte[] key, byte [] initialVector) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
	{
		Cipher cipher = Cipher.getInstance(cipherTransformation);
		SecretKeySpec secretKeySpec = new SecretKeySpec(key, aesEncryptionAlgorithm);
		IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVector);
		cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
		plainText = cipher.doFinal(plainText);
		return plainText;
	}

	private byte[] getKeyBytes(String key) throws UnsupportedEncodingException{
		byte[] keyBytes= new byte[16];
		byte[] parameterKeyBytes= key.getBytes(characterEncoding);
		System.arraycopy(parameterKeyBytes, 0, keyBytes, 0, Math.min(parameterKeyBytes.length, keyBytes.length));
		return keyBytes;
	}

	/// &lt;summary&gt;
	/// Encrypts plaintext using AES 128bit key and a Chain Block Cipher and returns a base64 encoded string
	/// &lt;/summary&gt;
	/// &lt;param name=&quot;plainText&quot;&gt;Plain text to encrypt&lt;/param&gt;
	/// &lt;param name=&quot;key&quot;&gt;Secret key&lt;/param&gt;
	/// &lt;returns&gt;Base64 encoded string&lt;/returns&gt;
	public String encrypt(String plainText, String key) throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException{
		byte[] plainTextbytes = plainText.getBytes(characterEncoding);
		byte[] keyBytes = getKeyBytes(key);
		return Base64.encodeToString(encrypt(plainTextbytes,keyBytes, keyBytes), Base64.DEFAULT);
	}

	/// &lt;summary&gt;
	/// Decrypts a base64 encoded string using the given key (AES 128bit key and a Chain Block Cipher)
	/// &lt;/summary&gt;
	/// &lt;param name=&quot;encryptedText&quot;&gt;Base64 Encoded String&lt;/param&gt;
	/// &lt;param name=&quot;key&quot;&gt;Secret Key&lt;/param&gt;
	/// &lt;returns&gt;Decrypted String&lt;/returns&gt;
	public String decrypt(String encryptedText, String key) throws KeyException, GeneralSecurityException, GeneralSecurityException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, IOException{
		byte[] cipheredBytes = Base64.decode(encryptedText, Base64.DEFAULT);
		byte[] keyBytes = getKeyBytes(key);
		return new String(decrypt(cipheredBytes, keyBytes, keyBytes), characterEncoding);
	}
</pre></p>
<p>Hopefully this saves someone time.</p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://zenu.wordpress.com/tag/aes/'>AES</a>, <a href='http://zenu.wordpress.com/tag/c/'>C#</a>, <a href='http://zenu.wordpress.com/tag/java/'>Java</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/521/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/521/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/521/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=521&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/09/21/aes-128bit-cross-platform-java-and-c-encryption-compatibility/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/09/worksforme.png" medium="image">
			<media:title type="html">worksforme</media:title>
		</media:content>
	</item>
		<item>
		<title>My First Android Application</title>
		<link>http://zenu.wordpress.com/2011/09/15/my-first-android-application/</link>
		<comments>http://zenu.wordpress.com/2011/09/15/my-first-android-application/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 08:02:05 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=504</guid>
		<description><![CDATA[I was hesitant to learn android development because of time. Last week, a requirement kicked in that needed an android front-end. Target platform was android 2.2.  This is my feel of android development after six days of using android SDK. Actually I had also never used an android phone, so I was amazed how cool [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=504&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;">
<p>I was hesitant to learn android development because of time. Last week, a requirement kicked in that needed an android front-end. Target platform was android 2.2.  This is my feel of android development after six days of using android SDK. Actually I had also never used an android phone, so I was amazed how cool android OS  is.I should say mobile development should have been easier like how android development is from the beginning. I have developed in QT, and J2ME, but both dont match up to android development with ease. The great UI controls that come out of the box, the eclipse integrated plugin, the ability to reuse most of the standard java code, its all great.</p>
<p>I did consult the <a title="Android SDK" href="http://developer.android.com/sdk/index.html" target="_blank">SDK documentation</a> and the <a title="Hello views" href="http://developer.android.com/resources/tutorials/views/index.html" target="_blank">hello tutorials</a> during the development. They where of great help. The application pulls the data from a .NET WCF JSON Rest based service. I used the <a href="http://code.google.com/p/google-gson/">Google Gson</a> for the serialization and de-serialization of json to object types.  On the WCF service I decorated by operation contracts with WebGet and WebInvoke depending on whether am making GET or POST requests. To reuse the forms based authentication, the http connection service takes care of  managing the cookies mainly the forms based authentication cookie to receive and send it on requests.</p>
<p>Coding in android though seams easier than QT or j2me, I got some beating for not reading the documentation. Some of the beating I got:-</p>
<p><a href="http://zenu.files.wordpress.com/2011/09/android.png"><img class="aligncenter size-full wp-image-513" title="android" src="http://zenu.files.wordpress.com/2011/09/android.png?w=600" alt=""   /></a></p>
<ul>
<li>Embedding more than one root view in the scroll viewer was just throwing exception. I was quite big headed on googling for a solution on this one, because I just couldn&#8217;t expect it was the cause.</li>
<li>The table layout. This I had to abandon and choose another approach. I needed to replicate a telerik like silverlight gridview with a details view on each row. Was t0o ambitous about it, but abandoned it. Got headaches about the table row layout parameters and scrollview.</li>
<li>Adding an activity to the manifest file. Was always forgetting about this step and that led me to debugging. And pretty much I would remember (f***) when the exception is raised from the line where I start the Activity.</li>
<li>A point I got so frustrated with exceptions from setting content view. The exceptions just could&#8217;t make sense. I don&#8217;t know what I f.*up, but when I change layouts, or add new layouts. I tend to get exceptions when setting activity view. It just couldn&#8217;t make sense why. so I went to the bin folder and did the mighty <strong>SHIFT-DELETE-RETURN</strong>. Damn. all references to resources in R.java couldn&#8217;t be recognized any more. I was quick to think may be its a build order, so I moved gen above src folder, build project and back. Some magic happened, no more errors even when setting the content view. I still don&#8217;t know why for now. But this seems to be the solution I do for now when I get exceptions when setting content view. It seems to work. Till when I become a sniper at android, I will overlook this.</li>
</ul>
<p>Damn! Hooking my configuration service to android preferences activity has been the easiest way of managing preferences on a mobile app have seen.</p>
<p>Lastly for now. The way resources are managed in android development, I can&#8217;t find an execuse for the laziness of harding cording strings in code files. Its damn fast, easy. Android is great. Android development platform is very great. Now I just feel cheated because I was missing a lot for a long time. I must boostrap my N900 with Nitdroid.</p>
<p>Android development is the way mobile development should have been like from the beginning.</p>
</div>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://zenu.wordpress.com/tag/android/'>android</a>, <a href='http://zenu.wordpress.com/tag/java/'>Java</a>, <a href='http://zenu.wordpress.com/tag/programming/'>Programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/504/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/504/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/504/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=504&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/09/15/my-first-android-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/09/android.png" medium="image">
			<media:title type="html">android</media:title>
		</media:content>
	</item>
		<item>
		<title>Audio FingerPrinting and Matching Using Acoustid Chromaprint on Windows With Python</title>
		<link>http://zenu.wordpress.com/2011/05/28/audio-fingerprinting-and-matching-using-acoustid-chromaprint-on-windows-with-python/</link>
		<comments>http://zenu.wordpress.com/2011/05/28/audio-fingerprinting-and-matching-using-acoustid-chromaprint-on-windows-with-python/#comments</comments>
		<pubDate>Sat, 28 May 2011 08:24:10 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[audio matching]]></category>
		<category><![CDATA[chromaprint]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=488</guid>
		<description><![CDATA[I needed to generate audio fingerprints for matching/pattern recognition. I should say I tried a couple of approaches like using MFCC and spectrogram matching using Computer Vision techniques but I was not successfully with it. Using acoustid Chromaprint gave positive results. Since I was using windows, I had to compile the latest version using Visual [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=488&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;">
I needed to generate audio fingerprints for matching/pattern recognition. I should say I tried a couple of approaches like using <a href="http://en.wikipedia.org/wiki/Mel-frequency_cepstral_coefficient">MFCC</a> and spectrogram matching using Computer Vision techniques but I was not successfully with it. Using <a href="http://acoustid.org/chromaprint" title="Chromaprint">acoustid Chromaprint</a> gave positive results. Since I was using windows, I had to compile the latest version using Visual Studio.<br />
Since I my target was to get wav format to work, I didnt need ffmpeg dependency, so I removed it. You will need the <a href="http://libav.org/">avcodec</a> and <a href="http://www.fftw.org/install/windows.html">ffwt</a> libs. The algorithm used for Acoustid for finger print matching is buried in a PostgreSQL user-defined C function which I easily translated to python for use.<br />
<span id="more-488"></span><br />
In the chromaprint python module, I just need to add only one function that compares two fingerprints and returns the distance between them. In the original function, a score is returned, the only change I return 1-score, which I call the distance measure.<br />
Following is the distance measure function.
</div>
<pre style="font:inherit;">
def calculate_distance(fingerprint1, fingerprint2):
    '''  http://oxygene.sk/lukas/2011/01/how-does-chromaprint-work/
    This algorithm is extracted from the postgres chromaprint c function
    Instead of returning the score
    I return 1-score as the distance measure
    '''
    if len(numpy.shape(fingerprint1)) != 1 != len(numpy.shape(fingerprint2)):
        raise Exception('Only one dimension arrays allowed')
    if fingerprint1 == None or fingerprint2 == None:
        return 0

    numcounts = len(fingerprint1) + len(fingerprint2) + 1;
    counts = numpy.zeros(numcounts);
    for i in range(len(fingerprint1)):
        jbegin = max(0, i - ACOUSTID_MAX_ALIGN_OFFSET);
        jend = min(len(fingerprint2), i + ACOUSTID_MAX_ALIGN_OFFSET);
        for j in range(jbegin,jend):
            biterror = popcount_lookup8(fingerprint1[i] ^ fingerprint2[j]);
            # ereport(DEBUG5, (errmsg("comparing %d and %d with error %d", i, j, biterror)));
            if (biterror &lt;= ACOUSTID_MAX_BIT_ERROR):
                offset = i - j + len(fingerprint2)
                counts[offset] += 1

    return 1.0 - (numpy.max(counts) /(1.0* min(len(fingerprint1), len(fingerprint2))))
</pre>
<div style="text-align:justify;">
Depending on the what you target of using the chromaprint matching algorithm, you can adjust the  ACOUSTID_MAX_BIT_ERROR, and ACOUSTID_MAX_ALIGN_OFFSET to get  lower or high distance values that you can use as the basis later on for classification using <a href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm">K-Nearest Neighbour</a>. You can download the windows chromaprint version 0.4 <a href="http://dl.dropbox.com/u/3158042/chromaprint.rar">here</a>. The download I compiled, fingerprints only wave data since I removed ffmpeg dependencies. The download also has the dependency dlls.
</div>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a>, <a href='http://zenu.wordpress.com/category/windows/'>Windows</a> Tagged: <a href='http://zenu.wordpress.com/tag/audio-matching/'>audio matching</a>, <a href='http://zenu.wordpress.com/tag/chromaprint/'>chromaprint</a>, <a href='http://zenu.wordpress.com/tag/python/'>Python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/488/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=488&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/05/28/audio-fingerprinting-and-matching-using-acoustid-chromaprint-on-windows-with-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>Unlocking a Huawei 3G Modem, use it on multiple networks</title>
		<link>http://zenu.wordpress.com/2011/05/19/unlocking-3g-modems-and-using-them-on-other-networks/</link>
		<comments>http://zenu.wordpress.com/2011/05/19/unlocking-3g-modems-and-using-them-on-other-networks/#comments</comments>
		<pubDate>Thu, 19 May 2011 17:50:12 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mobile Tele-communication]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[3G modem]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=475</guid>
		<description><![CDATA[Being able to use a locked Huawei 3G modem on another network involves two steps. Unlock the modem using Simbwa Phillip steps. Set the APN of the SIM Network whenever initializing the modem Simbwa Phillip has some steps which I was able to follow to perfectly unlock my Huawei 3G modem. I will just paste [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=475&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Being able to use a locked Huawei 3G modem on another network involves two steps.</p>
<ol>
<li><a href="#unlock-modem">Unlock the modem using Simbwa Phillip steps.</a></li>
<li><a href="#apn">Set the APN of the SIM Network whenever initializing the modem</a></li>
</ol>
<p>Simbwa Phillip has some steps which I was able to follow to perfectly unlock my Huawei 3G modem.<br />
I will just paste here the steps again so that you don&#8217;t have to bounce back and forth.<br />
<span id="more-475"></span></p>
<h3><a name="unlock-modem">Unlock the modem using Simbwa Phillip steps</a></h3>
<div style="font:inherit;">
Two ways of unlocking your 3G modem (first&#8211; the easyway, second, the geeky way).<br />
Prerequisites:<br />
a). Python 2.6  or greater<br />
b). For the easyway (huawei modems), download and install pyhumod 0.03 from here . If you choose to go the geeky way, you don&#8217;t need the pyhumod. Also if the easy way fails, go the geeky way</p>
<p>The easy way Huawei modem:</p>
<p>Paste the following code in your preferred editor (i use vim ) and save it as whatever name you choose (i use huawei_unlocker.py)</p>
<pre style="font:inherit;font-size:80%;padding:8px 12px;">
#!/usr/bin/env python

import hashlib
import humod
UNLOCK_SALT = "5e8dd316726b0335"

def show_code(imei, salt):
    digest = hashlib.md5((imei+salt).lower()).digest()
    code = 0
    for i in range(0,4):
        code += (ord(digest[i])^ord(digest[4+i])^ord(digest[8+i])^ord(digest[12+i])) &lt;&lt; (3-i)*8
        code &amp;= 0x1ffffff
        code |= 0x2000000
    return code

mod = humod.Modem()
imei = mod.show_imei()
status = humod.at_commands.Command(mod,&#039;AT^CARDLOCK=&quot;&#039;+str(show_code(imei,UNLOCK_SALT))+&#039;&quot;\r&#039;)
#------------------- code ends here -----------------------------
</pre>
<p>After save the file and quit your editor<br />
Check that you have plugged in your modem and has been detected by system. (&#8220;dmesg | tail&#8221; could help. Check that you have ttyUSB0, ttyUSBx  where x could be 1 or 2)<br />
Execute the python script on commandline like so:</p>
<p>python huawei_unlocker.py</p>
<p>Thats it!</p>
<p>2). The geeky way</p>
<p>    Plug in your modem<br />
    Check that its has been read by the system<br />
    Then at your terminal type:</p>
<p># cat /dev/ttyUSB0 &amp;</p>
<p>    We then extract the IMEI serial of the modem like so:</p>
<p># echo -e &#8220;ATI\r&#8221; &gt; /dev/ttyUSB0</p>
<p>    Make note of the IMEI serial<br />
    In your favorite editor paste the following code and save it as unlock.py</p>
<pre style="font:inherit;font-size:80%;padding:8px 12px;">
 #!/usr/bin/env python

import hashlib
UNLOCK_SALT = "5e8dd316726b0335"

def show_codes(imei, salt):
    digest = hashlib.md5((imei+salt).lower()).digest()
    code = 0
    for i in range(0,4):
        code += (ord(digest[i])^ord(digest[4+i])^ord(digest[8+i])^ord(digest[12+i])) &lt;&lt; (3-i)*8
        code &amp;= 0x1ffffff
        code |= 0x2000000
    return code

# PLEASE TYPE YOUR IMEI  BELOW
imei = &#039; &#039;
if(imei == &#039; &#039;):
    print &#039;Please open this script from your editor and enter your IMEI&#039;
else:
    print &quot;Your Modem unlock code: %s&quot; % show_codes(imei,UNLOCK_SALT);
</pre>
<p>    Execute the above script to generate your modem unlock code<br />
    Now its time to unlock the modem and we do it like so:<br />
<code><br />
# echo -e 'AT^CARDLOCK="XXXXXXXX"\r' &gt; /dev/ttyUSB0<br />
</code><br />
(Please use your generated modem unlock code in place of XXXXXXXX)</p>
<p>    You should see the modem reply with an OK<br />
    Press CTRL + C
</p></div>
<p></br></p>
<h3><a name="apn">Set the APN of the SIM Network whenever initializing the modem</a></h3>
<p>For linux if your using wvdial change the wvdial.conf or add the line below which sets the APN name</p>
<pre style="font:inherit;">
Init3 = AT+CGDCONT=1,"IP","TelecomNetworkAPNName"
</pre>
<p>For windows users, go to the device manager -&gt; Modems -&gt; Open properties of the modem -&gt; Under Advanced -&gt; in the extra initialization commands field put the entry</p>
<pre style="font:inherit;">
AT+CGDCONT=1,"IP","TelecomNetworkAPNName"
</pre>
<p>The TelecomNetworkAPNName varies from Telecom, for UTL it is <strong>utweb</strong> and for Orange it is <strong>orange.ug</strong>.<br />
So now you can create a connection with a dial number <strong>*99#</strong> or <strong>*99***1#</strong>.</p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/linux/'>Linux</a>, <a href='http://zenu.wordpress.com/category/mobile-tele-communication/'>Mobile Tele-communication</a>, <a href='http://zenu.wordpress.com/category/windows/'>Windows</a> Tagged: <a href='http://zenu.wordpress.com/tag/3g-modem/'>3G modem</a>, <a href='http://zenu.wordpress.com/tag/python/'>Python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/475/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/475/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=475&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/05/19/unlocking-3g-modems-and-using-them-on-other-networks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>Least Squares Regression on Uganda&#8217;s Consumer Price Index Items Influencing Inflation Rate Part I</title>
		<link>http://zenu.wordpress.com/2011/05/01/least-squares-regression-on-ugandas-consumer-price-index-items-influencing-inflation-rate-part-1/</link>
		<comments>http://zenu.wordpress.com/2011/05/01/least-squares-regression-on-ugandas-consumer-price-index-items-influencing-inflation-rate-part-1/#comments</comments>
		<pubDate>Sun, 01 May 2011 00:23:39 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Uganda]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=447</guid>
		<description><![CDATA[Views expressed hear are mine and if their mistakes please feel free to correct me. About four to five years back I was buying Petrol at around 2200, right now its 3500 Shillings. I am quite disgusted with whats going on in the country. The prices of basics are very high, the way the Government [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=447&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;">
Views expressed hear are mine and if their mistakes please feel free to correct me. About four to five years back I was buying Petrol at around 2200, right now its 3500 Shillings. I am quite disgusted with whats going on in the country. The prices of basics are very high, the way the Government is handling the walk to work demonstrators is totally inhumane. The inflation rate as of now is predicated to hit 14%. All this is happening when at the back of my mind I know that Government wasted a lot of tax payers money on recent presidential campaigns to finance their campaigns and bribery. I have rage that continues to build as I see corrupt officers (Freedom fighters <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) set free and time is wasted on legislations that will not build this country but fulfill personal ambitions.<span id="more-447"></span> Okay enough of my rage.</p>
<p> Am blogging about this because when you look at the graph of CPI items, it seems they are just increasing not going down. I look/analyze the inflation rate in Uganda using <a href="http://en.wikipedia.org/wiki/Consumer_price_index" title="CPI" target="_blank">Composite Consumer Price Index</a> (CPI) values from the <a href="http://www.bou.or.ug/bouwebsite/export/sites/default/bou/bou-downloads/research/Inflation/Composite_Consumer_Price_Index.xls" title="Bank of Uganda CPI" target="_blank">Bank of Uganda Website</a>. From wiki  <a href="http://en.wikipedia.org/wiki/Inflation_rate" title="Inflation rate" target="_blank">inflation rate</a> is a measure of inflation, the rate of increase of a price index (for example, a consumer price index). If we can predict CPI values that are used to calculate inflation rate, that means we are able to predict the inflation rate.</p>
<p>The major factors (CPI items) that decide the Uganda inflation rate as stated in the excel sheet are:-
</p></div>
<ul>
<li>Food</li>
<li>Beverages and tobacco</li>
<li>Clothing and footwear</li>
<li>Rent, Fuel and utilities</li>
<li>House hold and personal goods</li>
<li>Transport and communication.</li>
<li>Education</li>
<li>Health ,entertainment &amp; Others</li>
</ul>
<p>If we are able to build a linear function that can predict each of the items above based on their historical values, then we can predict the inflation rate of Uganda with an acceptable <a href="http://en.wikipedia.org/wiki/Mean_squared_error" title="Root Mean Squared Error" target="_blank">Root mean square error</a>. For each of the CPI items above, Least squares regression will be used to find five weights that we apply to recent historical values to estimate/predicate next month CPI of the item and the Root mean square error (RMSE) from predictions.</p>
<p><strong><br />
THE RED LINE SHOWS THE ORIGINAL VALUES, THE BLUE LINE SHOWS THE PREDICTED VALUE<br />
</strong></p>
<div>
<h3>Food</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/food.png?w=1600" alt="Food" width="100%" /><br />
<blockquote>
Weights w5=0.022637182175 w4=0.100118564555 w3=-0.512433115279 w2=1.4003471128 w1=-0.887631618337 RMSE 2.58435645556
</p></blockquote>
</div>
<div>
<h3>Beverages and tobacco</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/beveragesandtobacco.png?w=1600" alt="Beverages and tobacco" width="100%" /><br />
<blockquote>
Weights w5=-0.0298913144449 w4=0.0725116912485 w3=0.0976276103987 w2=0.868294319031 w1=-0.305850948846 RMSE 1.5260998916
</p></blockquote>
</div>
<div>
<h3>Clothing and footwear</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/clothingandfootwear.png?w=1600" alt="Clothing and footwear" width="100%" /><br />
<blockquote>
Weights w5=0.0239711496303 w4=-0.024598729962 w3=-0.151485582327 w2=1.1642440814 w1=-0.945136789909 RMSE 1.06661287832
</p></blockquote>
</div>
<div>
<h3>Rent, Fuel and utilities</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/rentfuelutilities.png?w=1600" alt="Rent, Fuel and utilities" width="100%" /><br />
<blockquote>
Weights w5=0.156511226268 w4=0.0550308851393 w3=-0.203995309207 w2=1.00390775576 w1=-0.409702600111 RMSE 1.46182056121
</p></blockquote>
</div>
<div>
<h3>H.hold and personal goods</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/householdandpersonalgoods.png?w=1600" alt="" width="100%" /><br />
<blockquote>
Weights w5=-0.0963582348489 w4=0.114897496498 w3=-0.284761046831 w2=1.2779029176 w1=-0.840274448644 RMSE 0.896403337867
</p></blockquote>
</div>
<div>
<h3>Transport and communication.</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/transportandcommunication.png?w=1600" alt="Transport and communication." width="100%" /><br />
<blockquote>
Weights w5=-0.0706169477501 w4=0.178402858572 w3=-0.0634676065735 w2=0.947318628322 w1=1.09095269902 RMSE 2.09112314015
</p></blockquote>
</div>
<div>
<h3>Education</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/education.png?w=1600" alt="Education" width="100%" /><br />
<blockquote>
Weights w5=0.138779134167 w4=0.0193111903052 w3=-0.00781772033164 w2=0.85619997931 w1=-0.00122761969614 RMSE 1.02538674821
</p></blockquote>
</div>
<div>
<h3>Health ,entert. &amp; Others</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/healthentertainmentothers.png?w=1600" alt="Health ,entert. &amp; Others" width="100%" /><br />
<blockquote>
Weights w5=0.169849157617 w4=-0.135560311837 w3=-0.0875331304828 w2=1.07711171275 w1=-1.90130658745 RMSE 1.0335827302
</p></blockquote>
</div>
<div>
<h3>All items index</h3>
<p><img src="http://zenu.files.wordpress.com/2011/04/all-items-index.png?w=1600" alt="All items index" width="100%" /><br />
<blockquote>
Weights w5=0.0327337947705 w4=0.0300853160046 w3=-0.367693694924 w2=1.31370438163 w1=-0.465757986242 RMSE 0.932900847743
</p></blockquote>
</div>
<p>To be able to predict the next CPI value for an Item, we take four previous values from current date and apply weights for them. e.g if we want to predict the Food CPI for march we take values Feb 2011 to Nov 2010. </p>
<pre style="font:inherit;font-weight:bold;">
2010	Nov	173.44
	Dec	173.69

2011	Jan	179.53
	Feb	183.04
</pre>
<p>The predicated Food CPI for march based on weights w5=0.022637182175 w4=0.100118564555 w3=-0.512433115279 w2=1.4003471128 w1=-0.887631618337 would be:-</p>
<p style="font-weight:bold;">
183.04 * w5 + 179.53 * w4 + 173.69 * w3 + 173.44 * w2 + w1 = 175.10
</p>
<p>After calculating the predicted CPI for every Item, them we can apply the inflation rate.<br />
Predicting values may not give the right answer since we are only looking at values of CPI, to further bring it closer to the present value, surrounding factors e.g. currency rate have to be considered.</p>
<p>To be Continued&#8230;<br />
END OF PART 1</p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/uganda/'>Uganda</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/447/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=447&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/05/01/least-squares-regression-on-ugandas-consumer-price-index-items-influencing-inflation-rate-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/food.png?w=1600" medium="image">
			<media:title type="html">Food</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/beveragesandtobacco.png?w=1600" medium="image">
			<media:title type="html">Beverages and tobacco</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/clothingandfootwear.png?w=1600" medium="image">
			<media:title type="html">Clothing and footwear</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/rentfuelutilities.png?w=1600" medium="image">
			<media:title type="html">Rent, Fuel and utilities</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/householdandpersonalgoods.png?w=1600" medium="image" />

		<media:content url="http://zenu.files.wordpress.com/2011/04/transportandcommunication.png?w=1600" medium="image">
			<media:title type="html">Transport and communication.</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/education.png?w=1600" medium="image">
			<media:title type="html">Education</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/healthentertainmentothers.png?w=1600" medium="image">
			<media:title type="html">Health ,entert. &#38; Others</media:title>
		</media:content>

		<media:content url="http://zenu.files.wordpress.com/2011/04/all-items-index.png?w=1600" medium="image">
			<media:title type="html">All items index</media:title>
		</media:content>
	</item>
		<item>
		<title>Illustration of solving sudoku puzzle using Brute Force, Generate and Test, and Arc consistency</title>
		<link>http://zenu.wordpress.com/2011/04/19/illustration-of-solving-sudoku-using-arc-consistency/</link>
		<comments>http://zenu.wordpress.com/2011/04/19/illustration-of-solving-sudoku-using-arc-consistency/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 19:14:23 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Arc Consistency]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Sudoku]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=344</guid>
		<description><![CDATA[There are different ways of solving Sudoku puzzles. Brute force, Generate and Test both perform pretty well for easy puzzles but Arc Consistency beats them all in speed and solving very complex puzzles with less CPU.  Peter Norvig has a robust solution that solve any puzzle . Brute force, Generate and Test are easy to implement. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=344&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;">There are different ways of solving Sudoku puzzles. Brute force, Generate and Test both perform pretty well for easy puzzles but Arc Consistency beats them all in speed and solving very complex puzzles with less CPU.  <a title="Peter Norvig" href="http://norvig.com/" target="_blank">Peter Norvig</a> has a robust solution that solve any <a title="Soduke Puzzle Solver" href="http://norvig.com/sudoku.html" target="_blank">puzzle</a> .</p>
<p>Brute force, Generate and Test are easy to implement. but what about using <a title="Arc Consistency" href="http://en.wikipedia.org/wiki/Local_consistency#Arc_consistency" target="_blank">Arc Consistency</a>. For adventure I attempted to try out using arc consistency to solve sudoku puzzles. I did manage to implement the concept though my implementation is not as fast as Norvig&#8217;s.<span id="more-344"></span></p>
<p>To ease the implementation, I modeled the sudoku as follows:-</p>
<ul>
<li>A Cell knows about  the row, column, block, general sudoku reference and its domain.</li>
<li>Both Column, Block and Row  know about the sudoku reference and the cells that are in it</li>
<li>Sudoku class itself knows its blocks, rows, columns and cells.</li>
<li>I also keep a list of constraints cell-to-row, cell-to-block and cell-to-column</li>
</ul>
<p>With the arrangement above I perform arc consistency on the constraints.
</p></div>
<pre>
import copy
import time

class Cell(object):
    row=None
    column=None
    block=None
    domain=None
    value=None
    sudoku=None
    def __init__(self,sudoku, value):
        self.sudoku=sudoku
        self.value=value
        self.domain=[]
    def __hash__(self):
        return int(str(self.row.index)+str(self.column.index))

    def __eq__(self,other):
        try:
            return self.row.index == other.row.index and self.column.index == other.column.index
        except:
            return False
    def __str__(self):
        return "Cell " + str(self.row.index) + str(self.column.index)

class Row(object):
    sudoku=None
    index=None
    cells=None
    def __init__(self,sudoku, index):
        self.sudoku=sudoku
        self.index=index
        self.cells=[]
    def addCell(self, cell):
        self.cells.append(cell)
        cell.row=self
    def __hash__(self):
        return int("9"+str(self.index))
    def __eq__(self, other):
        return isinstance(other, Row) and self.index == other.index
    def __str__(self):
        return "Row " + str(self.index)

class Column(object):
    sudoku=None
    index=None
    cells=None
    def __init__(self, sudoku,index):
        self.sudoku=sudoku
        self.index=index
        self.cells=[]
    def addCell(self,cell):
        self.cells.append(cell)
        cell.column=self
    def __hash__(self):
        return int("10"+str(self.index))
    def __eq__(self, other):
        return isinstance(other, Column) and self.index == other.index
    def __str__(self):
        return "Column " + str(self.index)

class Block(object):
    sudoku=None
    index=None
    cells=None
    def __init__(self,sudoku, index):
        self.sudoku=None
        self.index=index
        self.cells=[]
    def addCell(self, cell):
        self.cells.append(cell)
        cell.block=self
    def __hash__(self):
        return int("11"+str(self.index))
    def __eq__(self, other):
        return isinstance(other, Block) and self.index == other.index
    def __str__(self):
        return "Block " + str(self.index)

class Sudoku(object):
    columns=None
    rows=None
    blocks=None
    cells=None
    TDA = None
    __width=9

    def getBlockIndex(self, rowIndex, columnIndex):
        if rowIndex &lt;= 2:
            if columnIndex &lt;= 2:
                return 0
            elif columnIndex &lt;= 5:
                return 1
            elif columnIndex &lt;= 8:
                return 2
        elif rowIndex &lt;= 5:
            if columnIndex &lt;= 2:
                return 3
            elif columnIndex &lt;= 5:
                return 4
            elif columnIndex &lt;= 8:
                return 5
        elif rowIndex &lt;= 8:
            if columnIndex &lt;= 2:
                return 6
            elif columnIndex &lt;= 5:
                return 7
            elif columnIndex &lt;= 8:
                return 8
        return None

    def __init__(self, puzzle):
        self.TDA=dict()
        self.cells=[]
        self.blocks=[ Block(self,n) for n in range(self.__width)]
        self.columns=[ Column(self,n) for n in range(self.__width)]
        self.rows = [ Row(self,n) for n in range(self.__width)]

        for row in range(self.__width):
            for column in range(self.__width):
                cell = Cell(self,puzzle[row][column])
                self.cells.append(cell)
                self.columns[column].addCell(cell)
                self.rows[row].addCell(cell)
                self.blocks[self.getBlockIndex(row,column)].addCell(cell)

                if cell.value:
                    cell.domain.append(cell.value)
                else:
                    cell.domain.extend(range(1, self.__width+1))
                    self.TDA[(cell, cell.row)]=1
                    self.TDA[(cell, cell.column)]=1
                    self.TDA[(cell, cell.block)]=1

    def ArcConsistency(self):
        while (1 in self.TDA.values()):
            for cell, constraint in self.TDA:
                if self.TDA[(cell, constraint)] == 0: continue
                cellDomainModified=False
                for constraintCell in constraint.cells:
                    if cell != constraintCell and constraintCell.value != None and constraintCell.value in cell.domain:
                        cell.domain.remove(constraintCell.value)
                        cellDomainModified=True
                self.TDA[(cell, constraint)]=0
                if cellDomainModified:
                    for primeConstraint in [cell.row, cell.column, cell.block]:
                        if primeConstraint != constraint:
                            for primeConstraintCell in primeConstraint.cells:
                                if  primeConstraintCell.value==None:
                                    self.TDA[(primeConstraintCell, primeConstraint)]=1
        cellConstraintsToRemove=[]
        for cell, constraint in self.TDA:
            if len(cell.domain)==1:
                cell.value = cell.domain[0]
                cellConstraintsToRemove.append((cell, constraint))
        for cellConstraintToRemove in cellConstraintsToRemove:
            del self.TDA[cellConstraintToRemove]

    def solve(self):
	start=time.clock()
        self.ArcConsistency()
	if self.isSolved():
	    return self, time.clock()-start
	sol=self.search()
	return sol, time.clock()-start

    def isInconsistent(self):
	invalid=False
	for cell in self.cells:
	    if cell.value==None and len(cell.domain) == 0:
		invalid=True
		break
	if not invalid:
	    for row  in self.rows:
		if not self.areCellsValid(row.cells):
		    invalid=True
		    break
	if not invalid:
	    for block  in self.blocks:
		if not self.areCellsValid(block.cells):
		    invalid=True
		    break
	if not invalid:
	    for column  in self.columns:
		if not self.areCellsValid(column.cells):
		    invalid=True
		    break

	return invalid

    def areCellsValid(self, cells):
	noneNullCells = [cell for cell in cells if cell.value != None]
	return len(noneNullCells) == len(set(cell.value for cell in noneNullCells))

    def search(self):
	try:
	    if threading.currentThread().stopFlag:
		return None
	except:
	    pass

	sudokuCopy = copy.deepcopy(self)
	count, cell = min((len(cell.domain), cell) for cell in sudokuCopy.cells if cell.value == None)
	if( cell == None): return
	cellIndex = sudokuCopy.cells.index(cell)
	for value in copy.deepcopy(cell.domain):
	    sudokuTemp = copy.deepcopy(sudokuCopy)
	    sudokuTemp.cells[cellIndex].value=value
	    sudokuTemp.cells[cellIndex].domain=[]
	    sudokuTemp.cells[cellIndex].domain.append(value)
	    del sudokuTemp.TDA[(sudokuTemp.cells[cellIndex], sudokuTemp.cells[cellIndex].row)]
	    del sudokuTemp.TDA[(sudokuTemp.cells[cellIndex], sudokuTemp.cells[cellIndex].column)]
	    del sudokuTemp.TDA[(sudokuTemp.cells[cellIndex], sudokuTemp.cells[cellIndex].block)]
	    for tdaDictKey in sudokuTemp.TDA:
		sudokuTemp.TDA[tdaDictKey]=1
	    sudokuTemp.ArcConsistency()
	    if sudokuTemp.isInconsistent():
		continue
	    elif sudokuTemp.isSolved():
		return sudokuTemp
	    else:
		solution=sudokuTemp.search()
		if solution and solution.isSolved():
		    return solution
	return None

    def isSolved(self):
        value=True
        for cell in self.cells:
            if cell.value == None:
                value=False
                break
        return value

    def toPuzzle(self):
        return [ [ cell.value for cell in row.cells ] for row in self.rows ]

if __name__ == &quot;__main__&quot;:

    def printSudoku(sudokuPuzzle):
	for row in sudokuPuzzle.toPuzzle():
	    print str(row)

    puzzle=[[None,None,None,None,None,None,None,None,1],
            [None,None,None,None,None,None,None,None,None],
            [None,None,None,None,None,None,None,None,None],
            [None,None,None,None,None,None,None,None,None],
            [None,None,None,None,1,None,None,None,None],
            [None,None,None,None,None,None,None,None,None],
            [None,None,None,None,None,None,None,None,None],
            [None,None,None,None,None,None,None,None,None],
            [1,None,None,None,None,None,None,None,None]]

    sudoku = Sudoku(puzzle)
    solvedSudoku, elapsed=sudoku.solve()

    index=0
    for row in solvedSudoku.toPuzzle():
	print str(row) + &quot;\t\t\t&quot; + str(puzzle[index])
	index=index+1
    print &quot;Took &quot; + str(elapsed)
</pre>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://zenu.wordpress.com/tag/arc-consistency/'>Arc Consistency</a>, <a href='http://zenu.wordpress.com/tag/python/'>Python</a>, <a href='http://zenu.wordpress.com/tag/sudoku/'>Sudoku</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/344/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/344/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/344/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=344&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/04/19/illustration-of-solving-sudoku-using-arc-consistency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>UTL Uganda Telecom KwikTok Makes Internet More affordable</title>
		<link>http://zenu.wordpress.com/2011/04/19/utl-uganda-telecom-kwik-tok/</link>
		<comments>http://zenu.wordpress.com/2011/04/19/utl-uganda-telecom-kwik-tok/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 18:39:44 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Mobile Tele-communication]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[3G]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[UTL]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=436</guid>
		<description><![CDATA[UTL has an amazing product called KwikTok where you key in a ussd *250# and you get 100mb data, 20 free SMS and 10 minutes of talk. I have been a disgruntled UTL customer since 2003 but nothing has never made me proud of being a UTL customer like KwikTok. So why am I happy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=436&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:justify;">
<a href="http://utl.co.ug/">UTL</a> has an amazing product called <strong>KwikTok</strong> where you key in a ussd *250# and you get 100mb data, 20 free SMS and 10 minutes of talk. I have been a disgruntled UTL customer since 2003 but nothing has never made me proud of being a UTL customer like KwikTok.</p>
<p>So why am I happy about KwikTok? Well the 100MB of data isn&#8217;t a joke. 100MB!!!! for only 250 shillings. If you calculate that for 31 days, that is if you spend 100MB per day that totals to 7750 Shillings. That means you buying 3.1GB for just 7,750 Shillings. Hmmmm Yeaaaaaa. Now that&#8217;s sweet. 100MB is enough for you to stay online the whole day and make a couple of skype audio calls. If your to compare it with the major player <a href="http://orange.ug/mobile-plans/internet-everywhere.php">Orange</a> that am subscribed to for 3G internet 3GB would cost you 85,000 Shillings.</p>
<p>You should be just too crazy to underlook the UTL free internet. This means if your like me and have an old product like Orange 3G internet. You move UTL to higher priority and use Orange Internet when UTL connection is off or extremely slow. That makes you reserve your orange data when you extremely need blazing speed. Not that the UTL internet connection is slow. You can do pretty alot with the UTL connection. Pages load pretty fast and if your crazy like me who is running a proxy on all my machines and my N900 phone then that means better performance. Skype calls using my phone-n900 and laptop are both clear.</p>
<p>Every good thing has some annoying bit. KwikTok data doesn&#8217;t go without a negative spot. One thing that pisses me off is when your connected through the phone or your working from the phone and the 100MB is exceeded you don&#8217;t get any warning and it automatically switches to using the normal profile of your airtime which is maddly expensive. Coz my phone squashes 4000 in just less than 10minutes when active. You should be aware of this.</p></div>
<br />Filed under: <a href='http://zenu.wordpress.com/category/mobile-tele-communication/'>Mobile Tele-communication</a>, <a href='http://zenu.wordpress.com/category/networking/'>Networking</a> Tagged: <a href='http://zenu.wordpress.com/tag/3g/'>3G</a>, <a href='http://zenu.wordpress.com/tag/internet/'>Internet</a>, <a href='http://zenu.wordpress.com/tag/utl/'>UTL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=436&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/04/19/utl-uganda-telecom-kwik-tok/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>Using MongoDB as the Audit and Log data store with a custom tracelistener</title>
		<link>http://zenu.wordpress.com/2011/03/29/using-mongodb-as-the-audit-and-log-data-store-with-custom-tracelistener/</link>
		<comments>http://zenu.wordpress.com/2011/03/29/using-mongodb-as-the-audit-and-log-data-store-with-custom-tracelistener/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 21:35:56 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=416</guid>
		<description><![CDATA[This post illustrates how one would save changes to ADO entities and other logging via the enterprise library logging application block to MongoDB. MongoDB is an open source agile document oriented nosql database that supports sharding, map-reduce, indexing on attributes, GridFS etc. MongoDB is fast to setup and fast to scale. The choice to move [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=416&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post illustrates how one would save changes to ADO entities and other logging via the enterprise library logging application block to <a href="http://www.mongodb.org">MongoDB</a>. MongoDB is an open source agile document oriented nosql database that supports sharding, map-reduce, indexing on attributes, GridFS etc. <a href="http://www.mongodb.org">MongoDB</a> is fast to setup and fast to scale. The choice to move logging to MongoDB was to make use of running map reduce jobs on the dataset.</p>
<p>To be able to connect to MongoDB process you will have to download the latest <a href="http://www.mongodb.org/display/DOCS/CSharp+Community+Projects">C# Driver</a></p>
<p>To be able to log via the Enterprise Logging Application Block I created a custom trace listener and trace listener configuration. The trace listener configuration was to allow specifying MongoDB connection string and database name. The custom trace listener opens the connection to the MongoDB process and inserts the updates. Every attempted change to the entity is stored.<span id="more-416"></span></p>
<p>Changes to entity are logged at the point the data context is saving changes by subscribing to the SavingChanges event.</p>
<blockquote><p>
<code><br />
        void OnSavingChanges(object sender, EventArgs e)<br />
        {<br />
              ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Deleted | EntityState.Modified)<br />
                .Where(entity =&gt; !entity.IsRelationship &amp;&amp; entity.Entity is IEntity)<br />
                .Select(entity =&gt; new AuditEntry((IEntity)entity.Entity, UserService.GetCurrentUser().Name, entity.State))<br />
                .Log();<br />
        }<br />
</code></p></blockquote>
<p>The Entriprise lib LogEntry object is sent directly to the database unless it has AuditEntities. AuditEntities are saved in the AuditEntry collection whereas the rest of the log entries are stored in the LogEntry collection. The entity is saved as an attribute of AuditEntry called Entity.</p>
<blockquote><p>
<code><br />
    public interface IAuditEntry: IEntity where TEntity : IEntity<br />
    {<br />
        TEntity Entity { get; set; }<br />
        string EntityModifiedBy { get; set; }<br />
        EntityState @EntityState { get; set; }<br />
    }<br />
</code></p></blockquote>
<p>The Extension file has the code that checks the LogEntry object if it has AuditEntities in the ExtendedProperties and method for logging using the enterprise lib Logger. In the <a href="http://dl.dropbox.com/u/3158042/com.kutokea.rar">attached file</a> I mocked (Moq) the user IIdentity object, but depending on your application context you know how to get the current user IIdentity. You can download a zip having all the files <a href="http://dl.dropbox.com/u/3158042/com.kutokea.rar">here</a>.</p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://zenu.wordpress.com/tag/c/'>C#</a>, <a href='http://zenu.wordpress.com/tag/mongodb/'>MongoDB</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/416/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=416&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/03/29/using-mongodb-as-the-audit-and-log-data-store-with-custom-tracelistener/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>2011 Searchable Uganda Voters List</title>
		<link>http://zenu.wordpress.com/2011/02/19/2011-searchable-uganda-voters-list/</link>
		<comments>http://zenu.wordpress.com/2011/02/19/2011-searchable-uganda-voters-list/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 18:17:37 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uganda]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[mapreduce]]></category>
		<category><![CDATA[Voter List]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=404</guid>
		<description><![CDATA[I had scrapped a voters list a few months back. I realized its out of date. The new voters list available at the Electoral Commission website has voter id&#8217;s but it doesn&#8217;t offer search. I had to harvest a fresh list. You can search the voter&#8217;s list at http://reg.kutokea.com for the following information:- Voters Id [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=404&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had <a href="http://zenu.wordpress.com/2010/11/24/google-appengine-tale-using-python/">scrapped</a> a voters list a few months back. I realized its out of date. The new voters list available at the <a href="http://41.210.167.106/ec/nvr/">Electoral Commission website</a> has voter id&#8217;s but it doesn&#8217;t offer search.  I had to harvest a fresh list. You can search the voter&#8217;s list at <a href="http://reg.kutokea.com">http://reg.kutokea.com</a> for the following information:-<span id="more-404"></span></p>
<ul>
<li>Voters Id</li>
<li>Surname</li>
<li>Other names</li>
<li>Village</li>
<li>Polling station</li>
<li>Sub-Country</li>
<li>Parish</li>
<li>Constituency</li>
<li>District</li>
<li>or a combination of the above listed.</li>
</ul>
<p>The search results reflect accurate information from the EC website <a href="http://www.ec.or.ug/">http://www.ec.or.ug/</a> as of Febuary 19th, 2011.</p>
<p>If you want further analysis of the voters list:-</p>
<p>You can <a href="http://zenu.wordpress.com/about/">request</a> analysis reports which I can generate for you. Depending on the complex level of the report and resources that will be required. I may take a day or two to get back to you with that report.</p>
<p>For advanced users like developers I allow you to write readonly App Engine <a href="http://code.google.com/p/appengine-mapreduce/">mapreduce jobs</a> that I can run on the data set. All code is first analyzed before job submitted. If interested you can contact me for the model design and further information.</p>
<p>NB. By the time of writing this article <a href="http://code.google.com/p/appengine-mapreduce/">App Engine mapreduce</a> doesn&#8217;t have the same feature set as <a href="http://hadoop.apache.org/">Hadoop</a> e.g no Reduce, but it provides a feature set thats pretty enough to run simple MapReduce jobs. By the way if you have cron jobs that fit being run as mapreduce jobs, I would advice you to convert to using the appengine mapreduce api because its faster and cheaper with resource quotas and time. Am not sure if it may apply to your situation, but it does to mine. I scrapped the voters list using 8 shards for more than twenty five thousand polling stations, downloading pdfs, decrypting them and inserting voter data (&gt; 500) into the datastore. Took two days, yet the first time using cron jobs, it took almost a month.</p>
<p>Url:  <a href="http://reg.kutokea.com">http://reg.kutokea.com</a><br />
Currently the search indexes are rebuilding for more than ten million voters and will be done by the morning of 20th Febuary 2011.</p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a>, <a href='http://zenu.wordpress.com/category/uganda/'>Uganda</a> Tagged: <a href='http://zenu.wordpress.com/tag/app-engine/'>app engine</a>, <a href='http://zenu.wordpress.com/tag/mapreduce/'>mapreduce</a>, <a href='http://zenu.wordpress.com/tag/programming/'>Programming</a>, <a href='http://zenu.wordpress.com/tag/uganda/'>Uganda</a>, <a href='http://zenu.wordpress.com/tag/voter-list/'>Voter List</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=404&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/02/19/2011-searchable-uganda-voters-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
		<item>
		<title>AspectF in Java</title>
		<link>http://zenu.wordpress.com/2011/01/05/aspectf-in-java/</link>
		<comments>http://zenu.wordpress.com/2011/01/05/aspectf-in-java/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 17:56:45 +0000</pubDate>
		<dc:creator>Joseph Ssenyange</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AspectF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mockito]]></category>

		<guid isPermaLink="false">http://zenu.wordpress.com/?p=392</guid>
		<description><![CDATA[AspectF is a Fluent Aspect Framework written in C# by Omar AL Zabir. It helps reduce on the plumbing code. For more information about AspectF framework, you can read an article by Omar AL Zabir on code project. There are different aspect frameworks you can choose from, for C# there is postsharp, Castle.DynamicProxy, LinfuDynamicProxy, Sprint.Net [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=392&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/aspectf/">AspectF</a> is a Fluent Aspect Framework written in C# by  <a href="http://omaralzabir.com/">Omar AL Zabir</a>. It helps reduce on the plumbing code. For more information about AspectF framework, you can read an article by Omar AL Zabir on <a href="http://www.codeproject.com/KB/tips/aspectf.aspx">code project</a>. There are different aspect frameworks you can choose from, for C# there is postsharp, Castle.DynamicProxy, LinfuDynamicProxy, Sprint.Net etc and for java there is Spring, AspectJ etc. My experience in .Net is with Postsharp and AspectF. When it comes to java, I have played around with Spring AOP but I haven&#8217;t found it easy as with AspectF in .Net. I took the decision to convert AspectF by Omar AL Zabir  in C# to Java.<span id="more-392"></span><br />
<br />
AspectF is easy to adopt, easy to extend and rocks!, thanks to Omar AL Zabir. With that I went on the adventure of converting AspectF C# code to Java. Main C# features used in AspectF C# that needed to be converted to Java included:-</p>
<ul>
<li>Delegates: I had to create abstract classes Action, Func, IDelegate to account for the corresponding delegates in .Net</li>
<li>RunAsync: In C# it uses the BeginInvoke and EndInvoke for Java I have used the ExecutorService with a thread pool of 20.</li>
<li>TimeSpan: I created a simple TimeSpan class to be used in the timing calls.</li>
<li>C# Extensions: Since java doesn&#8217;t have extensions, I decided to merge the calls in AspectExtensions to the same class as AspectF</li>
</ul>
<p>Methods I skipped converting include <i>MustBeNonDefault</i> and <i>CacheList</i></p>
<p>I did use the same tests in AspectFTest class to make sure the conversion was atleast in a working condition.<br />
For mocking I used the <a href="http://code.google.com/p/mockito/">mockito</a> which is as simple as <a href="http://code.google.com/p/moq/">Moq</a>. The tests confirm to JUnit with some rough edge changes from <a href="http://xunit.codeplex.com/">xUnit.net</a>.<br />
<br />
The conversion wasn&#8217;t smooth since I had to hack my way around the Action and Func C# delegates.<br />
As of now there is a hacked Alpha version which needs further improvement. Am currently using it in my small projects and will improve it further as need arises.<br />
</br><br />
<a href="http://dl.dropbox.com/u/3158042/JavaAspectF.zip">Download AspectF in Java</a><br />
<i>NB. NetBeans 6.9 was used to build solution</i></p>
<br />Filed under: <a href='http://zenu.wordpress.com/category/programming/'>Programming</a> Tagged: <a href='http://zenu.wordpress.com/tag/aspectf/'>AspectF</a>, <a href='http://zenu.wordpress.com/tag/java/'>Java</a>, <a href='http://zenu.wordpress.com/tag/mockito/'>Mockito</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zenu.wordpress.com/392/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zenu.wordpress.com/392/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zenu.wordpress.com/392/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zenu.wordpress.com&amp;blog=2933292&amp;post=392&amp;subd=zenu&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zenu.wordpress.com/2011/01/05/aspectf-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac38459c3888aafa5936720fb3f38501?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Zenu</media:title>
		</media:content>
	</item>
	</channel>
</rss>
