<?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>meh &#187; coding</title>
	<atom:link href="http://www.bonf.net/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bonf.net</link>
	<description>-__-</description>
	<lastBuildDate>Sun, 11 Jul 2010 17:51:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>&#8220;Oh Crap It&#8217;s Morning&#8221; &#8211; Alpha Version</title>
		<link>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/</link>
		<comments>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 19:14:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[proof-of-concept]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=82</guid>
		<description><![CDATA[If you&#8217;ve been saying the above statement before, this program is for you. It&#8217;s an alarm clock application for S60 phones (more specifically Nokia 5800) written in Python The code is NOWHERE near what you&#8217;d expect of released code to be &#8211; this is NOT a release, rather a preview This is my first piece [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been saying the above statement before, this program is for you.</p>
<p>It&#8217;s an alarm clock application for S60 phones (more specifically Nokia 5800) written in Python<br />
<span id="more-82"></span></p>
<p><strong>The code is NOWHERE near what you&#8217;d expect of released code to be &#8211; this is NOT a release, rather a preview <img src='http://www.bonf.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></p>
<p>This is my first piece of code written in S60 Python. The code is not pretty, not well designed, not nothing &#8211; it&#8217;s just a proof of concept; helping me get to know the S60 python modules, and wake up on time.</p>
<p>The main feature of this program, that I could not find a ready-made S60 application that already accomplishes this, is the use of a random tune for every alarm.<br />
Don&#8217;t you hate it when you choose a song for an alarm clock, and find yourself hating the song ever after? Spazzing just a little bit every time you hear it?<br />
By choosing a random song every morning, you get to hear many of your favorite songs, without slowly developing hate towards them.</p>
<p>The second feature, is &#8220;fade in&#8221;. The song is initially played in low volume, which is gradually turned up.</p>
<p>Don&#8217;t rely on this code to wake you up for important meetings, it is probably full of bugs. It can&#8217;t save your last alarm properly (even though it tries to), but it will save your songs path.<br />
It is also semi-automatic, meaning you&#8217;ll have to set the alarm every night, it won&#8217;t do so automatically (yet!).<br />
It won&#8217;t survive phone shutdown either.<br />
It seems like python can&#8217;t overcome these obstacles easily, but I&#8217;ll try to improve it in the future. If I tried to code it with the bare Symbian API, it wouldn&#8217;t have reached the somewhat functional state it is in today&#8230;</p>
<p>I only post it here because I have started using it almost daily, and that both lowered my motivation to work for a more complete solution, and urged me to post the code somewhere, as other people may find it useful.<br />
It can also serve as a demo for S60 Python API use.</p>
<p>I have only tested it on Nokia 5800 which is S60 5th edition, with python 1.9.4.<br />
Other configurations may cause nuclear fusion.</p>
<p>Feel free to do whatever you want with the code.</p>
<p><a href="http://bonf.net/wp-content/uploads/2009/06/alarm.py">The Code</a></p>
<p>As a side note, during development I have used <a href="http://sourceforge.net/projects/pys60-compat/">pys60-compat</a> which is a wxPython based implementation of portions of the S60 python framework &#8211; meaning it let&#8217;s you run python code written for s60 in a testing environment on your desktop.<br />
It is somewhat outdated, and I have added some extensions of my own, which I may release in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create C# Documentation Using Sandcastle</title>
		<link>http://www.bonf.net/2009/03/04/create-c-documentation-using-sandcastle/</link>
		<comments>http://www.bonf.net/2009/03/04/create-c-documentation-using-sandcastle/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 14:10:42 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[sandcastle]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=76</guid>
		<description><![CDATA[Tomorrow I&#8217;m handing in my final project for my CS studies. This project is built in C#, and I was looking for a way to automatically create documentation that will aid browsing and understanding the main classes and their functions. A friend had told me about Sandcastle and I looked it up. Sandcastle is a [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow I&#8217;m handing in my final project for my CS studies. This project is built in C#, and I was looking for a way to automatically create documentation that will aid browsing and understanding the main classes and their functions.</p>
<p>A friend had told me about Sandcastle and I looked it up. <a href="http://sandcastle.codeplex.com/">Sandcastle</a> is a project by Microsoft, that is intended to create MSDN-style documentation from .NET assemblies&#8230;</p>
<p><span id="more-76"></span>I had managed to achieve my goal quite easily using Sandcastle, and I thought about sharing my experience to serve other people as a guide. This is just a quick write-up of what I did &#8211; I did not read Sandcastle&#8217;s documentation and I believe that I don&#8217;t know how to operate it to its full potential.</p>
<ol>
<li>The first step is to <a href="http://sandcastle.codeplex.com/">download</a> and install Sandcastle.</li>
<li>Next, if you haven&#8217;t done it already, you have to tell Visual Studio to build XML documentation files. This parses all your comments ( in the C# format ///&lt;summary&gt; etc&#8230;) and creates an XML file that we will feed into Sandcastle. To enable XML documentation, you have to go to Proect-&gt;(Project Name) Properties&#8230; and tick the relevant checkbox in the Build menu:<img class="alignnone size-full wp-image-77" title="builddoc" src="http://www.bonf.net/wp-content/uploads/2009/03/builddoc.png" alt="builddoc" width="790" height="666" /></li>
<li>We will now launch the Sandcastle GUI application, located in C:\Program Files\Sandcastle\Examples\generic ( replace C:\Program Files with wherever you had installed Sandcastle).</li>
<li>Add your assemblies (exe/dll) and XML comments file to the relevant list boxes and choose the desired output format. Enter you project name under &#8220;Name&#8221;.</li>
<li>Hit &#8220;Build&#8221;. The build process can take a while, and it may seem like the program is frozen, but it&#8217;s not.</li>
<li>Your documentation files should now be ready in  C:\Program Files\Sandcastle\Examples\Your Project Name</li>
<li>If you chose CHM as an output format, you will now have to compile the CHM file. To do this you need to download and install <a href="http://www.microsoft.com/downloads/details.aspx?familyid=00535334-c8a6-452f-9aa0-d597d16580cc&amp;displaylang=en">Microsoft HTML Help Workshop</a></li>
<li>After installing HTML Help Workshop, you will have to run hhc.exe (from the directory where you installed it). hhc takes an hhp (HTML Help Project) file as an argument. Sandcastle has created this hhp file for you, and it should be in your Sandcastle project directory. Just run &#8220;hhc yourproject.hhp&#8221; and this will produce a CHM file in the project&#8217;s directory.</li>
</ol>
<p>That&#8217;s it. You should now have your compiled CHM help file with nice MSDN-style documentation.</p>
<p>As I mentioned earlier, I don&#8217;t really know Sandcastle and will be happy to get some tips in the comments section if you have any.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2009/03/04/create-c-documentation-using-sandcastle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Generating Random Unicode Strings in C#</title>
		<link>http://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/</link>
		<comments>http://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 21:05:41 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=46</guid>
		<description><![CDATA[I have to admit this is quite a dull subject, but I thought it might help some guys( and gals! ) out there. I am working on a C# project for uni, and while fighting some pesky bugs, I decided I should get more organized and have a small &#8220;unit testing&#8221; framework built for it. [...]]]></description>
			<content:encoded><![CDATA[<p>I have to admit this is quite a dull subject, but I thought it might help some guys( and gals! ) out there.</p>
<p>I am working on a C# project for uni, and while fighting some pesky bugs, I decided I should get more organized and have a small &#8220;unit testing&#8221; framework built for it.</p>
<p>I had a need for random generated Unicode strings, and quick googling turned up no results. Instead of doing some broaded searching, I decided I could learn more by writing my own code:<br />
<span id="more-46"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> RandomUnicodeString
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> Random _r<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> RandomUnicodeString<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _r <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetString<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> length<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> str <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span>length <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> length <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">;</span> i<span style="color: #008000;">+=</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">int</span> chr <span style="color: #008000;">=</span> _r.<span style="color: #0000FF;">Next</span><span style="color: #000000;">&#40;</span>0xD7FF<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                str<span style="color: #000000;">&#91;</span>i<span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">byte</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>chr <span style="color: #008000;">&amp;</span> 0xFF00<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                str<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">byte</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>chr <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> Encoding.<span style="color: #0000FF;">Unicode</span>.<span style="color: #0000FF;">GetString</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>At first I had the string generation in the constructor, but it caused repeated strings, as I was using it in a loop, and newly created <em>Random</em> objects were using the same seed. More on this can be found in <a href="http://www.guyrutenberg.com/2007/09/03/seeding-srand/">Guy&#8217;s blog</a>.</p>
<p>If you want to limit the string to be of a specific language, there&#8217;s a reference of unicode mapping on <a href="http://en.wikipedia.org/wiki/Basic_Multilingual_Plane">Wikipedia</a>, just change _r.Next to use those limits.</p>
<p>There&#8217;s probably a better way for converting bytes to unicode chars, and this may not work on a little/big endian machine, but I don&#8217;t know enough about C# to tell for sure.</p>
<p>If you got here from google and this solved your coding problem, please post a comment ! =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[sic] &#8211; simple ipod converter</title>
		<link>http://www.bonf.net/2008/03/17/sic-simple-ipod-converter/</link>
		<comments>http://www.bonf.net/2008/03/17/sic-simple-ipod-converter/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 19:36:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[ipod]]></category>

		<guid isPermaLink="false">http://www.bonf.net/2008/03/17/sic-simple-ipod-converter/</guid>
		<description><![CDATA[&#8230;and why developing for Windows is not fun. Behold, a one-click way to convert your videos to a format playable by your iPod! [sic] Well, here&#8217;s my latest project. I&#8217;ve started it to provide my sister with a simple way to convert her videos, so that she could finally watch them on her shiny 6G [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;and why developing for Windows is not fun.</p>
<p>Behold, a one-click way to convert your videos to a format playable by your iPod!</p>
<p><a href="http://sic.bonf.net"><img src="http://sic.bonf.net/screen.png" alt="[sic]" height="219" width="231" />[sic]</a><br />
Well, here&#8217;s my latest project. I&#8217;ve started it to provide my sister with a simple way to convert her videos, so that she could finally watch them on her shiny 6G iPod.<br />
The result is this simple ffmpeg frontend, built to run on Windows, with the goal of ease of use.</p>
<p>At this point it is rather limited, and I&#8217;m not sure if I will ever work on it again.<br />
I&#8217;ve actually continued working on it after the uploaded build, but I have come to a <em>dead-end</em> with the Win32 API.<br />
I chose to work with the bare API because I did not want to do it in C#, and, well, as far as I know, there are no many other options.</p>
<p>Why not C#? Even though the .NET Framework is widely available, I thought it was too much for a couple of buttons that launch an exeternal application.<br />
I did not want to use MFC, because I&#8217;m unfamilar with it, and last time I used it it felt over-complex and messy. It also requires additional Dlls, or huge executable.</p>
<p>So Win32 API it was. I fired up Emacs (my new tool of the trade) and started coding.<br />
As long as my code was a mess (i.e. <strong>C</strong> style coding, global vars etc ), everything was smooth and fun. I then wanted to add a system tray notification icon, and thought it would be<br />
a good idea to create it inside a class, for use in later projects. This is where things started to break. I spent some hours researching methods to connect my window procedure to<br />
members of my class. The solution involved an assembly hack. While interesting, I wanted nothing of it.</p>
<p>During my research, I came across WTL, which sounds just like what I was looking for. If/When I continue this project and/or develop another Windows application, it&#8217;s going to be in WTL.<br />
Though I did find the lack of documentation annoying.</p>
<p>As a side note, I have to find out what utorrent used.</p>
<p>That&#8217;s it for now, hope someone will find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2008/03/17/sic-simple-ipod-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Almost) Free MIDI Controller</title>
		<link>http://www.bonf.net/2008/02/25/almost-free-midi-controller/</link>
		<comments>http://www.bonf.net/2008/02/25/almost-free-midi-controller/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 20:31:19 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[diy]]></category>
		<category><![CDATA[midi]]></category>
		<category><![CDATA[proof-of-concept]]></category>

		<guid isPermaLink="false">http://www.bonf.net/2008/02/25/almost-free-midi-controller/</guid>
		<description><![CDATA[Well it&#8217;s about time that I posted something. Two weeks ago, a friend of mine asked me for help. He wanted to create something that will allow him to control all sorts of effects in Fruity Loops, like many available midi controller products. He was, however, looking for the cheapest solution, and suggested using an [...]]]></description>
			<content:encoded><![CDATA[<p>Well it&#8217;s about time that I posted something.</p>
<p>Two weeks ago, a friend of mine asked me for help. He wanted to create something that will allow him to control all sorts of effects in Fruity Loops, like many available midi controller products. He was, however, looking for the cheapest solution, and suggested using an old keyboard as a controller.</p>
<p>As I was toying with MIDI and my Arduino at the time, and started messing around in Fruity Loops, I was able to come up with a quick and easy solution.  I used code from the <a href="http://www.memeteam.net/2007/s2midi/">s2midi</a> application, that I had known from my Arduino prototyping and another Code Project example about keyboard hooks in C#.</p>
<p>After around 10 hours of development I came up with a small application that catches all keyboard input using hooks (and does not pass them to other applications, to prevent collision with existing hotkeys), and generates MIDI control commands. <a href="http://www.midiox.com/">MIDI Yoke </a>was used to bridge  my application&#8217;s output and FL&#8217;s input.</p>
<p>The application works by &#8220;emulating&#8221; knobs, with assigned keys to increment, decrement, maximize or minimze their values. It is also possible to choose different step sizes for inc/dec. Currently the knobs are &#8220;hardcoded&#8221; as they are needed for my friend&#8217;s modified keyboard controller:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2008/02/24022008425.jpg" title="Controller"><img src="http://www.bonf.net/wp-content/uploads/2008/02/24022008425.thumbnail.jpg" alt="Controller" /></a></p>
<p>He connected the keyboard via USB, alongside a normal keyboard, and is going to use the two to control Fruity Loops in real-time.</p>
<p>Here&#8217;s a screenshot of my app:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2008/02/keyboardmidi.PNG" title="Screenshot"><img src="http://www.bonf.net/wp-content/uploads/2008/02/keyboardmidi.thumbnail.PNG" alt="Screenshot" /></a></p>
<p>Although it may be a bit funny to post about this application without releasing the code and executable, I&#8217;d rather not do it at the moment, as it requires a bit more work. I did not aim for high code quality anyway, as it is one of my first C# applications.</p>
<p>I think this will turn out to a simple program that one could use to control music software better than a mouse, but still no match for a true hardware MIDI controller (which is one of the projects in my TODO list <img src='http://www.bonf.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2008/02/25/almost-free-midi-controller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Translation through Wikipedia</title>
		<link>http://www.bonf.net/2007/06/09/translation-through-wikipedia/</link>
		<comments>http://www.bonf.net/2007/06/09/translation-through-wikipedia/#comments</comments>
		<pubDate>Sat, 09 Jun 2007 07:49:34 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[proof-of-concept]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://www.bonf.net/2007/06/09/translation-through-wikipedia/</guid>
		<description><![CDATA[There&#8217;s a new version of Wikislate up! read about it here Here&#8217;s a small neat script that I coded yesterday in about 1.5 hours &#8211; Wikislate The script was created to simplify a process that I&#8217;ve been using for some time. Being a math&#38;cs student, I&#8217;ve acquired the unique mathematical-technical jargon (and I keep doing [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #0000ff;"><strong><em>There&#8217;s a new version of Wikislate up! read about it <a href="http://www.bonf.net/2009/02/20/wikislatecom-is-up/">here</a></em></strong></span></p>
<p>Here&#8217;s a small neat script that I coded yesterday in about 1.5 hours &#8211; <a href="http://wikislate.bonf.net">Wikislate</a></p>
<p>The script was created to simplify a process that I&#8217;ve been using for some time. Being a math&amp;cs student, I&#8217;ve acquired the unique mathematical-technical jargon (and I keep doing so).<br />
The problem is that I live and study in Israel &#8211; in the Hebrew language. Given the fact that there&#8217;s a great English mathematical knowledge-base online (<a href="http://mathworld.wolfram.com/">Wolfram</a> is the first website that crosses my mind right now), I had to know the English equivalents of the Hebrew mathematical terms.<br />
The method that I found was to load up the Hebrew Wikipedia page for the term, and then look for the English interwiki link &#8211; for the English version of the article.<br />
Most of the time, I only had to read the title of the English page to know I was at the right place.</p>
<p>Yesterday night, after desperately trying to get asleep (my brain suddenly decided to start intensive thinking the night before an exam &#8211; took me 2 hours to get asleep)  , I came up with the idea to code a quick and simple PHP script that will do the work for me, and act as my scientific terms dictionary. I had some spare ( I decided it was spare ) time, and the above code was the result of a quick coding session. As the code came along, I thought that incorporating Google&#8217;s &#8220;Did you mean&#8221; is a neat feature. So in case a term wasn&#8217;t found, it tries the Google search for it, just to get the &#8220;Did you mean&#8221; line for you <img src='http://www.bonf.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I hope other people will find it useful. I might improve it, making it use shiny AJAX and maybe even have a db store the searched terms for autocompletion.<br />
I have the intention to write a bit about how it was done (really fairly simple) &#8211; again, if there&#8217;s enough interest.</p>
<p>Enjoy, and please comment about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2007/06/09/translation-through-wikipedia/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>So&#8230;</title>
		<link>http://www.bonf.net/2007/05/18/so/</link>
		<comments>http://www.bonf.net/2007/05/18/so/#comments</comments>
		<pubDate>Fri, 18 May 2007 20:36:38 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=3</guid>
		<description><![CDATA[Yeah, well, it&#8217;s my blog. Hi. So, hmm, basically, I&#8217;m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places. Solutions to coding problems (yes, I&#8217;m a [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, well, it&#8217;s my blog. Hi.</p>
<p>So, hmm, basically, I&#8217;m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places.  Solutions to coding problems (yes, I&#8217;m a coder) , interesting reviews and recommendations, and articles.</p>
<p>I thought that I should give back to the web, publish more code that I write, and help others with problems that I have solved. The hosting plan and domain were purchased about 2 months ago, and only now I write my first post, well, I&#8217;m a busy man XD</p>
<p>There&#8217;s more to come next. I don&#8217;t want to put too much effort to the first posts, as there&#8217;s a high chance that I will abandon this blog quickly, and no one will ever read them.</p>
<p>Anyway, I&#8217;ll post something small and quick that I had coded some days ago in 10 minutes.</p>
<p>Some weeks ago I&#8217;ve been contacted by an online buddy to whom I didn&#8217;t  speak in 2 or 3 years. It was a period during which I was highly enthusiastic about 3d and animation, and he was one of the experts in the forum where I used to &#8220;hang&#8221; <img src='http://www.bonf.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  . The short conversation with him inspired me to do some 3d modeling, and I came up with something (quite lame) for a quick modeling challenge in some forum.</p>
<p>So, I had a time limit, and I wanted to keep measure of time as I was modeling. The right thing to do was certainly to program a stopwatch in python using pygame ! I&#8217;ll just post the code now, and will look for a code highlighting plug-in for wordpress later.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pygame,pygame.<span style="color: black;">font</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pygame.<span style="color: #008000;">locals</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#yuck, global vars ^_^</span>
font=<span style="color: #008000;">None</span>
surface=<span style="color: #008000;">None</span>
<span style="color: #dc143c;">time</span>=<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># an array to keep the current time measurement which is being rendered</span>
start_state=<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;">#the time measurement from which to start counting</span>
start_tick=<span style="color: #ff4500;">0</span> <span style="color: #808080; font-style: italic;"># the number of ticks when we began counting</span>
on=<span style="color: #008000;">False</span> <span style="color: #808080; font-style: italic;">#wheter the stopwatch should be running or not</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> font,surface,on
&nbsp;
    video_flags = DOUBLEBUF
    pygame.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#initialize pygame</span>
    surface = pygame.<span style="color: black;">display</span>.<span style="color: black;">set_mode</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">200</span>,<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>, video_flags<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#create our main window SDL surface</span>
    surface.<span style="color: black;">fill</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#fill with white</span>
&nbsp;
    font = pygame.<span style="color: black;">font</span>.<span style="color: black;">Font</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'INK2SCRI.TTF'</span>,<span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#load up a ttf font</span>
    last_tick = pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>	<span style="color: #808080; font-style: italic;"># initialize the tick count</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>: <span style="color: #808080; font-style: italic;">#do forever</span>
        event = pygame.<span style="color: black;">event</span>.<span style="color: black;">poll</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> event.<span style="color: #008000;">type</span> == QUIT:
            <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> event.<span style="color: #008000;">type</span> == KEYUP <span style="color: #ff7700;font-weight:bold;">and</span> event.<span style="color: black;">key</span>==<span style="color: #ff4500;">32</span>: <span style="color: #808080; font-style: italic;"># if the space bar was pushed</span>
            <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>on<span style="color: black;">&#41;</span>: <span style="color: #808080; font-style: italic;"># if currently running</span>
                <span style="color: #808080; font-style: italic;">#prepare start_state for future use, save current time</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #808080; font-style: italic;">#starting the timer, so set the tick count reference to the current tick count</span>
                start_tick = pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            on = <span style="color: #ff7700;font-weight:bold;">not</span> on <span style="color: #808080; font-style: italic;">#toggle on</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>on<span style="color: black;">&#41;</span>:
            a = <span style="color: black;">&#40;</span>pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - start_tick<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># get the amount of ticks(miliseconds) that passed from when the stopwatch was last run</span>
&nbsp;
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+ <span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">60</span> <span style="color: #808080; font-style: italic;">#seconds</span>
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>+<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#minutes</span>
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>+<span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">3600</span> <span style="color: #808080; font-style: italic;">#hours</span>
&nbsp;
        draw<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        pygame.<span style="color: black;">display</span>.<span style="color: black;">flip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> draw<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> surface,font
&nbsp;
<span style="color: #808080; font-style: italic;">#render the time, by converting each array member to a string, and concating with ':' in between time components. render in black on a white background.</span>
    tempsurface=font.<span style="color: black;">render</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">':'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">':'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,<span style="color: #ff4500;">1</span>,<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>,<span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    surface.<span style="color: black;">fill</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#fill the screen with white, to erase the previous time</span>
    surface.<span style="color: black;">blit</span><span style="color: black;">&#40;</span>tempsurface,<span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span>,<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># blit the temporary surface to the screen</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>__name__==<span style="color: #483d8b;">'__main__'</span><span style="color: black;">&#41;</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Check out the screenshot:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2007/05/screen.PNG" title="screen.PNG"><img src="http://www.bonf.net/wp-content/uploads/2007/05/screen.thumbnail.PNG" alt="screen.PNG" /></a></p>
<p>And here&#8217;s the model that I used it for:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2007/05/hook.jpg" title="Hook"><img src="http://www.bonf.net/wp-content/uploads/2007/05/hook.thumbnail.jpg" alt="Hook" /></a></p>
<p>I&#8217;m happy to finally start this blog, hope I will manage to keep writing, and that people will actually read it some time in the future.</p>
<p>Ben.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2007/05/18/so/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
