<?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>Algorithm Blogs &#187; Miscellaneous</title>
	<atom:link href="http://www.algorithm.co.il/blogs/index.php/category/misc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.algorithm.co.il/blogs</link>
	<description>Algorithms, for the heck of it</description>
	<lastBuildDate>Thu, 22 Apr 2010 21:04:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>One-liner Guitar Tuner in Python</title>
		<link>http://www.algorithm.co.il/blogs/index.php/programming/python/one-liner-guitar-tuner-in-python/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/programming/python/one-liner-guitar-tuner-in-python/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 21:04:32 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[guitar]]></category>
		<category><![CDATA[guitar tuner]]></category>
		<category><![CDATA[one-liner]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=611</guid>
		<description><![CDATA[
On windows, assuming imports are free:


import winsound
winsound.Beep&#40;220*&#40;&#40;2**&#40;1/12.0&#41;&#41;**7&#41;, 2000&#41;



But that's just because I like to tune to E. If you prefer a more "natural looking" note, you can use A:


winsound.Beep&#40;110, 1000&#41;



But why choose at all when you can go for all of them?


&#91;winsound.Beep&#40;220*&#40;&#40;2**&#40;1/12.0&#41;&#41;**i&#41;, 500&#41; for i in &#91;7, 2, -2, -7, -12, -17&#93;&#93;



Image by Keela84
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.algorithm.co.il/sitecode/guitar.jpg" alt="Guitar" style="border: 2px solid black;"/></p>
<p>On windows, assuming imports are free:</p>
<div class="syntax_hilite">
<div id="python-4">
<div class="python"><span style="color: #00007f;font-weight:bold;">import</span> <span style="color: #dc143c;">winsound</span><br />
<span style="color: #dc143c;">winsound</span>.<span style="color: #000000;">Beep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">220</span>*<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>**<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>/<span style="color: #ff4500;">12</span>.<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>**<span style="color: #ff4500;">7</span><span style="color: black;">&#41;</span>, <span style="color: #ff4500;">2000</span><span style="color: black;">&#41;</span></div>
</div>
</div>
<p></p>
<p>But that's just because I like to tune to E. If you prefer a more "natural looking" note, you can use A:</p>
<div class="syntax_hilite">
<div id="python-5">
<div class="python"><span style="color: #dc143c;">winsound</span>.<span style="color: #000000;">Beep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">110</span>, <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span></div>
</div>
</div>
<p></p>
<p>But why choose at all when you can go for all of them?</p>
<div class="syntax_hilite">
<div id="python-6">
<div class="python"><span style="color: black;">&#91;</span><span style="color: #dc143c;">winsound</span>.<span style="color: #000000;">Beep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">220</span>*<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>**<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>/<span style="color: #ff4500;">12</span>.<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>**i<span style="color: black;">&#41;</span>, <span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span> <span style="color: #00007f;font-weight:bold;">for</span> i <span style="color: #00007f;font-weight:bold;">in</span> <span style="color: black;">&#91;</span><span style="color: #ff4500;">7</span>, <span style="color: #ff4500;">2</span>, -<span style="color: #ff4500;">2</span>, -<span style="color: #ff4500;">7</span>, -<span style="color: #ff4500;">12</span>, -<span style="color: #ff4500;">17</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span></div>
</div>
</div>
<p></p>
<p><small>Image by <a href="http://www.flickr.com/photos/keela84/8075445/">Keela84</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/programming/python/one-liner-guitar-tuner-in-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Call for Volunteers: Open Knesset &#8211; oknesset.org</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/call-for-volunteers-open-knesset-oknesset-org/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/call-for-volunteers-open-knesset-oknesset-org/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 20:05:10 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[open knesset]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=533</guid>
		<description><![CDATA[Over the last few weeks, I've been lightly involved in work on open knesset.
Mostly I've been helping two of the main developers, Benny and Ofri, and joining the discussions on the discussion group.
(For the non-Israelis: the Knesset is Israel's congress, where laws are passed.)
The website's mission is to improve Israeli citizens' involvement in our democracy, [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few weeks, I've been lightly involved in work on <a href="http://oknesset.org/">open knesset</a>.<br />
Mostly I've been helping two of the main developers, <a href="http://twitter.com/daonb">Benny</a> and <a href="http://twitter.com/ofri">Ofri</a>, and joining the discussions on the <a href="http://groups.google.com/group/open-knesset/">discussion group</a>.</p>
<p>(For the non-Israelis: <a href="http://en.wikipedia.org/wiki/Knesset">the Knesset</a> is Israel's congress, where laws are passed.)</p>
<p>The website's mission is to improve Israeli citizens' involvement in our democracy, and the first step in doing so is giving people more information. Ever wanted to know who keeps his promises? Who voted how? Who never votes? Which Member of Knesset is never present in discussions and votes? </p>
<p>Open Knesset is the place to put this information. If you know a bit of Python &#038; Django, you can join development either on the content harvesting front, or on the front-end front (pun not intended :).</p>
<p>"What about algorithms?" you may ask, or "what does this project has to do with algorithm.co.il?". Well, there's also plenty of room for innovation and interesting features. For example, finding the correlation between Members of Knesset that always vote together. Knowing which vote is for which law. Understanding if the vote is for or against that law. Plotting the party graph, and working with it. These are all things that still need to be done. See <a href="http://wiki.hamakor.org.il/index.php/Open-Knesset/%D7%AA%D7%A6%D7%95%D7%92%D7%95%D7%AA">these graphical examples</a> to see what I'm talking about.</p>
<p>The website is still in its infancy, but it already has lots of content and lots of features. Nevertheless, it still needs more work.<br />
If you're looking for an open-source project where your work will have great impact, this might just be it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/call-for-volunteers-open-knesset-oknesset-org/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>And now for something completely different</title>
		<link>http://www.algorithm.co.il/blogs/index.php/programming/python/and-now-for-something-completely-different/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/programming/python/and-now-for-something-completely-different/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 18:28:42 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Humour]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[clip]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[python zen]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=484</guid>
		<description><![CDATA[My friend Yuval whom you might already know from the comments here, apparently composed music for the Python Zen. It made me laugh today, and as it's been a long day, I thought it's worth sharing here. Especially as it is Python related.

]]></description>
			<content:encoded><![CDATA[<p>My friend <a href="http://uberpython.wordpress.com/">Yuval</a> whom you might already know from the comments here, apparently composed music for the <a href="http://www.python.org/dev/peps/pep-0020/">Python Zen</a>. It made me laugh today, and as it's been a long day, I thought it's worth sharing here. Especially as it is Python related.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/kYB72Qa6F9I&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/kYB72Qa6F9I&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/programming/python/and-now-for-something-completely-different/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PNG Minification</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/png-minification/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/png-minification/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 13:02:00 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[web-design]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[web-site optimization]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=351</guid>
		<description><![CDATA[Following Ned Batchelder's advice I've used pngout to minify the png's on my startup's web page.
It took them down from 641,281 bytes to 338,705. This is quite a nice return for the effort of a download and a single command line:
for %i in (*.png) do pngout "%i"

]]></description>
			<content:encoded><![CDATA[<p>Following <a href="http://nedbatchelder.com/blog/200908/png_optimization.html">Ned Batchelder's advice</a> I've used <a href="http://advsys.net/ken/utils.htm">pngout</a> to minify the png's on my startup's web page.</p>
<p>It took them down from 641,281 bytes to 338,705. This is quite a nice return for the effort of a download and a single command line:</p>
<blockquote><p>for %i in (*.png) do pngout "%i"
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/png-minification/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A New Kind of Journalism and Citizen Involvement</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/a-new-kind-of-journalism-and-citizen-involvement/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/a-new-kind-of-journalism-and-citizen-involvement/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 23:34:24 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Journalism]]></category>
		<category><![CDATA[Law]]></category>
		<category><![CDATA[שי דרומי]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=279</guid>
		<description><![CDATA[It's become a fashion of late to write about the effect the Internet had on journalism, and the way people get informed. Usually the discussion revolves around blogs, twitter, how the newspapers are dying, and so on.
I'd like to point out something different that I've observed of late.
It started a few weeks ago, with the [...]]]></description>
			<content:encoded><![CDATA[<p>It's become a fashion of late to write about the effect the Internet had on journalism, and the way people get informed. Usually the discussion revolves around blogs, twitter, how the newspapers are dying, and so on.</p>
<p>I'd like to point out something different that I've observed of late.</p>
<p>It started a few weeks ago, with the story of <a href="http://www.ynet.co.il/articles/0,7340,L-3735903,00.html">judge Drori</a>. He acquitted a man who ran over a the clerk at the parking lot, because she refused to let him leave without paying, and stood in the way of his car. After reading the story, and the actual court ruling, there was a public outrage. Judge Drori wrote a ruling of about 300 pages, where he explains the acquittal. Many people commented about the ruling itself, its length, the reasons given in it and so on.</p>
<p>The second story is about the farmer Shay Dromi, who was <a href="http://www.ynet.co.il/articles/0,7340,L-3746751,00.html">acquitted today</a> of killing. Two years ago, two Bedouin burglers broke into his farm at night, poisoned his dog, and then went about their business of stealing his property. At least they would have had Dromi hadn't noticed them, confronted them, shot one to death, and wounded the other. This was amid a wave of crime and break-ins at the area, while the police weren't doing much to stop that wave. As I said, Dromi was acquitted, the ruling was also published, and many people commented on the subject.</p>
<p>Now we can get to the point: usually, acquittals or convictions of the "small" people don't merit much press. Judge Drori's ruling probably would not have reached that publicity if he wasn't up for a seat at the supreme court. Dromi's story was publicized heavily a few years back, and the Knesset even changed the self-defense law because of this case.<br />
However, the publishing of full-text rulings is new. Except for a case I was personally involved in, I never read court rulings. I don't really know a lot about law. </p>
<p>Having these two stories published online, and not only in print, allows publishers to link to the full rulings. Newspapers will never come 300 attached pages of dense law text.<br />
Yet online it's easy as creating a link - and just like that, you have citizens reading rulings, understanding court processes, having opinions, commenting, and getting involved.</p>
<p>I find this amazing, and it makes me optimistic. The times are a-changing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/a-new-kind-of-journalism-and-citizen-involvement/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Must Have Python Packages</title>
		<link>http://www.algorithm.co.il/blogs/index.php/programming/python/must-have-python-packages/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/programming/python/must-have-python-packages/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 17:22:02 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Python packages]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=125</guid>
		<description><![CDATA[Python 2.6 and 3.0 are upon us.
I helped a friend set up the new Python environment for research and development, and we thought about constructing a PythonPack: a compilation of packages every home should have lying around.

I decided I'd write down my list of generic Python packages: packages you'd want to have regardless of what [...]]]></description>
			<content:encoded><![CDATA[<p>Python 2.6 and 3.0 are upon us.<br />
I helped a friend set up the new Python environment for research and development, and we thought about constructing a PythonPack: a compilation of packages every home should have lying around.<br />
<span id="more-125"></span><br />
I decided I'd write down my list of generic Python packages: packages you'd want to have regardless of what you were working on. So I didn't include any of the numerous web-development platforms, or some other very specialized packages.</p>
<p>What you won't see in this list however, are IDE's and editors. I don't feel like joining in on the religious wars just yet :)</p>
<p>So without further ado, here's my list:</p>
<ul>
<li><a href="http://ipython.scipy.org/moin/">IPython</a> - I just can't stress enough how useful this tool is. If you ever worked with Python's interactive prompt, this is the same thing, just on steroids. It has completion, history, shell capabilities, you name it. If you didn't yet work interactively, you won't do badly to start with IPython.</li>
<li><a href="http://www.activestate.com/Products/activepython/index.mhtml">ActiveState Python</a>, or the <a href="http://sourceforge.net/projects/pywin32/">win32 python extensions</a> - if you're developing on win32, it will allow you to get at the native win32 API, which I usually found as a blessing</li>
<li><a href="http://www.pygame.org/news.html">PyGame</a> - If you want to start game development on Python, that's the tool for you. Even if you don't, I found out I've used PyGame many times just for quick and dirty visualizations. Besides, it makes for a nice toy :)</li>
<li><a href="http://numpy.scipy.org/">numpy</a> - Ever needed to do any computation that's a bit more complicated than 1/(1-math.sin(x))**2? numpy is the way to go, with plenty of tools for vectors, matrices, and what not.</li>
<li>After mentioning numpy, it's important to mention <a href="http://www.scipy.org/">scipy</a> and <a href="http://matplotlib.sourceforge.net/">pylab (matplotlib)</a>. Just a bit of visualization strength, in the vein of matlab.</li>
<li><a href="http://nedbatchelder.com/code/modules/coverage.html">coverage.py</a> - Python code coverage by Ned Batchelder. An essential tool for effective testing. While you're there I'll also recommend checking out his <a href="http://nedbatchelder.com/blog/index.html">blog</a>.</li>
<li><a href="http://www.dabeaz.com/ply/">ply</a> - for most of your text parsing needs. Of course, this is just my preference. I heard about (but didn't use) PyParsing and other modules</li>
<li><a href="http://construct.wikispaces.com/">construct</a> - If you intend to do some binary parsing, construct is an excellent tool for that.</li>
<li><a href="http://pyopengl.sourceforge.net/">PyOpenGL</a> - I use it mostly for 3D visualizations, see for example my <a href="http://www.algorithm.co.il/blogs/index.php/programming/python/fractals-in-10-minutes-no-2-recursive-spring/">recursive spring</a>.</li>
<li><a href="http://www.pythonware.com/products/pil/">PIL</a> - Python Imaging Library is a very useful tool for working with images. I used it in my <a href="http://www.algorithm.co.il/blogs/index.php/programming/python/fractals-in-10-minutes-no-3-the-dragon/">twindragon fractal implementation</a></li>
<li><a href="http://www.nltk.org/">nltk</a> - Natural Language Toolkit - I realize most people won't be using this one, but it's generic enough, and I've used it enough times so far to include it in here. For example, I used it when I wanted to <a href="http://www.algorithm.co.il/blogs/index.php/programming/python/rhyme-and-reason-with-python/">find rhymes</a>.</li>
<li><a href="http://winpdb.org/">WinPDB</a> - A Python debugger especially useful for embedded Python apps (Python running from within another application).</li>
<li><a href="http://code.google.com/p/python-nose/">nose</a> - the framework I use for testing. Easy to start using it if you're already using unittest.</li>
<li><a href="http://psyco.sourceforge.net/">psyco</a> - if it so happens that you start to care about speed, psyco is by far the easiest way to go about doing it, short of writing your code in a different language.</li>
</ul>
<p>Other useful but less often used packages include:</p>
<ul>
<li><a href="http://dkbza.org/pefile.html">pefile</a> - for parsing win32 pe files.</li>
<li>PyDBG (from within <a href="http://www.openrce.org/downloads/details/208/PaiMei">PaiMei</a>) - an interace to the win32 debugging api (there's an upcoming post about that one :)</li>
<li><a href="http://www.secdev.org/projects/scapy/">scapy</a> - I didn't use it lately, but if you want to sniff packets programmatically, that's a good way to go about doing that</li>
<li><a href="http://sourceforge.net/project/showfiles.php?group_id=149840">Peach</a> - Easy Python tool for fuzzing. Didn't get the chance to use it myself though.</li>
<li><a href="http://www.ragestorm.net/distorm/">diStorm</a> - the fastest disassembler for x86 and amd64 around, with a Python interface. Of course, it helps if I'm also working with gil on the <a href="http://www.algorithm.co.il/blogs/index.php/tag/vial/">next version</a> :)</li>
<li><a href="http://www.sqlalchemy.org/">sqlalchemy</a> and <a href="http://www.sqlobject.org/">sqlobject</a> - your handy ORMs. I use them mostly for web development. For other work I don't often need a full blown db.</li>
<li><a href="http://wxpython.org/">wx</a> and <a href="http://www.pygtk.org/">PyGTK</a>- I really don't do that much GUI work, so I don't have really much to say about those two. I still have them lying around though, just in case.</li>
<li><a href="http://rpyc.wikidot.com/">RPyC</a> - Didn't get a chance to use it myself, but if you want to get into distributed Python programming, I'll look into RPyC first.</li>
<li><a href="http://networkx.lanl.gov/">NetworkX</a> - if you happen to need some graph algorithm or visualization, I'd go for networkx. Last time I used graphs I mostly wrote my own code, and discovered networkx only afterwards. Next time I'll be sure to use it.</li>
<li><a href="http://code.google.com/p/sympy/">SymPy</a> - Symbolic Python, in the vein of Maple and Mathematica. It allows you to do symbolic operations for example, integrating f(x)=sin(x) and still getting a function and not a number. I used it a little bit for my homework.</li>
</ul>
<p>Now it's your turn: what packages did I miss? </p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/programming/python/must-have-python-packages/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>My Bad Memory, High Load, and Python</title>
		<link>http://www.algorithm.co.il/blogs/index.php/programming/python/my-bad-memory-high-load-and-python/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/programming/python/my-bad-memory-high-load-and-python/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 09:57:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Computer trouble]]></category>
		<category><![CDATA[High Load]]></category>
		<category><![CDATA[memtest]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Voodoo]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/?p=109</guid>
		<description><![CDATA[About a month ago the new Ubuntu 8.04 was released and I wanted a clean install. I downloaded an image and burned it to a CD. Just before installing, I tried "check CD for defects" and found a few. Turns out (*) this was because of bad memory - and memtest confirmed it.
So I went [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago the new Ubuntu 8.04 was released and I wanted a clean install. I downloaded an image and burned it to a CD. Just before installing, I tried "check CD for defects" and found a few. Turns out (*) this was because of bad memory - and <a href="http://www.memtest.org/">memtest</a> confirmed it.<br />
So I went to the shop, replaced the bad memory, and also bought two new sticks. I went home to install the new Ubuntu, and after the installation, Firefox crashed. After rebooting back to memtest, I saw this:</p>
<p><a href="http://www.algorithm.co.il/sitecode/bad_memtest.jpg"><img src="http://www.algorithm.co.il/sitecode/bad_memtest.jpg" alt="memory errors in memtest" border="2" width="200"/></a></p>
<p>Back at the computer shop, they asked me to reproduce the errors. Just firing up the computer and booting directly into memtest didn't seem to do the trick, so I suspected that I had to overwork my computer a bit to reproduce this.</p>
<p>Since I was at the lab, I didn't want to muck around too much.<br />
So I thought, "what's the quickest way to give your CPU a run around the block?"<br />
That's right - a tight loop:</p>
<div class="syntax_hilite">
<div id="python-11">
<div class="python"><span style="color: #00007f;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:<br />
&nbsp; &nbsp; <span style="color: #00007f;font-weight:bold;">pass</span></div>
</div>
</div>
<p>
However, this snippet doesn't really play with the memory.</p>
<p>The next simplest thing to do, that also jiggles some ram is the following (and one of my favorites):</p>
<div class="syntax_hilite">
<div id="python-12">
<div class="python">In <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>: x = <span style="color: #ff4500;">4</span>**<span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>**<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><br />
In <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>: y = <span style="color: #ff4500;">4</span>**x</div>
</div>
</div>
<p>
I will talk about this peculiar piece of code at a later post.</p>
<p>In any case, this snippet also didn't reproduce the error. It is also quite unwieldy, as it raises a MemoryError after some time. Later at home I tried two more scripts.<br />
The first is a variation on the one above:</p>
<div class="syntax_hilite">
<div id="python-13">
<div class="python">x = <span style="color: #ff4500;">4</span>**<span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>**<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><br />
<span style="color: #00007f;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:<br />
&nbsp; &nbsp; <span style="color: #00007f;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; y = <span style="color: #ff4500;">4</span>**x<br />
&nbsp; &nbsp; <span style="color: #00007f;font-weight:bold;">except</span> <span style="color: #008000;">MemoryError</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;font-weight:bold;">pass</span></div>
</div>
</div>
<p>
I ran a few of those in parallel. However, my Ubuntu machine actually killed the processes running this one by one.</p>
<p>The second is smarter. It allocates some memory and then just copies it around:</p>
<div class="syntax_hilite">
<div id="python-14">
<div class="python"><span style="color: #00007f;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #00007f;font-weight:bold;">import</span> <span style="color: #dc143c;">copy</span><br />
megabytes = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: #000000;">argv</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></p>
<p>x1 = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">"a"</span>*<span style="color: #ff4500;">1000</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> <span style="color: #00007f;font-weight:bold;">for</span> i <span style="color: #00007f;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #00007f;font-weight:bold;">for</span> j <span style="color: #00007f;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>megabytes<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
<span style="color: #00007f;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:<br />
&nbsp; &nbsp; x2 = <span style="color: #dc143c;">copy</span>.<span style="color: #000000;">deepcopy</span><span style="color: black;">&#40;</span>x1<span style="color: black;">&#41;</span></div>
</div>
</div>
<p></p>
<p>After both of these scripts didn't reproduce the problem and it still persisted arbitrarily, I returned the computer to the lab. Turns out that the two replacement sticks and the two new sticks weren't exactly identical, and that was the cause of the problem. So now my memory is well again.</p>
<p>As for the scripts above, I once wrote a similar script at work. I was asked to help with testing some software in some stress testing. The goal was to simulate a heavily used computer. A few lines of Python later and the testing environment was ready.</p>
<p>Footnotes:<br />
(*) - Finding out that it was a memory issue wasn't as easy as it sounds. I didn't think of running memtest. I checked the image on my HD with md5, and the hash didn't match. I downloaded a second image, and again the hash didn't match. I checked twice.<br />
At this point I was really surprised: not only the second check didn't match the published md5, it also didn't match the first check. Some hours and plenty of voodoo later, a friend suggested running memtest, and the culprit was found.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/programming/python/my-bad-memory-high-load-and-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Breaking Rapidshare&#8217;s Annoying Captcha the Easy Way</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/breaking-rapidshares-annoying-captcha-the-easy-way/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/breaking-rapidshares-annoying-captcha-the-easy-way/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 19:54:50 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Programming Philosophy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[web-design]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[rapidshare]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/index.php/misc/breaking-rapidshares-annoying-captcha-the-easy-way/</guid>
		<description><![CDATA[Like many others, I got stuck in front of Rapidshare's captcha. After more than five attempts at reading different letters with kittens and other critters hidden behind them, I was thinking of giving up. Especially because each time I failed I had to wait a half a minute again. However,  in one instance I [...]]]></description>
			<content:encoded><![CDATA[<p>Like <a href="http://depressedprogrammer.wordpress.com/2008/04/20/worst-captcha-ever/">many</a> <a href="http://allstrox.visualserver.org/blog/?p=29">others</a>, I got stuck in front of Rapidshare's captcha. After more than five attempts at reading different letters with kittens and other critters hidden behind them, I was thinking of giving up. Especially because each time I failed I had to wait a half a minute again. However,  in one instance I went *back* via my browser, and tried solving the same captcha again. Turns out this works, and I got the file.</p>
<p>I know I could probably have solved it in a smarter fashion, but it wasn't worth the effort.</p>
<p>My lesson:</p>
<blockquote><p>When someone writes crappy software, their software is probably crappy in more than one way.</p></blockquote>
<p>This is not the first time I've seen this happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/breaking-rapidshares-annoying-captcha-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Short Story: First Hit, Last Hit</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/short-story-first-hit-last-hit/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/short-story-first-hit-last-hit/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 08:52:13 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[bionic man]]></category>
		<category><![CDATA[ransomware]]></category>
		<category><![CDATA[science fiction]]></category>
		<category><![CDATA[short story]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/index.php/misc/short-story-first-hit-last-hit/</guid>
		<description><![CDATA[I decided to try something a little bit different, and publish a short story I wrote. I'll be glad to read any comments you might have on the subject, or the story itself. I might upload some more stories to the blog, but I'll try to keep them technology-related.
Here's the link to the story.
I actually [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to try something a little bit different, and publish a short story I wrote. I'll be glad to read any comments you might have on the subject, or the story itself. I might upload some more stories to the blog, but I'll try to keep them technology-related.</p>
<p><a href="http://www.algorithm.co.il/sitecode/last_hit_first_hit.pdf">Here's the link to the story.</a></p>
<p>I actually wrote this one about a year ago, when I was discussing with Gadi his <a href="http://events.ccc.de/camp/2007/Fahrplan/events/2049.en.html">lecture on the bionic man</a>. I thought the subject has a lot of room to play and a lot of security implications to consider. Some of our ideas became a reality when researchers <a href="http://www.nytimes.com/2008/03/12/business/12heart-web.html">managed to hack into a pace-maker</a>. </p>
<p>Well, I hope this short story never comes true.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/short-story-first-hit-last-hit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Back From the Dead</title>
		<link>http://www.algorithm.co.il/blogs/index.php/misc/back-from-the-dead/</link>
		<comments>http://www.algorithm.co.il/blogs/index.php/misc/back-from-the-dead/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 09:46:24 +0000</pubDate>
		<dc:creator>lorg</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Origami]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[Origami Flier]]></category>

		<guid isPermaLink="false">http://www.algorithm.co.il/blogs/index.php/misc/back-from-the-dead/</guid>
		<description><![CDATA[As you can see, the website is back online, and I hope it stays that way.
Cheers go to Randy and James, for fixing the server.
I've been doing various things lately, including work on Vial and various university tests. I'll be sure to write some more now that the website is back online, to make up [...]]]></description>
			<content:encoded><![CDATA[<p>As you can see, the website is back online, and I hope it stays that way.<br />
Cheers go to Randy and James, for fixing the server.</p>
<p>I've been doing various things lately, including work on Vial and various university tests. I'll be sure to write some more now that the website is back online, to make up for the lost time.</p>
<p>I also had a job interview in Tel Aviv a few days ago. Here's a little critter I folded on the train (click for larger images):</p>
<p><a href="http://www.algorithm.co.il/origami/misc/flier_2.jpg" border="2"><img border="2" src="http://www.algorithm.co.il/origami/misc/flier_2.jpg" align="left" width="133" height="100" alt="Origami Flier" /></a><a href="http://www.algorithm.co.il/origami/misc/flier_4.jpg" border="2"><img src="http://www.algorithm.co.il/origami/misc/flier_4.jpg" aligh="right" width="133" height="100" border="2" alt="Origami Flier" /></a></p>
<p>This one is made from a square piece of paper, and it has 6 legs. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm.co.il/blogs/index.php/misc/back-from-the-dead/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
