<?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>Guy Rutenberg &#187; Projects</title>
	<atom:link href="http://www.guyrutenberg.com/tag/projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Audio Based True Random Number Generator POC</title>
		<link>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/</link>
		<comments>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/#comments</comments>
		<pubDate>Fri, 14 May 2010 12:18:14 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=678</guid>
		<description><![CDATA[Few days ago I came up with an idea to create a true random number generator based on noise gathered from a cheap microphone attached to my computer. Tests showed that when sampling the microphone, the least significant bit behaves pretty randomly. This lead me to think it might be good source for gathering entropy [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I came up with an idea to create a true random number generator based on noise gathered from a cheap microphone attached to my computer. Tests showed that when sampling the microphone, the least significant bit behaves pretty randomly. This lead me to think it might be good source for gathering entropy for a true random number generator.<br />
<span id="more-678"></span><br />
The base design was to gather the noise from the microphone than apply a process that will make in more uniform and refine its randomness. After some design iterations I came up with a process based on applying a hash function to the noise. Each iteration involves filling block of the hash function from the least significant bits of the microphone output and applying the hash. Each iteration outputs the current hash digest. Assuming the hash function is uniform, this will output a uniformly distributed blocks of bits. Furthermore, because there the previous state of the hash function influences the next digest computation, the process accumulates entropy that can smooth out potentially less random blocks. Because for all commonly used hash function the block size is much larger than the digest size the output can tell much about the current state or any future or past state. This also holds true even if someone can find all pre-images of the hash function as the amount of possible states will be too big.</p>
<p>I&#8217;ve built a Python proof of concept (using md5 as a hash function) suitable for Linux.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> GRandom:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">audio</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/dev/dsp&quot;</span>,<span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span> = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_raw_block<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        buffer = <span style="color: #008000;">self</span>.<span style="color: black;">audio</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">block_size</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">bytes</span> = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%iB&quot;</span><span style="color: #66cc66;">%</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>buffer<span style="color: black;">&#41;</span>, buffer<span style="color: black;">&#41;</span>
&nbsp;
        longs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">block_size</span>/<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>:
            temp = <span style="color: #ff4500;">0</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> b <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">bytes</span><span style="color: black;">&#91;</span>i<span style="color: #66cc66;">*</span><span style="color: #ff4500;">32</span>:<span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">32</span><span style="color: black;">&#93;</span>:
                temp = <span style="color: black;">&#40;</span>temp <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> ^ <span style="color: black;">&#40;</span>b <span style="color: #66cc66;">&amp;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
            longs.<span style="color: black;">append</span><span style="color: black;">&#40;</span>temp<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%iI&quot;</span><span style="color: #66cc66;">%</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>longs<span style="color: black;">&#41;</span>, <span style="color: #66cc66;">*</span>longs<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_block<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">get_raw_block</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: #008000;">hash</span>.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The amount of generated bits per second is given by (sample rate)*(digest size)/(block size). So for 8KHz (default) sampling rate and md5 we&#8217;ll get a theoretical speed of ~250Kbs. SHA type hashes have higher digest to block size ration thus may result in higher speeds. Another source of speed up may be to change the sample rate of the microphone. But setting it to high may have negative effects on the entropy. The code may get a considerable performance gain by porting it to c/c++, as it uses both bit manipulations and calculates hashes. Anyways, even the Python implementation&#8217;s speed allows us it be used for many cases where true randomness is required, such as generating passwords.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2010/05/14/audio-based-true-random-number-generator-poc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Early Release of the New cssrtl.py-2.0</title>
		<link>http://www.guyrutenberg.com/2009/09/20/an-early-release-of-the-new-cssrtl-py-2-0/</link>
		<comments>http://www.guyrutenberg.com/2009/09/20/an-early-release-of-the-new-cssrtl-py-2-0/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 10:00:50 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[cssrtl.py]]></category>
		<category><![CDATA[RTL]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=578</guid>
		<description><![CDATA[It has been three years since I&#8217;ve released the ]]></description>
			<content:encoded><![CDATA[<p>It has been three years since I&#8217;ve released the <a href=/2007/12/28/convert-css-layout-to-rtl-cssrtlpy/">original version</a> of <code>cssrtl.py</code> (and two since it&#8217;s re-release). The old version did a nice job, but experience gained during that time led me to write from scratch a new version. I&#8217;ve detailed more than a month ago, the <a href="/2009/08/05/designing-a-better-a-css-rtl-convertor/">basic principles and ideas</a> that guided me to design a better tool to help adapting CSS files from left-to-right to right-to-left.</p>
<p>The guidelines weren&#8217;t just empty words, they were written while working on the <a href="/2009/08/15/rtl-and-hebrew-adaptation-of-the-fusion-wordpress-theme/">Hebrew adaptation to the Fusion theme</a> and in the same time writing a new proof-of-concept version of <code>cssrtl.py</code>. The original intent was to release a more mature version of that code when it will be completed. However, due to the apparent shortage of time in the present and foreseeable future, I can&#8217;t see myself complete the project any time soon. So following the &#8220;release early&#8221; mantra, I&#8217;ve decided to release the code as-is. As I said, the code is in working state, but not polished, so it may be of benefit but may contain bugs. If you find any bugs or have any suggestions, I would be glad to hear.<br />
<span id="more-578"></span></p>
<h3>Download</h3>
<p>You can download the new version from here: <a href="/wp-content/uploads/2009/09/cssrtl.py-2.0.tar.bz2">cssrtl.py-2.0.tar.bz2</a>. The code is available under the GPLv2 or any later version.</p>
<h3>Usage</h3>
<p>The new version works by creating a seperate css &#8220;fix&#8221; file that fixes the directionality of the css styles.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">./cssrtl.py &lt; main.css &gt; main-rtl.css</pre></div></div>

<p>Afterward, just link the <code>main-rtl.css</code> after <code>main.css</code> in your HTML files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/09/20/an-early-release-of-the-new-cssrtl-py-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple AI Engine for the Oware Game</title>
		<link>http://www.guyrutenberg.com/2009/08/19/simple-ai-engine-for-the-oware-game/</link>
		<comments>http://www.guyrutenberg.com/2009/08/19/simple-ai-engine-for-the-oware-game/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 10:54:28 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[oware]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=568</guid>
		<description><![CDATA[Sometime ago I worked with a friend on building an Oware game. I was supposed to build the AI engine, and he was supposed to build the user interface to it. Unfortunately, while AI engine interface I designed and a simple alpha-beta pruning engine was implemented, the project was never completed.

Instead of letting the project [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime ago I worked with a friend on building an <a href="http://en.wikipedia.org/wiki/Oware">Oware</a> <a href="http://www.wikimanqala.org/wiki/Oware">game</a>. I was supposed to build the AI engine, and he was supposed to build the user interface to it. Unfortunately, while AI engine interface I designed and a simple alpha-beta pruning engine was implemented, the project was never completed.</p>
<div id="attachment_569" class="wp-caption alignnone" style="width: 672px"><img src="http://www.guyrutenberg.com/wp-content/uploads/2009/08/oware-screenshot.png" alt="Screenshot of game session" title="oware-screenshot" width="662" height="412" class="size-full wp-image-569" /><p class="wp-caption-text">Screenshot of game session</p></div>
<p><span id="more-568"></span><br />
Instead of letting the project just sit and wait until it will be redeemed and completed I&#8217;ve decided to release my code. It consists of a simple terminal user-interface and an AI opponent. Compiling is straight forward and doesn&#8217;t require any special libraries. You can obtain the code from here: <a href="/wp-content/uploads/2009/09/oware-0.1.tar.bz2">oware-0.1.tar.bz2</a> [15.1 KB].</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">tar xvf ./oware-0.1.tar.bz2
cd oware
g++ main.cpp ai/basic_ai_engine.cpp -o oware</pre></div></div>

<p>Running the program is pretty simple, just type <code>./oware</code>. You will be prompted to select the level of the AI opponent. The higher the number the slower and better the opponent will play. I suggest starting pretty low, and climbing up untill you find it challenging. The houses (holes) are numbered from 0 to 11 starting with the bottom left hole (yours) and going counter-clockwise. </p>
<p>The game is licensed under the GPLv2 or any latter version, so fill free to hack and improve the game if you have time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/08/19/simple-ai-engine-for-the-oware-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RTL and Hebrew Adaptation of the Fusion Wordpress Theme</title>
		<link>http://www.guyrutenberg.com/2009/08/15/rtl-and-hebrew-adaptation-of-the-fusion-wordpress-theme/</link>
		<comments>http://www.guyrutenberg.com/2009/08/15/rtl-and-hebrew-adaptation-of-the-fusion-wordpress-theme/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 05:52:22 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[RTL]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=455</guid>
		<description><![CDATA[I&#8217;ve ported the Fusion theme by digitalnature to RTL, and adapted it to Hebrew.


 Porting this theme to RTL was the main catalysis for improving my cssrtl.py script. Beside translating the theme to Hebrew and making the necessary CSS adaptation to RTL, I had also to adopt the fonts used. The font selected by the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve ported the <a href="http://digitalnature.ro/projects/fusion">Fusion</a> theme by <a href="http://digitalnature.ro/">digitalnature</a> to RTL, and adapted it to Hebrew.</p>
<p><img src="http://www.guyrutenberg.com/wp-content/uploads/2009/08/screenshot.png" alt="screenshot" title="screenshot" width="300" height="225" class="alignnone size-full wp-image-527" /><br />
<span id="more-455"></span><br />
 Porting this theme to RTL was the main catalysis for improving my <a href="/2009/08/05/designing-a-better-a-css-rtl-convertor/">cssrtl.py</a> script. Beside translating the theme to Hebrew and making the necessary CSS adaptation to RTL, I had also to adopt the fonts used. The font selected by the author weren&#8217;t compatible with Hebrew, and the alternatives looked awful. So I&#8217;ve chose some other fonts from the same family to keep the overall look of the theme, but make it more Hebrew friendly.</p>
<p>You can see a live version of the theme in <a href="http://www.davidzadok.co.il">David Zadok</a>&#8217;s site. The theme can be downloaded from here: <a href="/wp-content/uploads/2009/08/fusion-rtl-2.6.zip">fusion-rtl-2.6.zip</a> [326.8kb]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/08/15/rtl-and-hebrew-adaptation-of-the-fusion-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Histogram Widget for wxWidgets</title>
		<link>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/</link>
		<comments>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:25:28 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[wxWidgets]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=444</guid>
		<description><![CDATA[When working on Open Yahtzee 1.10 (or what ever I&#8217;ll call the version after 1.9), I&#8217;ve written a simple histogram widget to be part of the new statistics dialog. I should emphasize the simple part, this widget was mean to display a simple histogram without requiring any special bloated ploting libraries. It doesn&#8217;t support all [...]]]></description>
			<content:encoded><![CDATA[<p>When working on <a href="http://www.openyahtzee.org/">Open Yahtzee</a> 1.10 (or what ever I&#8217;ll call the version after 1.9), I&#8217;ve written a simple histogram widget to be part of the new statistics dialog. I should emphasize the <em>simple</em> part, this widget was mean to display a simple histogram without requiring any special bloated ploting libraries. It doesn&#8217;t support all the fancy stuff, just plain histogram. </p>
<p>I&#8217;ve figured that a simple pie plot would better serve Open Yahtzee&#8217;s needs, so unfortunately this code will not be released as part of the program. While the code is not perfect, it&#8217;s functional and serves a good example of a custom widget. So I&#8217;ve felt pity letting it fall into oblivion in Open Yahtzee&#8217;s SVN repository, and I&#8217;ve thought it might come handy to someone else (or at least for me) if it will be easily accessible.</p>
<p><img src="http://www.guyrutenberg.com/wp-content/uploads/2009/08/simple_histogram.png" alt="simple_histogram" title="simple_histogram" width="320" height="254" class="alignnone size-full wp-image-450" /><br />
<span id="more-444"></span><br />
The widget is made up of two files: <code>simple_histogram.h</code> and <code>simple_histogram.cpp</code>. The code uses <code>stl::vector</code> to pass the plotting data and depenpends on <code>BOOST_FOREACH</code> (but it can easily be removed).</p>
<p><code>simple_histogram.h</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/***************************************************************************
 *   Copyright (C) 2009 by Guy Rutenberg   *
 *   http://www.guyrutenberg.com/contact-me   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/</span>
&nbsp;
<span style="color: #339900;">#include &lt;wx/wx.h&gt;</span>
<span style="color: #339900;">#include &lt;vector&gt;</span>
&nbsp;
<span style="color: #339900;">#ifndef SIMPLE_HISTOGRAM_INC</span>
<span style="color: #339900;">#define SIMPLE_HISTOGRAM_INC</span>
&nbsp;
<span style="color: #0000ff;">class</span> SimpleHistogram <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> wxPanel <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	SimpleHistogram <span style="color: #008000;">&#40;</span>wxWindow<span style="color: #000040;">*</span> parent, wxWindowID id,
		 <span style="color: #0000ff;">const</span> wxPoint<span style="color: #000040;">&amp;</span> pos <span style="color: #000080;">=</span> wxDefaultPosition, <span style="color: #0000ff;">const</span> wxSize<span style="color: #000040;">&amp;</span> size <span style="color: #000080;">=</span> wxDefaultSize,
		 <span style="color: #0000ff;">long</span> style <span style="color: #000080;">=</span> wxNO_BORDER, <span style="color: #0000ff;">const</span> wxString<span style="color: #000040;">&amp;</span> name <span style="color: #000080;">=</span> wxPanelNameStr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> SetData<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> d<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> OnPaint<span style="color: #008000;">&#40;</span>wxPaintEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> OnResize<span style="color: #008000;">&#40;</span>wxSizeEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> data<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> data_total<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #339900;">#endif</span></pre></div></div>

<p><code>simple_histogram.cpp</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/***************************************************************************
 *   Copyright (C) 2009 by Guy Rutenberg   *
 *   http://www.guyrutenberg.com/contact-me   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/</span>
&nbsp;
<span style="color: #339900;">#include &quot;simple_histogram.h&quot;</span>
<span style="color: #339900;">#include &lt;boost/foreach.hpp&gt;</span>
<span style="color: #339900;">#include &lt;memory&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">SimpleHistogram</span><span style="color: #008000;">&#40;</span>wxWindow<span style="color: #000040;">*</span> parent, wxWindowID id,
				<span style="color: #0000ff;">const</span> wxPoint<span style="color: #000040;">&amp;</span> pos, <span style="color: #0000ff;">const</span> wxSize<span style="color: #000040;">&amp;</span> size,
				<span style="color: #0000ff;">long</span> style, <span style="color: #0000ff;">const</span> wxString<span style="color: #000040;">&amp;</span> name<span style="color: #008000;">&#41;</span>
				<span style="color: #008080;">:</span> wxPanel<span style="color: #008000;">&#40;</span>parent, id, pos, size, style, name<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Connect<span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetId<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, wxEVT_PAINT, wxPaintEventHandler<span style="color: #008000;">&#40;</span>SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnPaint</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Connect<span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetId<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, wxEVT_SIZE, wxSizeEventHandler<span style="color: #008000;">&#40;</span>SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnResize</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnPaint</span><span style="color: #008000;">&#40;</span>wxPaintEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	wxPaintDC pdc<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	auto_ptr<span style="color: #000080;">&lt;</span>wxGraphicsContext<span style="color: #000080;">&gt;</span> dc<span style="color: #008000;">&#40;</span>wxGraphicsContext<span style="color: #008080;">::</span><span style="color: #007788;">Create</span><span style="color: #008000;">&#40;</span>pdc<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	dc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>SetBrush<span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>wxBLUE_BRUSH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> width, height<span style="color: #008080;">;</span>
	GetClientSize<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>width, <span style="color: #000040;">&amp;</span>height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">double</span> column_width <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>width<span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> data.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> item_x, item_y, item_ratio, item_height<span style="color: #008080;">;</span>
	BOOST_FOREACH<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> d, data<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		item_x <span style="color: #000080;">=</span> i <span style="color: #000040;">*</span> column_width<span style="color: #008080;">;</span>
		item_ratio <span style="color: #000080;">=</span> data_total <span style="color: #008080;">?</span> d<span style="color: #000040;">/</span>data_total <span style="color: #008080;">:</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
		item_height <span style="color: #000080;">=</span> item_ratio <span style="color: #000040;">*</span> height<span style="color: #008080;">;</span>
		item_y <span style="color: #000080;">=</span> height<span style="color: #000040;">-</span>item_height<span style="color: #008080;">;</span>
		dc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>DrawRectangle<span style="color: #008000;">&#40;</span>item_x, item_y, column_width, item_height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		i<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">OnResize</span><span style="color: #008000;">&#40;</span>wxSizeEvent<span style="color: #000040;">&amp;</span> event<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Refresh<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	event.<span style="color: #007788;">Skip</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> SimpleHistogram<span style="color: #008080;">::</span><span style="color: #007788;">SetData</span><span style="color: #008000;">&#40;</span>vector<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span> d<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	data.<span style="color: #007788;">assign</span><span style="color: #008000;">&#40;</span>d.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, d.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	data_total <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	BOOST_FOREACH<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> tmp, data<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		data_total <span style="color: #000040;">+</span><span style="color: #000080;">=</span> tmp<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>UPDATE 2009-08-17:</strong> Removed commented out function &#8211; <code>DoGetBestSize()</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/08/13/simple-histogram-widget-for-wxwidgets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Designing a Better a CSS RTL Convertor</title>
		<link>http://www.guyrutenberg.com/2009/08/05/designing-a-better-a-css-rtl-convertor/</link>
		<comments>http://www.guyrutenberg.com/2009/08/05/designing-a-better-a-css-rtl-convertor/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 09:41:15 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[cssrtl.py]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=418</guid>
		<description><![CDATA[About a year and a half ago I&#8217;ve released cssrtl.py, a script that translates CSS code to RTL. The script was designed to be fully autonomous, however translating CSS code is a complex task, as not all the information needed to make the translation is available in the CSS files. While cssrtl.py did a very [...]]]></description>
			<content:encoded><![CDATA[<p>About a year and a half ago I&#8217;ve released <a href="/2007/12/28/convert-css-layout-to-rtl-cssrtlpy/"><code>cssrtl.py</a>, a script that translates CSS code to RTL. The script was designed to be fully autonomous, however translating CSS code is a complex task, as not all the information needed to make the translation is available in the CSS files. While <code>cssrtl.py</code> did a very good job on some tasks it lacks on several issues:</p>
<ol>
<li>When a design update is released, one cannot use previous translation work.</li>
<li>When things don't go smooth, it's hard to find out why.</li>
<li>Complex CSS can't be translated automatically, as it requires understanding of the structure of the corresponding html files and how the CSS will be used by future code.</li>
</ol>
<p><span id="more-418"></span><br />
There are two basic ideas behind building a new and improved replacement for <code>cssrtl.py</code>. The first, instead of translating the CSS file, the script will create a patch that translates the code. This would allow to see the changes required for RTL changes and easily adapt new version of the CSS code. This also solves the second problem, as it makes clear what changes where made by the script and what are part of the original code. The other change takes the script from trying to be autonomous to human guided translation. Instead of making all the changes completely by itself, the script only makes trivial changes (which are most changes) and clearly leaves comments guiding the human operator on what work remained to be done. This approach saves a lot of time as the script works only does what it can and doesn't hinder the translation efforts by trying to translate code that it can't translate properly.</p>
<p>Following this new design for CSS to RTL convertor, I've built a new version of <code>cssrtl.py</code>. The new version is still premature work, and some work needs to be done before I'll be able to release it publicly. However, it already revealed itself handy when I adapted a WordPress theme to Hebrew, which I intend to release soon.</p>
<p><strong>Update 2009-08-15:</strong> I've released the mentioned WordPress theme, it's <a href="/2009/08/15/rtl-and-hebrew-adaptation-of-the-fusion-wordpress-theme/">RTL port of the Fusion theme</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/08/05/designing-a-better-a-css-rtl-convertor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hash Puppy &#8211; A Qt Checksum Calculator</title>
		<link>http://www.guyrutenberg.com/2009/05/29/hash-puppy-a-qt-checksum-calculator/</link>
		<comments>http://www.guyrutenberg.com/2009/05/29/hash-puppy-a-qt-checksum-calculator/#comments</comments>
		<pubDate>Fri, 29 May 2009 10:56:03 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Hash Puppy]]></category>
		<category><![CDATA[QT]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=365</guid>
		<description><![CDATA[I&#8217;ve decided to give Qt a try after long time of wxWidgets programming. When I learn to a new language or how to use a new library I always like to build some small projects to get my hands dirty with. This time I&#8217;ve built small checksum calculator &#8211; Hash Puppy (in fact, first I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to give Qt a try after long time of wxWidgets programming. When I learn to a new language or how to use a new library I always like to build some small projects to get my hands dirty with. This time I&#8217;ve built small checksum calculator &#8211; Hash Puppy (in fact, first I had the name then I&#8217;ve decided I must use it for some new project). </p>
<p><img src="http://www.guyrutenberg.com/wp-content/uploads/2009/05/hashpuppy.png" alt="hashpuppy" title="hashpuppy" width="518" height="211" class="aligncenter size-full wp-image-366" /><br />
<span id="more-365"></span><br />
As a checksum calculator Hash Puppy is pretty simple, as it supports only MD4, MD5 and SHA1. It also supports basic Drag and Drop and clipboard interaction. The source code for Hash Puppy is released under the GPL and available from here: <a href="/wp-content/uploads/2009/05/hashpuppy-0.1.tar.bz2">hashpuppy-0.1.tar.bz2</a>.</p>
<p>While the wxWidgets vs Qt story should be part of another post, I can note that programming Qt was fun. While first I was dismayed by the use of non-standard C++ syntax for the Signal-Slot mechanism, I really liked the otherwise clean and modern C++ syntax used by Qt. The Qt Designer is a great utility, and really makes the tedious work of making the UI easy. I liked that Qt Designer encourages the user to inherit the dialog classed he designs in order to add functionality, over the approach used in <a href="http://wxglade.sourceforge.net/">wxGlade</a> which is based on editing the code the program generates. Unfortunately, I don&#8217;t have enough time to pursue such change in wxGlade. </p>
<p><strong>Update</strong> 11/12/2009: Fixed the download link.<br />
<strong>Update</strong> 31/3/2010: A new version is available: <a href="/2010/03/31/hash-puppy-0-2/">Hash Puppy 0.2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/05/29/hash-puppy-a-qt-checksum-calculator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>tarsum-0.2 &#8211; A read only version of tarsum</title>
		<link>http://www.guyrutenberg.com/2009/04/29/tarsum-02-a-read-only-version-of-tarsum/</link>
		<comments>http://www.guyrutenberg.com/2009/04/29/tarsum-02-a-read-only-version-of-tarsum/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 06:58:31 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[tarsum]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=315</guid>
		<description><![CDATA[When I first scratched the itch of calculating checksums for every file in a tar archive, this was my original intention. When I decided I want the script in bash for simplicity, I forfeited the idea and settled for extracting the files and then going over all the files to calculate their checksum value.
So when [...]]]></description>
			<content:encoded><![CDATA[<p>When I first scratched the itch of calculating checksums for every file in a tar archive, this was my original intention. When I decided I want the script in bash for simplicity, I forfeited the idea and settled for extracting the files and then going over all the files to calculate their checksum value.</p>
<p>So when <a href="/2008/10/24/tarsum-calculate-checksum-for-files-inside-tar-archive/#comment-19087">Jon Flowers asked</a> in the comments of the original <a href="/2008/10/24/tarsum-calculate-checksum-for-files-inside-tar-archive/"><code>tarsum</code> post</a> about the possibility of getting the checksums of files in the tar file without extracting all the archive, I&#8217;ve decided to re-tackle the problem.</p>
<p><span id="more-315"></span></p>
<p>This time I&#8217;ve chose python and by using the <code>tarfile</code> and <code>hashlib</code> modules I came up with a solution that allowed me to go over tar files to calculate the checksum values without extracting all of them to the disk. However some sacrifices where made in the form of back-compatibility of the output. I&#8217;ve tried to make the interface similar to the old one, and have kept all the command line options. Instead of specifying a program name to calculate the checksum values (such as <code>sha1sum</code>) as argument to <code>--checksum</code> you specify the name of the checksum algorithm such as md5, sha1, sha256, sha512 (or any other supported by <code>hashlib</code>).</p>
<p>Other changes where made so tar files can be piped directly into <code>tarsum</code> (which also works transparently with bzip2 and gzip compression).</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">tarsum &lt; sometarfile.tar.gz &gt; sometarfile.tar.gz.md5</pre></div></div>

<p>Performance-wise, according to some tests I&#8217;ve carried out, the new version is faster with big tar files than the old one, but it&#8217;s the other way around with small archives (which I find less important).</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Copyright (C) 2008-2009 by Guy Rutenberg</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This program is free software; you can redistribute it and/or modify</span>
<span style="color: #808080; font-style: italic;"># it under the terms of the GNU General Public License as published by</span>
<span style="color: #808080; font-style: italic;"># the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #808080; font-style: italic;"># (at your option) any later version.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># This program is distributed in the hope that it will be useful,</span>
<span style="color: #808080; font-style: italic;"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #808080; font-style: italic;"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #808080; font-style: italic;"># GNU General Public License for more details.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># You should have received a copy of the GNU General Public License</span>
<span style="color: #808080; font-style: italic;"># along with this program; if not, write to the</span>
<span style="color: #808080; font-style: italic;"># Free Software Foundation, Inc.,</span>
<span style="color: #808080; font-style: italic;"># 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">tarfile</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> tarsum<span style="color: black;">&#40;</span>input_file, <span style="color: #008000;">hash</span>, output_file<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        input_file  - A FILE object to read the tar file from.
        hash - The name of the hash to use. Must be supported by hashlib.
        output_file - A FILE to write the computed signatures to.
        &quot;&quot;&quot;</span>
        tar = <span style="color: #dc143c;">tarfile</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>mode=<span style="color: #483d8b;">&quot;r|*&quot;</span>, fileobj=input_file<span style="color: black;">&#41;</span>
&nbsp;
        chunk_size = <span style="color: #ff4500;">100</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">1024</span>
        store_digests = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> member <span style="color: #ff7700;font-weight:bold;">in</span> tar:
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> member.<span style="color: black;">isfile</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">continue</span>
            f = tar.<span style="color: black;">extractfile</span><span style="color: black;">&#40;</span>member<span style="color: black;">&#41;</span>
            h = hashlib.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span><span style="color: #008000;">hash</span><span style="color: black;">&#41;</span>
            data = f.<span style="color: black;">read</span><span style="color: black;">&#40;</span>chunk_size<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">while</span> data:
                h.<span style="color: black;">update</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
                data = f.<span style="color: black;">read</span><span style="color: black;">&#40;</span>chunk_size<span style="color: black;">&#41;</span>
            output_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s  %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>h.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, member.<span style="color: black;">name</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</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: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    version=<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%prog 0.2.1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
             <span style="color: #483d8b;">&quot;Copyright (C) 2008-2009 Guy Rutenberg &lt;http://www.guyrutenberg.com/contact-me&gt;&quot;</span><span style="color: black;">&#41;</span>
    usage=<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%prog [options] TARFILE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
           <span style="color: #483d8b;">&quot;Print a checksum signature for every file in TARFILE.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
           <span style="color: #483d8b;">&quot;With no FILE, or when FILE is -, read standard input.&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span>usage=usage, version=version<span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-c&quot;</span>, <span style="color: #483d8b;">&quot;--checksum&quot;</span>, dest=<span style="color: #483d8b;">&quot;checksum&quot;</span>, <span style="color: #008000;">type</span>=<span style="color: #483d8b;">&quot;string&quot;</span>,
        <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;use HASH as for caclculating the checksums. [default: %default]&quot;</span>, metavar=<span style="color: #483d8b;">&quot;HASH&quot;</span>,
        default=<span style="color: #483d8b;">&quot;md5&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-o&quot;</span>, <span style="color: #483d8b;">&quot;--output&quot;</span>, dest=<span style="color: #483d8b;">&quot;output&quot;</span>, <span style="color: #008000;">type</span>=<span style="color: #483d8b;">&quot;string&quot;</span>,
        <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;save signatures to FILE.&quot;</span>, metavar=<span style="color: #483d8b;">&quot;FILE&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: black;">&#40;</span>option, args<span style="color: black;">&#41;</span> = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    output_file = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> option.<span style="color: black;">output</span>:
        output_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>option.<span style="color: black;">output</span>, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    input_file = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span>==<span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">and</span> args<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">!</span>=<span style="color: #483d8b;">&quot;-&quot;</span>:
        input_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    tarsum<span style="color: black;">&#40;</span>input_file, option.<span style="color: black;">checksum</span>, output_file<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">optparse</span> <span style="color: #ff7700;font-weight:bold;">import</span> OptionParser
    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># vim: ai ts=4 sts=4 et sw=4</span></pre></div></div>

<p>You can get a wget&#8217;able version here: <a href="/wp-content/uploads/2009/04/tarsum-0.2.bz2">tarsum-0.2.bz2</a>.</p>
<p><strong>Update 2009-08-12:</strong> Removed excess argument to <code>tarsum()</code> and switched the <code>filemode</code> to <code>r|*</code> (from <code>r:*</code>). Bumped version string.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/04/29/tarsum-02-a-read-only-version-of-tarsum/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>InfiniteTTT 0.6 Released</title>
		<link>http://www.guyrutenberg.com/2008/11/22/infinitettt-06-released/</link>
		<comments>http://www.guyrutenberg.com/2008/11/22/infinitettt-06-released/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 08:55:53 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[InfiniteTTT]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=166</guid>
		<description><![CDATA[InfiniteTTT 0.6 was released today. The main change in the new version is that the game is now multi-threaded.
InfiniteTTT is a variation of Tic-Tac-Toe which is played on an infinite board.
The new version has new multi-threaded AI engine, and several minor fixes and improvements. The changes improved the user experience and made the game more [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/infinitettt">InfiniteTTT</a> 0.6 was released today. The main change in the new version is that the game is now multi-threaded.</p>
<p><a href="/infinitettt">InfiniteTTT</a> is a variation of Tic-Tac-Toe which is played on an infinite board.</p>
<p>The new version has new multi-threaded AI engine, and several minor fixes and improvements. The changes improved the user experience and made the game more responsive. The new release contains binaries for Windows, source package and a Gentoo ebuild. Packages for other Linux distributions will follow soon (help will be appreciated).</p>
<p>To download the new version visit <a href="http://www.guyrutenberg.com/infinitettt/#download">InfiniteTTT&#8217;s download</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/11/22/infinitettt-06-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tarsum &#8211; Calculate Checksum for Files inside Tar Archive</title>
		<link>http://www.guyrutenberg.com/2008/10/24/tarsum-calculate-checksum-for-files-inside-tar-archive/</link>
		<comments>http://www.guyrutenberg.com/2008/10/24/tarsum-calculate-checksum-for-files-inside-tar-archive/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 20:02:05 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[tarsum]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=149</guid>
		<description><![CDATA[Update: I&#8217;ve released tarsum-0.2, a new version of tarsum.
Some time ago, I got back a hard disk back from data recovery. One of the annoying issues I encountered with the recovered data was corrupted files. Some files looked like they were recovered successfully but their content was corrupted. The ones that were configuration files, where [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update</b>: I&#8217;ve released <a href="/2009/04/29/tarsum-02-a-read-only-version-of-tarsum/">tarsum-0.2</a>, a new version of <code>tarsum</code>.</p>
<p>Some time ago, I got back a hard disk back from data recovery. One of the annoying issues I encountered with the recovered data was corrupted files. Some files looked like they were recovered successfully but their content was corrupted. The ones that were configuration files, where usually easy to detect, as it raised errors in programs that tried to use them. But when such error occurs in some general text file, (or inside the data of an SQL dump), the file may seem correctly fine unless closely inspected.</p>
<p>I have an habit of storing old backups on CDs (they are initially made to online storage), I do it in order to reduce backup costs. But the recovered/corrupted data issue raised some concerns about my ability to recover using this disks. Assuming that I have a disk failure, and I couldn&#8217;t recover from my online backups for reason, how can I check the integrity of my CD backups?</p>
<p>Only storing and comparing hash signature for the whole archive, is almost useless. It allows you to validate whether all the files are probably fine, but it can&#8217;t tell apart one corrupted file in the archive from a completed corrupted archive. My idea was to calculate checksum (hash) for each file in the data and store the signature in a way that would allow me to see which individual files are corrupted.</p>
<p>This is where <code>tarsum</code> comes to the rescue. As it&#8217;s name applies it calculate checksum for each file in the archive. You can download <code>tarsum</code> from <a href="/wp-content/uploads/2008/10/tarsum.gz">here</a>.</p>
<p>Using tarsum is pretty straight forward.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">tarsum backup.tar &gt; backup.tar.md5</pre></div></div>

<p>Calculates the MD5 checksums of the files. You can specify other hashes as well, by passing a tool that calculates it (it must work like <code>md5sum</code>).</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">tarsum --checksum=sha256sum backup.tar &gt; backup.tar.sha256</pre></div></div>

<p>To verify the integrity of the files inside the archive we use the <code>diff</code> command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">tarsum backup.tar | diff backup.tar.md5 -</pre></div></div>

<p>where <code>backup.tar.md5</code> is the original signature file we created. This is possible because the signatures are sorted alphabetically by the file name inside the archive, so it the order of the files is always the same.</p>
<p>Note that if you use an updated version of GNU tar, <code>tarsum</code> can also operate directly on compressed archives (e.g. tar.bz2, tar.gz).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/10/24/tarsum-calculate-checksum-for-files-inside-tar-archive/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.931 seconds -->
