<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>I’m a software engineer working mainly in Python. My homepage is at amir.rachum.com.

Follow me on Twitter: @AmirRachum</description><title>Amir Rachum</title><generator>Tumblr (3.0; @nurdok)</generator><link>http://blog.amir.rachum.com/</link><item><title>Using 'screen' - The Absolute Essentials</title><description>&lt;p&gt;You&amp;#8217;re probably here because you heard screen is a more &amp;#8220;safe&amp;#8221; way to ssh, so that a broken connection won&amp;#8217;t terminate your processes. Here&amp;#8217;s how to do it:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-html"&gt;sudo apt-get install screen&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Initial connection&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ ssh rachum@server&lt;br/&gt;$ screen&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Reconnection&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-html"&gt;$ ssh rachum@server&lt;br/&gt;$ screen -ls&lt;br/&gt;There is a screen on:&lt;br/&gt;    6786.pts-0.ubuntu	(05/10/2013 09:42:11 AM)	(Detached)&lt;br/&gt;1 Socket in /var/run/screen/S-rachum.&lt;br/&gt;$ screen -r 6786.pts-0.ubuntu&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;#8230; And that&amp;#8217;s all you need to know to get something out of &lt;code&gt;screen&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;So what is this about? If you take a look at &lt;span&gt;screen&lt;/span&gt;&amp;#8217;s man pages you&amp;#8217;ll read that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Which is true, but not very helpful. While you may use &lt;span&gt;screen&lt;/span&gt;&amp;#8217;s multiplexing-window-managing features, you most likely came across it while looking for a way to ssh to some machine and run something that won&amp;#8217;t die when you disconnect. Multiplexing comes later. If you&amp;#8217;re interested in screen&amp;#8217;s more advanced features, &lt;a href="http://kb.iu.edu/data/acuy.html"&gt;check&lt;/a&gt; &lt;a href="http://www.thegeekstuff.com/2010/07/screen-command-examples/"&gt;out&lt;/a&gt; &lt;a href="http://www.computerhope.com/unix/screen.htm"&gt;some&lt;/a&gt; &lt;a href="http://www.ibm.com/developerworks/aix/library/au-gnu_screen/"&gt;of&lt;/a&gt; &lt;a href="http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/"&gt;these&lt;/a&gt; &lt;a href="http://www.howtoforge.com/linux_screen"&gt;guides&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/50076409920</link><guid>http://blog.amir.rachum.com/post/50076409920</guid><pubDate>Fri, 10 May 2013 10:33:07 +0300</pubDate></item><item><title>My Licensing Wake-Up Call</title><description>&lt;p&gt;The other day I got an email that really hit me on the head. It was titled &amp;#8220;JOOLS, Y U NO SPECIFY A LICENSE?&amp;#8221; and here&amp;#8217;s how it read:&lt;/p&gt;
&lt;blockquote&gt;

&lt;div&gt;FYI, your Jools project on GitHub specifies no license.  It looks like you intend it to be Open Source or Public Domain, but without specifying a license explicitly, the license is &amp;#8220;all rights reserved, no reuse or redistribution allowed&amp;#8221;.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Though I don&amp;#8217;t mention the project or you by name, the lack of a license inspired this post:&lt;/div&gt;
&lt;div&gt;&lt;a href="http://goo.gl/GeVje" target="_blank"&gt;&lt;a href="http://goo.gl/GeVje"&gt;http://goo.gl/GeVje&lt;/a&gt;&lt;/a&gt;  ;-)&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;HTH,&lt;/div&gt;
&lt;div&gt;Jens Knutson&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div&gt;Harsh, but I know I had it coming. From time to time I hear about license X or license Y, or see a post on HN about which license to use, but I never paid much attention. Licensing is a problem for people with successful projects, I thought. Who has time? My job is to build stuff!&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Well, as it seems, &lt;em&gt;not specifying a license can mean failure for your project&lt;/em&gt;. I thanked Jens for his email - all the while thinking &lt;em&gt;how many people were in the same situation and &lt;strong&gt;didn&amp;#8217;t&lt;/strong&gt; send me an&lt;/em&gt; email? Oh man, This is bad.&lt;/div&gt;
&lt;div&gt;I went ahead and&lt;a href="https://github.com/Nurdok/Jools"&gt; put up a LICENSE file in my repository right away&lt;/a&gt; (I chose the &lt;a href="http://opensource.org/licenses/MIT"&gt;MIT license&lt;/a&gt;, for those interested).&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Don&amp;#8217;t let this happen to you. Got an open source project? License it &lt;strong&gt;today.&lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/50027662207</link><guid>http://blog.amir.rachum.com/post/50027662207</guid><pubDate>Thu, 09 May 2013 22:08:06 +0300</pubDate></item><item><title>Python: Number Conversion Chart</title><description>&lt;p&gt;Ever forget how to take a hex string like &amp;#8220;2D&amp;#8221; and convert it into binary data? Or how to parse an ascii-binary string like &amp;#8220;101101&amp;#8221; into a plain integer? Me too.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s why I crafted this table. It doens&amp;#8217;t include all conversion, but it includes every conversion type I know, and you can chain them to get from any source type to any destination.&lt;/p&gt;
&lt;p&gt;Every from/to cell assumes that the &amp;#8220;original&amp;#8221; integer is 45. Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/Nurdok/4096182" title="Python Number Conversion Chart" target="_blank"&gt;Number Conversion Chart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Python Posts&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/39501813266/python-the-dictionary-playbook"&gt;The Dictionary Playbook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/27860231695/what-else-is-there-in-python"&gt;What Else is There in Python?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/30176371115/you-cant-handle-the-truth"&gt;You Can&amp;#8217;t Handle the Truth!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.amir.rachum.com/post/48428590088</link><guid>http://blog.amir.rachum.com/post/48428590088</guid><pubDate>Sat, 20 Apr 2013 13:38:00 +0300</pubDate></item><item><title>Making History with Bash</title><description>&lt;p&gt;This is a nifty little trick for making Bash a little more intuitive (for my taste). Usually, when you press the up key, Bash will bring back the last command you typed. This is cool, but what bothers me is that sometimes I start typing a command and then remember I executed it before. So I press the up key and&amp;#8230; Bash shows me the last command, disregarding what I typed. What I want it to do is search history for things with the prefix I entered.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s what you do to achieve this. In your &lt;code&gt;inputrc&lt;/code&gt; file (&lt;code&gt;~/.inputrc&lt;/code&gt; for personal configuration, &lt;code&gt;/etc/inputrc&lt;/code&gt; file for global configuration), add the following lines:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;"\C-[OA": history-search-backward&lt;br/&gt;"\C-[[A": history-search-backward&lt;br/&gt;&lt;br/&gt;"\C-[OB": history-search-forward&lt;br/&gt;"\C-[[B": history-search-forward&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The weird symbols at the start of each line represent up/down arrow keys in keypad/ANSI modes. I wish Unix configurations would use proper readable symbols, but a man can only dream.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/40626432300</link><guid>http://blog.amir.rachum.com/post/40626432300</guid><pubDate>Tue, 15 Jan 2013 23:48:25 +0200</pubDate><category>bash</category><category>linux</category><category>unix</category></item><item><title>Moving Around with Bash</title><description>&lt;p&gt;Little things matter. I&amp;#8217;m often amazed of how I can feel I mastered a certain tool or technology, only to discover I&amp;#8217;ve missed some basic way of using it. It happened to me on Windows a couple of weeks ago when I discovered cool keyboard shortcuts, like Win+E (which opens My Computer), or on Eclipse when I found out &lt;a href="http://blog.amir.rachum.com/post/34835507709/eclipse-quick-access-how-did-i-miss-this"&gt;there is a menu that finds everything&lt;/a&gt;. On Linux, I&amp;#8217;ve found that this happens all the time. Now, finding out how to use &lt;code&gt;awk&lt;/code&gt; or &lt;code&gt;sed&lt;/code&gt; is one thing, and it requires learning a complicated tool. But there are a lot of little things that are so easy to pick up, that it&amp;#8217;s a shame that people miss them. Playing around with directories is so common in a Unix shell, and there are so many tricks you can use.&lt;/p&gt;
&lt;p&gt;The basic way of moving around is, of course, &lt;code&gt;cd path/to/dir&lt;/code&gt;. So far, so good. What more can you do?&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;You can go back to the last directory you were in by simply executing &lt;code&gt;cd -&lt;/code&gt;.&lt;br/&gt;&lt;pre&gt;&lt;code class="language-html"&gt;$ cd /usr/local/bin/&lt;br/&gt;$ pwd&lt;br/&gt;/usr/local/bin&lt;br/&gt;$ cd ~/projects/python_toolbox/&lt;br/&gt;$ cd -&lt;br/&gt;/usr/local/bin&lt;br/&gt;$ cd -&lt;br/&gt;/home/rachum/projects/python_toolbox&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;The previous point is mostly useful when you&amp;#8217;re jumping back and forth between two directories. Sometimes you&amp;#8217;re jumping between directory &lt;em&gt;A&lt;/em&gt; and directory &lt;em&gt;B&lt;/em&gt;, and while you&amp;#8217;re in &lt;em&gt;B&lt;/em&gt;, you &lt;code&gt;cd&lt;/code&gt; into some subdirectory, and poof, there goes your way to go back to &lt;em&gt;A&lt;/em&gt;. What you&amp;#8217;d really like is to tell Bash &amp;#8220;Remember this directory. I&amp;#8217;m going to go on a trip to &lt;em&gt;B&lt;/em&gt;, where I may travel in and out of subdirectories as I please, but eventually I want you to take me back here, to &lt;em&gt;A&lt;/em&gt;&amp;#8221;. Well wouldn&amp;#8217;t you know, there&amp;#8217;s a way to do that. But it gets better. You can do that to an unlimited amount of directories, each time remembering or going back to where you were. &lt;br/&gt;If this sounds like a stack of directories to you, you&amp;#8217;re right. The commands to do this are called &lt;code&gt;pushd&lt;/code&gt; and &lt;code&gt;popd&lt;/code&gt;. &lt;code&gt;pushd&lt;/code&gt; acts like &lt;code&gt;cd&lt;/code&gt;, in the way that it takes a directory name and changes your current directory to it, but it also remembers where you came from. The next time you use &lt;code&gt;popd&lt;/code&gt; it will take you back there. You can &lt;code&gt;pushd&lt;/code&gt; several times in a row, and each time, &lt;code&gt;popd&lt;/code&gt; will take you back one step. If you want to go back without taking the current directory out of the stack, you can do &lt;code&gt;pushd &lt;/code&gt;without parameters. 
&lt;pre&gt;&lt;code class="language-html"&gt;$ pwd&lt;br/&gt;/home/rachum/projects&lt;br/&gt;$ pushd ~/private_files/&lt;br/&gt;~/private_files ~/projects&lt;br/&gt;$ cd forbidden_dir/&lt;br/&gt;$ mkdir do_not_enter&lt;br/&gt;$ cd do_not_enter/&lt;br/&gt;$ echo "do some work" &amp;gt; work.txt&lt;br/&gt;$ popd&lt;br/&gt;~/projects&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;If you&amp;#8217;re like me, this happens to you ALL. THE. TIME.
&lt;pre&gt;&lt;code class="language-html"&gt; $ cd..&lt;br/&gt; cd..: command not found&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
Well, instead of beating yourself up about it, just fix it!
&lt;pre&gt;&lt;code class="language-html"&gt;$ alias cd..="cd .."&lt;br/&gt;$ pwd&lt;br/&gt;/home/rachum/projects&lt;br/&gt;$ cd..&lt;br/&gt;$ pwd&lt;br/&gt;/home/rachum&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
Or, even better, just do &lt;code class="language-html"&gt;alias ..="cd .."&lt;/code&gt;, so you can just type &lt;code&gt;..&lt;/code&gt; to go to the parent directory.&lt;/li&gt;
&lt;li&gt;This one isn&amp;#8217;t necessarily related to directories &lt;em&gt;per-se&lt;/em&gt;, but it seems like it belongs here. There&amp;#8217;s a really useful syntax in Unix shells which utilizes curly braces. It&amp;#8217;s a little bit difficult to put into words, so let&amp;#8217;s look at an example:
&lt;pre&gt;&lt;code&gt;$ echo {j,h}ello!&lt;br/&gt;jello! hello!&lt;/code&gt;&lt;/pre&gt;
Bash understands this line as two words, one with &amp;#8216;j&amp;#8217; and the other with &amp;#8216;h&amp;#8217;. The cool thing about this is that it also works with several braces in a single expression:
&lt;pre&gt;&lt;code&gt;$ echo {j,h}el{l,}o&lt;br/&gt;jello jelo hello helo&lt;/code&gt;&lt;/pre&gt;
Bash knows how to create every possible permutation of the word! Notice that it&amp;#8217;s possible to put in an &amp;#8220;empty&amp;#8221; option, and any number of options in the same braces:
&lt;pre&gt;&lt;code&gt;$ echo {j,h,m,}ello!&lt;br/&gt;jello! hello! mello! ello!&lt;/code&gt;&lt;/pre&gt;
You can think of all kinds of use cases where this is useful, but the one I use most often is when I want to rename a file. Usually it happens when I want to back up a file. I usually add a suffix to the file like so:
&lt;pre&gt;&lt;code&gt;$ cp my_precious_data.dat my_precious_data.dat.backup&lt;/code&gt;&lt;/pre&gt;
With curly braces, you can do it like this:
&lt;pre&gt;&lt;code&gt;$ cp my_precious_data.dat{,.backup}&lt;/code&gt;&lt;/pre&gt;
Of course, this works with any shell command:
&lt;pre&gt;&lt;code&gt;$ touch test_data{1,2,3}.csv&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Related Posts&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/23244871726/how-i-started-to-love-the-shell-and-why-powershell-is"&gt;How I Started to Love the Shell and Why PowerShell is Awesome&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/34835507709/eclipse-quick-access-how-did-i-miss-this"&gt;Eclipse Quick Access - How Did I Miss This?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.amir.rachum.com/post/39740385224</link><guid>http://blog.amir.rachum.com/post/39740385224</guid><pubDate>Sat, 05 Jan 2013 14:10:00 +0200</pubDate><category>bash</category><category>unix</category></item><item><title>Python: The Dictionary Playbook</title><description>&lt;p&gt;I so often come across various kinds of boilerplate code regarding dictionaries in Python, that I decided to show some of it here and share the more concise way of performing the same operations. &lt;br/&gt;Presenting: &lt;strong&gt;The Dictionary Playbook&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" height="352" src="http://images1.wikia.nocookie.net/__cb20101106160412/himym/images/8/81/The_playbook.png" width="625"/&gt;&lt;/p&gt;
&lt;h1&gt;&lt;!-- more --&gt;&lt;/h1&gt;
&lt;h1&gt;1. The &amp;#8220;Are You There?&amp;#8221;&lt;/h1&gt;
&lt;p&gt;This one is pretty simple, but I&amp;#8217;m amazed as to how it&amp;#8217;s missed - finding out if a key exists in the dictionary.&lt;/p&gt;
&lt;h4&gt;The Lame Version&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;dct.has_key(key)&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;The Python Way&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;key in dct&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;2. The &amp;#8220;Yoda Test&amp;#8221;&lt;/h1&gt;
&lt;p&gt;For those programmers who master the &amp;#8220;Are You There&amp;#8221; play, there&amp;#8217;s usually another simple, yet annoying behavior. It doesn&amp;#8217;t only apply to dicts, but it&amp;#8217;s very common.&lt;/p&gt;
&lt;h4&gt;Do This You Must Not&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;not key in dct&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;English, Do You Speak It?&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;key not in dct&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;3. The &amp;#8220;Get the Value Anyway&amp;#8221;&lt;/h1&gt;
&lt;p&gt;This one is really popular. You have a dictionary and a key, and you want to modify the key&amp;#8217;s value. For example, adding 1 to it (let&amp;#8217;s say you&amp;#8217;re counting something).&lt;/p&gt;
&lt;h4&gt;The Boilerplate&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;if key not in dct:&lt;br/&gt;    dct[key] = 0&lt;br/&gt;dct[key] = dct[key] + 1&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;The Awesome Way&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;dct[key] = dct.get(key, 0) + 1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;dct.get(key[, default])&lt;/code&gt; returns &lt;code&gt;dct[key]&lt;/code&gt; if it exists, and &lt;code&gt;default&lt;/code&gt; if not.&lt;/p&gt;
&lt;h4&gt;The Even More Awesome&lt;/h4&gt;
&lt;p&gt;If you&amp;#8217;re using Python 2.7 and you want to count up amounts of stuff, you can use &lt;code&gt;&lt;a href="http://docs.python.org/2/library/collections.html#collections.Counter"&gt;Counter&lt;/a&gt;.&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from collections import Counter&lt;br/&gt;&amp;gt;&amp;gt;&amp;gt; d = [1, 1, 1, 2, 2, 3, 1, 1]&lt;br/&gt;&amp;gt;&amp;gt;&amp;gt; Counter(d)&lt;br/&gt;Counter({1: 5, 2: 2, 3: 1})&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And here&amp;#8217;s a more complete example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; counter = Counter()&lt;br/&gt;... for _ in range(10):&lt;br/&gt;...     num = int(raw_input("Enter a number: "))&lt;br/&gt;...     counter.update([num]) &lt;br/&gt;...&lt;br/&gt;... for key, value in counter.iteritems():&lt;br/&gt;...     print "You have entered {}, {} times!".format(key, value) &lt;br/&gt;&lt;span class="nocode"&gt;Enter a number: 1&lt;br/&gt;Enter a number: 1&lt;br/&gt;Enter a number: 2&lt;br/&gt;Enter a number: 3&lt;br/&gt;Enter a number: 51&lt;br/&gt;Enter a number: 1&lt;br/&gt;Enter a number: 1&lt;br/&gt;Enter a number: 1&lt;br/&gt;Enter a number: 2&lt;br/&gt;Enter a number: 3&lt;br/&gt;You have entered 1, 5 times!&lt;br/&gt;You have entered 2, 2 times!&lt;br/&gt;You have entered 3, 2 times!&lt;br/&gt;You have entered 51, 1 times!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;h1&gt;4. The &amp;#8220;Make It Happen&amp;#8221;&lt;/h1&gt;
&lt;p&gt;Sometimes your dictionary contains mutable objects, and you want to initialize and modify them. Let&amp;#8217;s say you&amp;#8217;re sorting out some data into a dictionary where the values are lists (examples courtesy of &lt;a href="http://stackoverflow.com/a/3483652/166067"&gt;this answer in Stack Overflow&lt;/a&gt;)&lt;/p&gt;
&lt;h4&gt;Spelling It Out&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;dct = {} &lt;br/&gt;for (key, value) in data: &lt;br/&gt;    if key in dct: &lt;br/&gt;        dct[key].append(value) &lt;br/&gt;    else: &lt;br/&gt;        dct[key] = [value]&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Getting Down with the Python&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;dct = {} &lt;br/&gt;for (key, value) in data:&lt;br/&gt;    group = dct.setdefault(key, []) # key might exist already &lt;br/&gt;    group.append(value)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What &lt;code&gt;setdefault(key, default)&lt;/code&gt; does is returns &lt;code&gt;dct[key]&lt;/code&gt; if it exists, and if it doesn&amp;#8217;t - sets it to &lt;code&gt;default&lt;/code&gt; and returns it. Compared to &lt;code&gt;get&lt;/code&gt;, it&amp;#8217;s useful when the default value is an object you can modify, so you don&amp;#8217;t have to manually reinsert its modified version to the dictionary.&lt;/p&gt;
&lt;h4&gt;Rocking it Out&lt;/h4&gt;
&lt;pre&gt;&lt;code&gt;dct = defaultdict(list) &lt;br/&gt;for (key, value) in data: &lt;br/&gt;    dct[key].append(value) # all keys have a default already&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;defaultdict&lt;/code&gt; is pretty awesome. It&amp;#8217;s pretty self-explanatory - it&amp;#8217;s a dict with default values. This means that every access to a key in &lt;code&gt;dct&lt;/code&gt; that doesn&amp;#8217;t exist in the dictionary (that would usually raise a &lt;code&gt;KeyError&lt;/code&gt;) creates it with the default value. It&amp;#8217;s as if every access to &lt;code&gt;dct&lt;/code&gt; is done with &lt;code&gt;setdefault&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;One interesting use I&amp;#8217;ve found for &lt;code&gt;defaultdict&lt;/code&gt; is when implementing &lt;a href="http://en.wikipedia.org/wiki/Sparse_matrix"&gt;sparse data structures&lt;/a&gt;. You set &lt;code&gt;defaultdict&lt;/code&gt; to the default value and use coordinates (or whatever is applicable) as the key. I&amp;#8217;ve used this to represents multi-dimensional grids and it&amp;#8217;s definitely easier than using intricately wrapped lists. &lt;/p&gt;
&lt;p&gt;An even more interesting example of its use is the &lt;a href="https://gist.github.com/2012250"&gt;one-line tree definition&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Related Posts&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/27860231695/what-else-is-there-in-python"&gt;What else is there in Python?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/30176371115/you-cant-handle-the-truth"&gt;You Can&amp;#8217;t Handle the Truth!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.amir.rachum.com/post/28779584872/self-printing-programs-in-python"&gt;Self Printing Programs in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><link>http://blog.amir.rachum.com/post/39501813266</link><guid>http://blog.amir.rachum.com/post/39501813266</guid><pubDate>Wed, 02 Jan 2013 23:32:00 +0200</pubDate><category>python</category></item><item><title>Moving Changes to Feature Branches After-the-Fact in Mercurial</title><description>&lt;p&gt;At my workplace we use Mercurial. We don&amp;#8217;t usually work in feature-branches, but in the default branch instead. This is usually not problematic, but I keep running into the following situation: I started working on feature &lt;strong&gt;A&lt;/strong&gt; (on the default branch), when suddenly I am forced to work on (and ship) feature &lt;strong&gt;B&lt;/strong&gt; instead, for whatever reason. When that happens, I usually say to myself &amp;#8220;God damn it! I wish I worked on &lt;strong&gt;A&lt;/strong&gt; in a branch to begin with!&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Enter &lt;strong&gt;hg rebase. &lt;/strong&gt;Here&amp;#8217;s what you do.&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;First, let&amp;#8217;s create a small repo and work on some task:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg init repo &lt;br/&gt;$ cd repo/ &lt;br/&gt;$ touch readme &lt;br/&gt;$ hg add &lt;br/&gt;adding readme &lt;br/&gt;$ hg commit -m "add readme" &lt;br/&gt;$ echo "task 1" &amp;gt; task.txt &lt;br/&gt;$ hg add adding task.txt &lt;br/&gt;$ hg commit -m "work on task 1" &lt;br/&gt;$ echo "task 1" &amp;gt;&amp;gt; task.txt &lt;br/&gt;$ hg commit -m "work some more on task 1" &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s how our log looks like now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg log&lt;br/&gt;changeset: 2:729895012a70&lt;br/&gt;tag: tip&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:20:38 2012 -0800&lt;br/&gt;summary: work some more on task 1&lt;br/&gt;&lt;br/&gt;changeset: 1:f71e084223c8&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:20:15 2012 -0800&lt;br/&gt;summary: work on task 1&lt;br/&gt;&lt;br/&gt;changeset: 0:ac29a6da9b78&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:18:12 2012 -0800&lt;br/&gt;summary: add readme&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now let&amp;#8217;s say we didn&amp;#8217;t finish working on &lt;em&gt;task 1&lt;/em&gt; and for some reason we need to put it aside and start working on a different task. We want to move changesets 1 and 2 to a branch for a while. Here&amp;#8217;s how to do it:&lt;/p&gt;
&lt;p&gt;First, we need to create the branch we want to transfer them to, at the correct point (which is revision 0):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg update -r0&lt;br/&gt;0 files updated, 0 files merged, 1 files removed, 0 files unresolved&lt;br/&gt;$ hg branch task-1&lt;br/&gt;marked working directory as branch task-1&lt;br/&gt;(branches are permanent and global, did you want a bookmark?)&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we need to create an &amp;#8220;empty&amp;#8221; commit for the branch. This is needed because as of now the branch doesn&amp;#8217;t really exist and it needs to, for the &lt;code&gt;rebase&lt;/code&gt; command to work. If you want to transfer the commits to an existing branch (that has some commits already), you don&amp;#8217;t need this step.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg commit -m "created task-1 branch"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br/&gt;Now, all there&amp;#8217;s left is to perform the rebase command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg rebase --base 1 --dest 3&lt;br/&gt;saved backup bundle to /home/rachum/repo/.hg/strip-backup/f71e084223c8-backup.hg&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--dest&lt;/code&gt; option is where to &amp;#8220;stick&amp;#8221; the changesets and the &lt;code&gt;--base&lt;/code&gt; option defines the changesets that will be moved (it selects the first common ancestor with the revision specified in &lt;code&gt;--dest&lt;/code&gt;and downwards). Here&amp;#8217;s how our log looks like now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hg log&lt;br/&gt;changeset: 3:79318074f4a9&lt;br/&gt;branch: task-1&lt;br/&gt;tag: tip&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:20:38 2012 -0800&lt;br/&gt;summary: work some more on task 1&lt;br/&gt;&lt;br/&gt;changeset: 2:a9d9c50a1bdb&lt;br/&gt;branch: task-1&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:20:15 2012 -0800&lt;br/&gt;summary: work on task 1&lt;br/&gt;&lt;br/&gt;changeset: 1:25e0d60da309&lt;br/&gt;branch: task-1&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:23:07 2012 -0800&lt;br/&gt;summary: created task-1 branch&lt;br/&gt;&lt;br/&gt;changeset: 0:ac29a6da9b78&lt;br/&gt;user: nurdok&lt;br/&gt;date: Sun Dec 23 13:18:12 2012 -0800&lt;br/&gt;summary: add readme&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We stored task-1 away and we can start working on other stuff in the default branch.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/39140324119</link><guid>http://blog.amir.rachum.com/post/39140324119</guid><pubDate>Sat, 29 Dec 2012 20:18:00 +0200</pubDate><category>source-control</category><category>mercurial</category></item><item><title>Eclipse Quick Access - How Did I Miss this?</title><description>&lt;p&gt;I can&amp;#8217;t believe I&amp;#8217;ve been using Eclipse for - what? - 4 or 5 years now without using Quick Access.&lt;/p&gt;
&lt;p&gt;Sidebar - I&amp;#8217;ve long been promoting Eclipse&amp;#8217;s excellent menu search. It lets you search menu windows for each and every preference and value. For example, consider looking for how to enable print margin display (for keeping your code from exceeding 80 character rows; you do that, right?). Imagine sifting through this intricate hierarchy of menus:&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" height="392" src="http://i.imgur.com/1I8OC.png" width="658"/&gt;&lt;/p&gt;
&lt;p&gt;However, notice the search box on the upper left side. It allows you to search like so:&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" height="392" src="http://i.imgur.com/w0I8g.jpg" width="658"/&gt;&lt;/p&gt;
&lt;p&gt;Being such a promoter for this feature, I can&amp;#8217;t believe I missed Quick Access. Let me explain. You&amp;#8217;re working on some code, hacking away, and suddenly you need the PyUnit window thingy. Y&amp;#8217;know, this one:&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" height="247" src="http://i.imgur.com/Z8MTf.png" width="714"/&gt;&lt;/p&gt;
&lt;p&gt;You know what you want, but how do you open it? Window? Perspective? Views? If you aren&amp;#8217;t an Eclipse veteran you will probably be confused by the terminology, and all you want is to run some tests. Enter Quick Access. Quick Access is normally mapped to Ctrl+3. Press it and be amazed. You get a window with a search bar. Type something and get search results for practically everything in Eclipse. Let&amp;#8217;s try it with PyUnit:&lt;/p&gt;
&lt;p&gt;&lt;img alt="image" height="214" src="http://i.imgur.com/wDCUV.jpg" width="960"/&gt;&lt;/p&gt;
&lt;p&gt;You get search results for preferences, views, commands, open files, etc. &lt;a href="http://www.youtube.com/watch?v=fvDUx0fTnNg"&gt;It&amp;#8217;s the greatest thing since sliced bread&lt;/a&gt;. Thanks to &lt;a href="https://twitter.com/hannanaha"&gt;@hannanaha&lt;/a&gt; for pointing this one out.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/34835507709</link><guid>http://blog.amir.rachum.com/post/34835507709</guid><pubDate>Fri, 02 Nov 2012 18:32:00 +0200</pubDate><category>eclipse</category></item><item><title>Is it possible to be productive with only a smartphone? </title><description>&lt;p&gt;In the last month, I was in several situations where I was bored to death and had only my Android phone for amusement (Samsung Galaxy S2, for those wondering). I have the itch to program or do something productive in these situations, but for the life of me, I can&amp;#8217;t think of any such option and I usually end up playing a brain-numbing game instead. &lt;/p&gt;

&lt;p&gt;I am catching up on some reading in Hacker News, but when I have several hours to pass, it&amp;#8217;s just not enough. There&amp;#8217;s a new Github app out there, but my repositories don&amp;#8217;t have enough activity for me to do anything with it. I also didn&amp;#8217;t find any free Git client for the Android, so just getting my code is kind of a hassle. Same goes for a Python shell of some sort. &lt;/p&gt;

&lt;p&gt;So, the title of this post is an actual question on my part, not rhetorical: how do you stay productive on your phone?&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/31326074022</link><guid>http://blog.amir.rachum.com/post/31326074022</guid><pubDate>Tue, 11 Sep 2012 10:35:24 +0300</pubDate></item><item><title>Programming in The Zone</title><description>&lt;p&gt;A lot has been written about the concept of &lt;a href="http://en.wikipedia.org/wiki/Flow_(psychology)"&gt;flow&lt;/a&gt;, and I was well aware of this particular psychological mode way before I had a name for it. I like saying that I&amp;#8217;m &lt;em&gt;in the zone&lt;/em&gt;. In &lt;a href="http://www.imdb.com/title/tt1285016/"&gt;The Social Network&lt;/a&gt;, they refer to this state as being &lt;em&gt;wired in&lt;/em&gt;. The most interesting thing about the zone is, of course, how to get there. I can&amp;#8217;t really pinpoint the variables that help me get in the flow (possibly because when I&amp;#8217;m in it, I usually don&amp;#8217;t think about it), and Wikipedia agrees:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;One cannot force oneself to enter flow. It just happens. A flow state can be entered while performing any activity, although it is most likely to occur when one is wholeheartedly performing a task or activity for intrinsic purposes.&lt;/p&gt;
&lt;p&gt;There are three conditions that are necessary to achieve the flow state:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;One must be involved in an activity with a clear set of goals. This adds direction and structure to the task.&lt;/li&gt;
&lt;li&gt;One must have a good balance between the perceived challenges of the task at hand and his or her own perceived skills. One must have confidence that he or she is capable to do the task at hand.&lt;/li&gt;
&lt;li&gt;The task at hand must have clear and immediate feedback. This helps the person negotiate any changing demands and allows him or her to adjust his or her performance to maintain the flow state.&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;
&lt;p&gt;When I was reading this article, I simultaneously thought about how this translates to programming and I was surprised to see that every point mentioned very clearly suggests opinions I&amp;#8217;ve held strongly for quite some time. Here&amp;#8217;s what I came up with:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;em&gt;&amp;#8220;It is most likely to occur when one is wholeheartedly performing a task or activity for intrinsic purposes&amp;#8221; -&lt;/em&gt; good programmers love what they do. You can fake your way into mediocrity, but to reach the top, you&amp;#8217;ve got to care.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;#8220;One must be involved in an activity with a clear set of goals.&amp;#8221;&lt;/em&gt; - small programming cycles, consisting of well separated, well-formed tasks, as advocated by agile methodologies, are the most effective way to focus on what you&amp;#8217;re doing, do it well, and move from your finished task to the next one with ease.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;#8220;One must have confidence that he or she is capable to do the task at hand.&amp;#8221;&lt;/em&gt; - some people, and rightly so, are sometimes surprised by my hubris. While I try not to offend anyone, I believe that hubris is one of the &lt;a href="http://c2.com/cgi/wiki?LazinessImpatienceHubris"&gt;virtues of a good programmer&lt;/a&gt;. It&amp;#8217;s &lt;em&gt;the thing that makes you write programs to do something that&amp;#8217;s already been done, because you believe you can do it better.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;span&gt;&lt;em&gt;&amp;#8220;The task at hand must have clear and immediate feedback.&amp;#8221;&lt;/em&gt; - &lt;/span&gt;&lt;/em&gt;some more agile words of wisdom. To me, this translated directly as unit tests. I never work better than when I, in an obsessive-compulsive manner, run unit tests as often as I save my code.&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.amir.rachum.com/post/31127785679</link><guid>http://blog.amir.rachum.com/post/31127785679</guid><pubDate>Sat, 08 Sep 2012 18:55:00 +0300</pubDate></item><item><title>Reddit Thinks I'm a Spammer</title><description>&lt;p&gt;When I published my post about &lt;a href="http://blog.amir.rachum.com/post/27860231695/what-else-is-there-in-python"&gt;else statements in Python&lt;/a&gt;, I got lots of comments and a score of over 400 on &lt;a href="http://www.reddit.com/r/programming/"&gt;reddit.com/r/programming&lt;/a&gt; (okay, I realize I&amp;#8217;m &amp;#8220;bragging&amp;#8221; &lt;em&gt;again&lt;/em&gt;, but this actually is a part of the story). My several following posts got measly viewership although I posted them on reddit as well. I was surprised to discover they weren&amp;#8217;t showing up on the &lt;a href="http://www.reddit.com/r/programming/new/"&gt;New page&lt;/a&gt; at all. I thought I just wasn&amp;#8217;t seeing it for some reason, but now I contacted a moderator and, well, here it is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You&amp;#8217;re not banned, but the spam filter has identified you (quite accurately) as a spammer. You have essentially only submitted your own domain, and have only commented on your own submissions. This is exactly the kind of behavior that the spam filter looks for, and accounts very much like yours get submitted to &lt;a href="http://www.reddit.com/r/reportthespammers"&gt;/r/reportthespammers&lt;/a&gt; all day long.&lt;/p&gt;
&lt;p&gt;Please see &lt;a href="http://www.reddit.com/r/Moderating/comments/cz6zu/identifying_spammers_101/"&gt;Identifying Spammers 101&lt;/a&gt; for some insight into what mods look for to identify spammers, and how you might be able to &amp;#8220;legitimize&amp;#8221; your activity on the site.&lt;/p&gt;

&lt;/blockquote&gt;
&lt;p&gt;Well, I can&amp;#8217;t blame the moderator as that&amp;#8217;s their policy, I just have to wonder if they shouldn&amp;#8217;t put some weight to the acceptance of &amp;#8220;spam&amp;#8221; posts by the community. Surely, I&amp;#8217;m not posting cat photos from wesindicatecatphotos.com, am I?&lt;/p&gt;
&lt;p&gt;Reddit thinks I&amp;#8217;m a spammer, and in a way they&amp;#8217;re right. It shocked me a little to discover this, as I consider myself a lawful citizen of the Internet. While I respect their need to protect their community and try to maintain members that are active in the community as a whole (as opposed to utilitarian parasites like me), I&amp;#8217;m not sure if I&amp;#8217;m going to try to legitimize myself for their spam filter. My main go-to technology articles site is &lt;a href="http://news.ycombinator.com/"&gt;HackerNews&lt;/a&gt;, and I don&amp;#8217;t think I&amp;#8217;ll abandon it for reddit (even though reddit is responsible for most of my viewership).&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/30185348950</link><guid>http://blog.amir.rachum.com/post/30185348950</guid><pubDate>Sat, 25 Aug 2012 21:52:19 +0300</pubDate><category>bitching</category><category>meta</category><category>reddit</category><category>hackerNews</category></item><item><title>You Can't Handle the Truth!</title><description>&lt;p&gt;I got a chance to review some other people&amp;#8217;s Python code recently, and there&amp;#8217;s one comment I almost always have to give, which is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;if x&lt;/code&gt; and &lt;code&gt;if x is not None&lt;/code&gt; are not the same!&lt;br/&gt;&lt;em&gt;corollary&lt;/em&gt;: &lt;code&gt;if not x&lt;/code&gt; and &lt;code&gt;if x is None&lt;/code&gt; are also quite different, obviously.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This usually happens when someone assigns &lt;code&gt;None&lt;/code&gt; to a variable (say, &lt;code&gt;x&lt;/code&gt;) as a sentinel value, and then &lt;code&gt;x&lt;/code&gt; may or may not be assigned to. The test is designed to check whether or not &lt;code&gt;x&lt;/code&gt; was assigned to, or not.&lt;/p&gt;
&lt;p&gt;When you do &lt;code&gt;if x is None&lt;/code&gt;, you call the operator &lt;code&gt;is&lt;/code&gt;, which checks the identity of &lt;code&gt;x&lt;/code&gt;. &lt;code&gt;None&lt;/code&gt; is a singleton in Python and all &lt;code&gt;None&lt;/code&gt; values are also the exact same instance. When you say &lt;code&gt;if x&lt;/code&gt;, something different happens. if expects a boolean, and assuming &lt;code&gt;x&lt;/code&gt; is not a boolean, Python automatically calls &lt;code&gt;x&lt;/code&gt;&amp;#8217;s &lt;code&gt;__nonzero__&lt;/code&gt; method. i.e., if &lt;code&gt;x&lt;/code&gt; is actually executed as if &lt;code&gt;x.__nonzero__&lt;/code&gt; (or &lt;code&gt;bool(x)&lt;/code&gt;). &lt;code&gt;__nonzero__&lt;/code&gt; is pretty poorly named*, but it&amp;#8217;s a method that evaluated a class as a boolean value. It&amp;#8217;s one of Python&amp;#8217;s Magic Methods. The confusing thing is, that &lt;code&gt;bool(None)&lt;/code&gt; returns &lt;code&gt;False&lt;/code&gt;, so if x is &lt;code&gt;None&lt;/code&gt;, &lt;code&gt;if x&lt;/code&gt; works as you expect it to. However, there are other values that are evaluated as &lt;code&gt;False&lt;/code&gt;. The most prominent example is an empty list. &lt;code&gt;bool([])&lt;/code&gt; returns &lt;code&gt;False&lt;/code&gt; as well. Usually, an empty list has a meaning that is different to &lt;code&gt;None&lt;/code&gt;; &lt;code&gt;None&lt;/code&gt; means &lt;em&gt;no value&lt;/em&gt; while an empty list means &lt;em&gt;zero values&lt;/em&gt;. Semantically, they are different. I guess people are just unaware of the semantic difference between the two ways to write the condition.&lt;/p&gt;
&lt;p&gt;Here are some useful snippets to demonstrate:&lt;/p&gt;
&lt;h3&gt;Testing &lt;code&gt;None&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = None &lt;br/&gt;... if x: &lt;br/&gt;...     print 'if x' &lt;br/&gt;... if x is not None: &lt;br/&gt;...     print 'if x is not None' &lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Testing an Empty List&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = [] &lt;br/&gt;... if x: &lt;br/&gt;...     print 'if x' &lt;br/&gt;... if x is not None: &lt;br/&gt;...     print 'if x is not None' &lt;br/&gt;if x is not None &lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Testing a Normal Value&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; x = 42 &lt;br/&gt;... if x: &lt;br/&gt;...     print 'if x' &lt;br/&gt;... if x is not None: &lt;br/&gt;...     print 'if x is not None'&lt;br/&gt;if x &lt;br/&gt;if x is not None &lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Testing a Custom Class&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; class Foo(object): &lt;br/&gt;...     def __nonzero__(self): &lt;br/&gt;...         print 'Foo is evaluated to a boolean!' &lt;br/&gt;...         return True &lt;br/&gt;... &lt;br/&gt;... x = Foo() &lt;br/&gt;... if x: &lt;br/&gt;...     print 'if x' &lt;br/&gt;... if x is not None: &lt;br/&gt;...     print 'if x is not None' &lt;br/&gt;Foo is evaluated to a boolean! &lt;br/&gt;if x &lt;br/&gt;if x is not None&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;* Fortunately, the folks working on Python had the sense to change this to &lt;code&gt;__bool__&lt;/code&gt; in Python 3.x!&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/30176371115</link><guid>http://blog.amir.rachum.com/post/30176371115</guid><pubDate>Sat, 25 Aug 2012 19:18:00 +0300</pubDate><category>python</category></item><item><title>Gathering the Comments of the Web</title><description>&lt;p&gt;My recent post about the &lt;a href="http://blog.amir.rachum.com/post/27860231695/what-else-is-there-in-python"&gt;else keyword in Python&lt;/a&gt; was a tremendous success (relative to my other posts), reaching 20,000+ unique visitors within about 24 hours. It was especially successful in Reddit&amp;#8217;s /r/programming, where it got &lt;a href="http://www.reddit.com/r/programming/comments/x1eij/what_else_is_there_in_python/"&gt;over 400 total upvotes and 130 comments&lt;/a&gt;. However, in the post&amp;#8217;s own Disqus thread, there were only 3 comments (one of them was mine). Now, I get that people like to comment in the community where they came from - Reddit folks want to comment on the Reddit thread, HackerNews people want to mingle among themselves, people want to post their comments as twitter responds, etc., but as a blogger, I want people coming in from anywhere to see that there are 100+ comments on my post.&lt;/p&gt;
&lt;p&gt;A friend of mine told me that he saw the post (which I also posted on my facebook wall) and that he didn&amp;#8217;t know where to respond - on my wall, on my twitter account, on the Disqus thread - so many options!&lt;/p&gt;
&lt;p&gt;It got us thinking together on how to solve this issue. Obviously we still want to maintain the separation of comment threads on their respective sites, but as a site owner / blogger, I would like &lt;em&gt;my&lt;/em&gt; website to show all of them. So the solution is quite simple: a comment system like Disqus, which allows users to comment as usual on the thread, which is also tabbed with different communities. When you finish reading, you can see immediately how many comments there are in different communities. There was already a post I saw in HackerNews that used the HN API &lt;a href="http://hncomments.nathancahill.com/"&gt;to display HN comments in your blog&lt;/a&gt;. I suggest taking it a step forward and creating a dynamic tool which works (with plugins, I imagine) for different communities.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/28852177525</link><guid>http://blog.amir.rachum.com/post/28852177525</guid><pubDate>Mon, 06 Aug 2012 22:33:15 +0300</pubDate><category>hackernews</category><category>reddit</category><category>twitter</category><category>project-idea</category><category>meta</category></item><item><title>Self Printing Programs in Python</title><description>&lt;p&gt;Let&amp;#8217;s talk about self printing programs (or, quines). A self printing program is, as is its name, self explanatory. Today I thought about how to implement a quine in Python, I whipped up a solution on my own and then posed the challenge to some people in the office. These are the results:&lt;/p&gt;
&lt;h3&gt;My Version &lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;s = r"print 's = r\"{0}\"'.format(s), '\n', s" &lt;br/&gt;print 's = r\"{0}\"'.format(s), '\n', s&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This exemplifies a common way to implement a quine - the main problem is that you have to use some sort of function that prints. But of course, you also have to print &lt;em&gt;that function&lt;/em&gt;, and so on. The way to deal with this is put the entire program in a string, except the assignment to that string, then print the assignment (where you can use the string itself to avoid explicitly writing it again, thus avoiding the recursion), and then the string.  Notice there&amp;#8217;s a lot of playing with quotation marks. Next is a version that tries to solve this.&lt;/p&gt;
&lt;h3&gt;Using &lt;code&gt;chr&lt;/code&gt; for Quotation Marks&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;a = "b = chr(97) + chr(32) + chr(61) + chr(32) + chr(34); b += a; print b + chr(34); print a"&lt;br/&gt;b = chr(97) + chr(32) + chr(61) + chr(32) + chr(34); b += a; print b + chr(34); print a&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This version (while a bit cumbersome) solves the quotation marks problem by just explicitly printing the ascii characters.&lt;/p&gt;
&lt;h3&gt;Using &lt;code&gt;exec&lt;/code&gt; Instead of Repeating the &lt;code&gt;print&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;s = r"print 's = r\"' + s + '\"' + '\nexec(s)'"&lt;br/&gt;exec(s)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I really likes this version, as it mostly avoids repeating the code in the two lines.&lt;/p&gt;
&lt;h3&gt;The Smartass Approach&lt;/h3&gt;
&lt;p&gt;Well, the first person I introduced this challenge to, had a pretty wiseass, but overall, clever approach. He did this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;print open(__file__).read()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works, and is pretty clever, but it obviously isn&amp;#8217;t what quines are all about. It also wouldn&amp;#8217;t work in an interactive shell.&lt;/p&gt;
&lt;h3&gt;The &amp;#8220;Google&amp;#8221; Way&lt;/h3&gt;
&lt;p&gt;After I got the above answers, I just had to google Python quines and see what comes up. A StackOverflow thread points out &lt;a href="http://stackoverflow.com/questions/6223285/shortest-python-quine"&gt;this (pretty cool) snippet&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;_='_=%r;print _%%_';print _%_&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It assigns to the variable &lt;code&gt;_&lt;/code&gt; a string which is contains the entire code, except for its own value which is replaced by a formatting instruction, and then print &lt;code&gt;_&lt;/code&gt; and feeds itself into its formatting. Looks obfuscated, but it&amp;#8217;s pretty cool when you take a deeper look.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/28779584872</link><guid>http://blog.amir.rachum.com/post/28779584872</guid><pubDate>Sun, 05 Aug 2012 22:07:00 +0300</pubDate><category>python</category></item><item><title>TDGotchi - A Tamagotchi that lives in your Eclipse and feeds on tests and refactorings</title><description>&lt;a href="http://www.happyprog.com/tdgotchi/?repost=true"&gt;TDGotchi - A Tamagotchi that lives in your Eclipse and feeds on tests and refactorings&lt;/a&gt;</description><link>http://blog.amir.rachum.com/post/27957482413</link><guid>http://blog.amir.rachum.com/post/27957482413</guid><pubDate>Wed, 25 Jul 2012 06:35:36 +0300</pubDate></item><item><title>What else is there in Python?</title><description>&lt;p&gt;We all use the &lt;code&gt;else&lt;/code&gt; keyword in Python, usually accompanying &lt;code&gt;if&lt;/code&gt; statement:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if x &amp;gt; 0: &lt;br/&gt;    print 'positive' &lt;br/&gt;elif x &amp;lt; 0: &lt;br/&gt;    print 'negative' &lt;br/&gt;else: &lt;br/&gt;    print 'zero' &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; but Python has a few other uses to the &lt;code&gt;else&lt;/code&gt; keyword that most people are unfamiliar with.&lt;/p&gt;
&lt;p&gt;&lt;!-- more --&gt;&lt;/p&gt;
&lt;h3&gt;for .. else&lt;/h3&gt;
&lt;p&gt;I bet you didn&amp;#8217;t know that you can put an &lt;code&gt;else&lt;/code&gt; clause after a for loop! What does it do? When the items you iterate over are exhausted, the &lt;code&gt;else&lt;/code&gt; clause is executed. When aren&amp;#8217;t the items exhausted? When you use a break statement.&lt;/p&gt;
&lt;p&gt;Using the keyword &lt;code&gt;else&lt;/code&gt; for this clause is kind of silly, as &lt;code&gt;else&lt;/code&gt; doesn&amp;#8217;t really describe the behavior here, but this syntactic sugar can be useful if you put a &lt;code&gt;break&lt;/code&gt; somewhere and need to know if it was used. Let&amp;#8217;s say we have a computer object and a list of people, and we want each person to use the computer, unless one of them breaks it. At the end, we want to know if the computer was broken or not. Usually, we&amp;#8217;d do it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;broken = False &lt;br/&gt;for person in people: &lt;br/&gt;    person.use(computer) &lt;br/&gt;    if computer.is_broken: &lt;br/&gt;        broken = True &lt;br/&gt;        break &lt;br/&gt;if not broken: &lt;br/&gt;    print 'The computer is fine!' &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With &lt;code&gt;for..else&lt;/code&gt; we can do it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for person in people: &lt;br/&gt;    person.use(computer) &lt;br/&gt;    if computer.is_broken: &lt;br/&gt;        break &lt;br/&gt;else: &lt;br/&gt;    print 'The computer is fine!' &lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;while .. else&lt;/h3&gt;
&lt;p&gt;This has pretty much the same semantics as the &lt;code&gt;for..else&lt;/code&gt; syntax. The main while body is executed in a loop as long as the condition is satisfied - that far you already know. If the condition is not satisfied, the &lt;code&gt;else&lt;/code&gt; clause is executed. However, a &lt;code&gt;break&lt;/code&gt; statement will break out of the entire while..else block, so the &lt;code&gt;else&lt;/code&gt; body will not be executed. In a nutshell, it&amp;#8217;s the same as the &lt;code&gt;for&lt;/code&gt; loop: the &lt;code&gt;else&lt;/code&gt; will be executed unless you break out of the loop.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while usage &amp;lt; 10 and person.want_to_play: &lt;br/&gt;    person.use(computer) &lt;br/&gt;    if computer.broken: &lt;br/&gt;        break &lt;br/&gt;else: &lt;br/&gt;    print 'The computer is fine!' &lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;try .. except .. else&lt;/h3&gt;
&lt;p&gt;You got some code in a &lt;code&gt;try&lt;/code&gt; block. You want to catch certain exceptions and handle them, but what if no exceptions were raised? That&amp;#8217;s where the &lt;code&gt;else&lt;/code&gt; clause comes in. It&amp;#8217;s executed only if no exceptions were caught, and before the &lt;code&gt;finally&lt;/code&gt; clause, if it exists. It&amp;#8217;s important to note that exceptions raised by statements in the &lt;code&gt;else&lt;/code&gt; block are not caught by the preceding &lt;code&gt;except&lt;/code&gt;s:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; def get_person(people):&lt;br/&gt;     try:&lt;br/&gt;         person = people[3]&lt;br/&gt;     except IndexError:&lt;br/&gt;         person = None&lt;br/&gt;     else:&lt;br/&gt;         person.do_work()&lt;br/&gt;     return person &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; clause is only executed if &lt;code&gt;IndexError&lt;/code&gt; was not caught. Why is this useful? Well, one would probably put the &lt;code&gt;person.do_work()&lt;/code&gt; bit inside the &lt;code&gt;try&lt;/code&gt; block, &lt;strong&gt;but what if &lt;code&gt;do_work&lt;/code&gt; raises an &lt;code&gt;IndexError&lt;/code&gt;?&lt;/strong&gt; In that case, it will be caught by our &lt;code&gt;except&lt;/code&gt; block, which could be catastrophic if we didn&amp;#8217;t intend for that. This way, if &lt;code&gt;do_work&lt;/code&gt; raises an &lt;code&gt;IndexError&lt;/code&gt;, it will propagate through the code, as it should.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Well, I haven&amp;#8217;t found the &lt;code&gt;else&lt;/code&gt; keyword very useful outside an &lt;code&gt;if&lt;/code&gt; block. My opinion is that with &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loops it should probably be avoided as its behavior is not intuitive. Use it only if it&amp;#8217;s more readable than its more verbose alternative. Using &lt;code&gt;else&lt;/code&gt; in a &lt;code&gt;try&lt;/code&gt; statement, on the other hand, is much more intuitive, and is probably a better alternative than catching exceptions you didn&amp;#8217;t plan on, or using a variable to store information on whether an exception was raised to be used after the &lt;code&gt;try..except&lt;/code&gt; block.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/27860231695</link><guid>http://blog.amir.rachum.com/post/27860231695</guid><pubDate>Tue, 24 Jul 2012 00:43:00 +0300</pubDate><category>python</category></item><item><title>Cool Syntax and Weird Documentation - Fun with Scapy</title><description>&lt;p&gt;I was looking for a way to parse TCP/IP packets in Python, when a friend recommended &lt;a href="http://www.secdev.org/projects/scapy/"&gt;Scapy&lt;/a&gt;. Scapy is a nice python package that&amp;#8217;s got a very cool interface using the &amp;#8220;div&amp;#8221; operator, and is used like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;packet = IP()/TCP()/"GET / HTTP/1.0\r\n\r\n"&lt;br/&gt;str(packet) # returns the packet's binary data &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which is pretty cool and creative. It makes the layers concept pretty visual. Now, I was looking for a way to parse packets, i.e., the other way around. So we were looking in scapy&amp;#8217;s documentation. The section on &amp;#8220;dissecting&amp;#8221; seemed like it might be what we wanted, and here&amp;#8217;s the introduction:&lt;/p&gt;
&lt;blockquote&gt;
&lt;h3&gt;Dissecting&lt;/h3&gt;
&lt;p id="index-2"&gt;Layers are only list of fields, but what is the glue between each field, and after, between each layer. These are the mysteries explain in this section.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I ended up not needing to parse packets, but I did use it to generate TCP/IP packets, and I gotta say, it couldn&amp;#8217;t be any easier. &lt;a href="http://www.secdev.org/projects/scapy/"&gt;Go on, check it out&lt;/a&gt;. Their documentation &lt;a href="http://www.secdev.org/projects/scapy/doc/introduction.html#learning-python"&gt;also teaches Python&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/27503391253</link><guid>http://blog.amir.rachum.com/post/27503391253</guid><pubDate>Wed, 18 Jul 2012 23:36:59 +0300</pubDate><category>python</category><category>network</category><category>ip</category></item><item><title>Converting a Software Thief into a Customer</title><description>&lt;a href="https://www.blurity.com/blog/2012/07/17/how-i-converted-a-software-thief-into-a-customer/"&gt;Converting a Software Thief into a Customer&lt;/a&gt;</description><link>http://blog.amir.rachum.com/post/27468125350</link><guid>http://blog.amir.rachum.com/post/27468125350</guid><pubDate>Wed, 18 Jul 2012 09:30:21 +0300</pubDate></item><item><title>A Late Introduction to Jools</title><description>&lt;p&gt;A while back I wrote a small Java tools library called Jools. I never really presented it to &amp;#8220;the world&amp;#8221; (except for &lt;a href="https://github.com/Nurdok/Jools"&gt;hosting it on Github&lt;/a&gt;). So I figured, now is my chance. Here are the features Jools provide:&lt;/p&gt;
&lt;h3&gt;Python-like Range Objects&lt;/h3&gt;
&lt;p&gt;This one is pretty straight forward&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for (final int i : new Range(5)) { &lt;br/&gt;    players.add(new SmartPlayer(names.get(i))); &lt;br/&gt;}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Generating Permutations&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;PermutationGenerator&amp;lt;String&amp;gt; pg = new PermutationGenerator&amp;lt;String&amp;gt;("a", "b", "c"); &lt;br/&gt;for (List&amp;lt;String&amp;gt; permutation : pg) { &lt;br/&gt;    System.out.println("Permutation: " + permutation); &lt;br/&gt;}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This prints:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Permutation: [a, b, c] &lt;br/&gt;Permutation: [a, c, b] &lt;br/&gt;Permutation: [b, a, c] &lt;br/&gt;Permutation: [b, c, a] &lt;br/&gt;Permutation: [c, a, b] &lt;br/&gt;Permutation: [c, b, a]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The cool thing about this class is that it also allows to get a permutation &lt;strong&gt;based on its index&lt;/strong&gt; (calculated efficiently in O(n) time, when n is the number of items (not permutation)):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;System.out.println("Permutation #3: " + pg.get(3));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This yields:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Permutation #3: [b, c, a]&lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;h3&gt;Iterable Wrapper For Looping with Indices&lt;/h3&gt;
&lt;p&gt;Similar to Python&amp;#8217;s enumerate function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;final List&amp;lt;String&amp;gt; list = Arrays.asList("A", "B", "C", "D", "E", "F", "G"); &lt;br/&gt;for (final IndexedElement&amp;lt;String&amp;gt; element : new Indexer&amp;lt;String&amp;gt;(list)) { &lt;br/&gt;    System.out.println(element.getElement() + " : " + element.getIndex()); &lt;br/&gt;} &lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;That&amp;#8217;s it. Not a big library, as I said, but it&amp;#8217;s been helpful to me, and I hope it can be helpful to you as well!&lt;/div&gt;</description><link>http://blog.amir.rachum.com/post/27201385517</link><guid>http://blog.amir.rachum.com/post/27201385517</guid><pubDate>Sat, 14 Jul 2012 20:18:07 +0300</pubDate><category>java</category><category>jools</category><category>my-projects</category></item><item><title>Double Iteration in List Comprehension</title><description>&lt;p&gt;Here&amp;#8217;s something I didn&amp;#8217;t know possible in Python: iteration over more than one iterable in a list comprehension:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; seq_x = [1, 2, 3, 4]&lt;br/&gt;&amp;gt;&amp;gt;&amp;gt; seq_y = 'abc'&lt;br/&gt;&amp;gt;&amp;gt;&amp;gt; [(x,y) for x in seq_x for y in seq_y]&lt;br/&gt;[(1, 'a'), &lt;br/&gt;(1, 'b'), &lt;br/&gt;(1, 'c'), &lt;br/&gt;(2, 'a'), &lt;br/&gt;(2, 'b'), &lt;br/&gt;(2, 'c'), &lt;br/&gt;(3, 'a'), &lt;br/&gt;(3, 'b'), &lt;br/&gt;(3, 'c'), &lt;br/&gt;(4, 'a'), &lt;br/&gt;(4, 'b'), &lt;br/&gt;(4, 'c')]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cool, isn&amp;#8217;t it? It&amp;#8217;s equivalent to the following snippet:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; result = [] &lt;br/&gt;... for x in seq_x: &lt;br/&gt;...     for y in seq_y: &lt;br/&gt; ...         result.append((x,y)) &lt;br/&gt;&amp;gt;&amp;gt;&amp;gt; result &lt;br/&gt;[(1, 'a'), &lt;br/&gt;(1, 'b'), &lt;br/&gt;(1, 'c'), &lt;br/&gt;(2, 'a'), &lt;br/&gt;(2, 'b'), &lt;br/&gt;(2, 'c'), &lt;br/&gt;(3, 'a'), &lt;br/&gt;(3, 'b'), &lt;br/&gt;(3, 'c'), &lt;br/&gt;(4, 'a'), &lt;br/&gt;(4, 'b'), &lt;br/&gt;(4, 'c')]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It also supports both &amp;#8220;if&amp;#8221; statements and referencing the outer iterator from the inner one, like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; seq = ['abc', 'def', 'g', 'hi'] &lt;br/&gt;... [y for x in seq if len(seq) &amp;gt; 1 for y in x if y != 'e'] &lt;br/&gt;['a', 'b', 'c', 'd', 'f', 'g', 'h', 'i']&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is equivalent to the snippet:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; result = [] &lt;br/&gt;... for x in seq: &lt;br/&gt;...     if len(seq) &amp;gt; 1: &lt;br/&gt;...         for y in x: &lt;br/&gt;...             if y != 'e': &lt;br/&gt;...                 result.append(y) &lt;br/&gt;... result ['a', 'b', 'c', 'd', 'f', 'g', 'h', 'i']&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The thing you should notice here, is that the outer loop is the first &amp;#8216;for&amp;#8217; loop in the list comprehension. This was a little confusing for me at first because when I nest list comprehensions it&amp;#8217;s the other way around.&lt;/p&gt;
&lt;p&gt;To read more about this feature, check out &lt;a href="http://stackoverflow.com/questions/1198777/double-iteration-in-list-comprehension"&gt;this StackOverflow thread&lt;/a&gt; or the &lt;a href="http://docs.python.org/howto/functional.html"&gt;Python Manual&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.amir.rachum.com/post/27155549191</link><guid>http://blog.amir.rachum.com/post/27155549191</guid><pubDate>Sat, 14 Jul 2012 02:33:00 +0300</pubDate><category>python</category></item></channel></rss>
