<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ruslan's Blog</title>
	<atom:link href="http://ruslanspivak.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ruslanspivak.com</link>
	<description>Musings on dynamic languages and more than that</description>
	<lastBuildDate>Tue, 07 Apr 2009 01:45:02 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/04a636b5f08c182c190ff6d8ae67239e?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Ruslan's Blog</title>
		<link>http://ruslanspivak.com</link>
	</image>
			<item>
		<title>Downcase with replace-regexp</title>
		<link>http://ruslanspivak.com/2009/04/06/downcase-with-replace-regexp/</link>
		<comments>http://ruslanspivak.com/2009/04/06/downcase-with-replace-regexp/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 01:45:02 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=117</guid>
		<description><![CDATA[Recently I&#8217;ve been working with CSS files and wanted to replace color definitions with downcased equivalents, i.e. #FFFFFF; would become #ffffff;
To do that I used pretty well known feature of Emacs, namely use of Lisp expressions in the replacement string of replace-regexp function.
Commands entered in minibuffer:
M-x replace-regexp RET \(#.*\)  RET \,(downcase \1) RET
The only problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=117&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently I&#8217;ve been working with CSS files and wanted to replace color definitions with downcased equivalents, i.e. <strong>#FFFFFF;</strong> would become <strong>#ffffff;</strong></p>
<p>To do that I used pretty well known feature of Emacs, namely use of <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html">Lisp expressions</a> in the replacement string of <strong>replace-regexp</strong> function.</p>
<p>Commands entered in minibuffer:</p>
<p><strong>M-x replace-regexp RET \(#.*\)  RET \,(downcase \1) RET</strong></p>
<p>The only problem with that code is that if you have variable <strong>case-fold-search</strong> in Emacs set to <strong>true</strong> (which is the case in my Emacs by default) <strong>replace-regexp</strong> will report about successful replace but string won&#8217;t be downcased anyway. To quickly switch off <strong>case-fold-search</strong> I used <strong>M-: (setq case-fold-search nil)</strong> and after that downcasing worked as expected.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=117&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/04/06/downcase-with-replace-regexp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>IPython profile for Grok</title>
		<link>http://ruslanspivak.com/2009/03/30/ipython-profile-for-grok/</link>
		<comments>http://ruslanspivak.com/2009/03/30/ipython-profile-for-grok/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 06:46:27 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[grok]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=111</guid>
		<description><![CDATA[To use IPython shell from Grok based project is easy, just add ipython to eggs directive in your buildout.cfg
My part with ipython added looks like this:
[app]
recipe = zc.recipe.egg
eggs = grok-awesome
       ipython
       Paste
       PasteScript
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=111&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>To use IPython shell from Grok based project is easy, just add <em>ipython</em> to eggs directive in your <em>buildout.cfg</em></p>
<p>My part with <em>ipython</em> added looks like this:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">[<span style="color:#8DA6CE;">app</span>]
<span style="color:#FF6400;">recipe</span> = zc.recipe.egg
<span style="color:#FF6400;">eggs</span> = grok-awesome
       ipython
       Paste
       PasteScript
       PasteDeploy
<span style="color:#FF6400;">interpreter</span> = python-console</pre>
<p>But I wanted to be able to inspect Grok instance and use path TAB auto-completion to navigate ZODB hierarchy.</p>
<p>Inspired by existing IPython profile fo Zope2 I whipped out basic implementation for Grok.</p>
<p>It&#8217;s available under <a href="http://github.com/rspivak/grok-ipython/tree">grok-ipython</a>. Now all IPython power can be used when inspecting objects in Grok instance:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#F8F8F8;background-color:#0C1021;">(mygrok)[alienoid@capricorn grok-awesome]$ bin/ipython -p grok</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">IPython shell for Grok.</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#F8F8F8;background-color:#0C1021;">Bound object names:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">-------------------</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  root</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  ctx</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#F8F8F8;background-color:#0C1021;">Bound command names:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">--------------------</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  cdg / ;cdg</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  lsg / ;lsg</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  pwdg</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  sync</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">  commit</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#F8F8F8;background-color:#0C1021;">Grok IPython 0.9.1   Py 2.5.2</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">1</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">root</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">1</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;zope.app.folder.folder.Folder object at 0x9003e6c&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">2</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">ctx</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">2</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;zope.app.folder.folder.Folder object at 0x9003e6c&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">3</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">;cdg blog</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#00cd00;background-color:#0C1021;">------&gt; </span><span style="color:#F8F8F8;background-color:#0C1021;">cdg("blog")</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">3</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">u'/blog'</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">4</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">ctx</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">4</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;grokawesome.blog.Blog object at 0x81d2d6c&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">5</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">;cdg </span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">my-first-post  second-post    </span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">5</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">;cdg my-first-post</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#00cd00;background-color:#0C1021;">------&gt; </span><span style="color:#F8F8F8;background-color:#0C1021;">cdg("my-first-post")</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">5</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">u'/blog/my-first-post'</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">6</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">ctx</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">6</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;grokawesome.entry.BlogEntry object at 0xb7d556ac&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">7</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">pwdg</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;">Out[</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">7</span><span style="color:#cd0000;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">u'/blog/my-first-post'</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">8</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">ctx?</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Type:</span><span style="color:#F8F8F8;background-color:#0C1021;">           </span><span style="color:#F8F8F8;background-color:#0C1021;">BlogEntry</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Base Class:</span><span style="color:#F8F8F8;background-color:#0C1021;">     </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;class 'grokawesome.entry.BlogEntry'&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">String Form:</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;grokawesome.entry.BlogEntry object at 0xb7d556ac&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Namespace:</span><span style="color:#F8F8F8;background-color:#0C1021;">      </span><span style="color:#F8F8F8;background-color:#0C1021;">Interactive</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Length:</span><span style="color:#F8F8F8;background-color:#0C1021;">         </span><span style="color:#F8F8F8;background-color:#0C1021;">0</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">File:</span><span style="color:#F8F8F8;background-color:#0C1021;">           </span><span style="color:#F8F8F8;background-color:#0C1021;">/home/alienoid/mygrok/grok-awesome/src/grokawesome/entry.py</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Docstring:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">    &lt;no docstring&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span>
<span style="color:#00cd00;background-color:#0C1021;">In [</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">9</span><span style="color:#00cd00;background-color:#0C1021;">]: </span><span style="color:#F8F8F8;background-color:#0C1021;">ctx??</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Type:             </span><span style="color:#F8F8F8;background-color:#0C1021;">BlogEntry</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Base Class:       </span><span style="color:#F8F8F8;background-color:#0C1021;">&lt;class 'grokawesome.entry.BlogEntry'&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">String Form:</span><span style="color:#F8F8F8;background-color:#0C1021;">   &lt;grokawesome.entry.BlogEntry object at 0xb7d556ac&gt;</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Namespace:        </span><span style="color:#F8F8F8;background-color:#0C1021;">Interactive</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Length:           </span><span style="color:#F8F8F8;background-color:#0C1021;">0</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">File:             </span><span style="color:#F8F8F8;background-color:#0C1021;">/home/alienoid/mygrok/grok-awesome/src/grokawesome/entry.py</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#cd0000;background-color:#0C1021;font-weight:bold;">Source:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">class</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">BlogEntry</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">grok</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">Container</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">grok</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">implements</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">IBlogEntry</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">portal_type</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#0000ee;background-color:#0C1021;font-weight:bold;">'blogentry'</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">created</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">property</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">DCProperty</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#0000ee;background-color:#0C1021;font-weight:bold;">'created'</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">modified</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">property</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">DCProperty</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#0000ee;background-color:#0C1021;font-weight:bold;">'modified'</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#F8F8F8;background-color:#0C1021;">

</span><span style="color:#F8F8F8;background-color:#0C1021;">    </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">def</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">__init__</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">title</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">content</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">                 </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">summary</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#0000ee;background-color:#0C1021;font-weight:bold;">u''</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">                 </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">categories</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">None</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">                 </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">allow_comments</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">False</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">:</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">super</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">BlogEntry</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">,</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">__init__</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">(</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">)</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">title</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">title</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">content</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">content</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">summary</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#0000ee;background-color:#0C1021;font-weight:bold;">''</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">if</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">summary</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">is</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">None</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">else</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">summary</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">categories</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">[</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">]</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">if</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">categories</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">is</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">None</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#00cd00;background-color:#0C1021;font-weight:bold;">else</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">categories</span><span style="color:#F8F8F8;background-color:#0C1021;">
</span><span style="color:#F8F8F8;background-color:#0C1021;">        </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">self</span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">.</span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">allow_comments</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#cdcd00;background-color:#0C1021;font-weight:bold;">=</span><span style="color:#F8F8F8;background-color:#0C1021;"> </span><span style="color:#ffffff;background-color:#0C1021;font-weight:bold;">allow_comments</span></pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=111&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/30/ipython-profile-for-grok/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>TinyMCE widget in Grok</title>
		<link>http://ruslanspivak.com/2009/03/24/tinymce-widget-in-grok/</link>
		<comments>http://ruslanspivak.com/2009/03/24/tinymce-widget-in-grok/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 22:48:26 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[grok]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=100</guid>
		<description><![CDATA[I have added TinyMCE widget to grok-awesome for editing html and it was easy as pie.
If you want TinyMCE in your Grok based project it can be achieved with following steps:
1. Add dependencies to setup.py into install_requires section:
                  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=100&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have added TinyMCE widget to <a href="http://github.com/rspivak">grok-awesome</a> for editing html and it was easy as pie.</p>
<p>If you want <a href="http://tinymce.moxiecode.com/">TinyMCE</a> in your Grok based project it can be achieved with following steps:</p>
<p><strong>1</strong>. Add dependencies to <em>setup.py</em> into <em>install_requires</em> section:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">                        <span style="color:#61CE3C;">'hurry.tinymce'</span>,
                        <span style="color:#61CE3C;">'hurry.zopetinymce'</span>,</pre>
<p><a href="http://pypi.python.org/pypi/hurry.tinymce/">hurry.tinymce</a> allows you to include TinyMCE into your project without additional burden, you don&#8217;t need to do anything. Well, almost &#8211; just make sure to call:<br />
<strong><em>from hurry.tinymce import tinymce<br />
tinymce.need()</em></strong><br />
to trigger inclusion of TinyMCE in the web page.</p>
<p><strong>2</strong>. Create custom widget which calls <em>tinymce.need()</em> as noted above  and initializes TinyMCE</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#FBDE2D;">from</span> zope.app.form.browser <span style="color:#FBDE2D;">import</span> TextAreaWidget
<span style="color:#FBDE2D;">from</span> hurry.tinymce <span style="color:#FBDE2D;">import</span> tinymce

<span style="color:#FF6400;">template</span> = <span style="color:#61CE3C;">"""%(widget_html)s
&lt;script type="</span>text/javascript<span style="color:#61CE3C;">"&gt;
  tinyMCE.init({
    mode : "</span>exact<span style="color:#61CE3C;">",
    elements: "</span>%(elements)s<span style="color:#61CE3C;">",
    theme: "</span>advanced<span style="color:#61CE3C;">"
  });
&lt;/script&gt;"""</span>

<span style="color:#FBDE2D;">class</span> <span style="color:#8DA6CE;">TinyMCEWidget</span>(TextAreaWidget):
    <span style="color:#61CE3C;">"""Widget to edit html using TinyMCE WYSIWYG editor."""</span>

    <span style="color:#FBDE2D;">def</span> <span style="color:#FF6400;">__call__</span>(<span style="color:#FBDE2D;">self</span>, *args, **kw):
        widget_html = <span style="color:#F8F8F8;">super</span>(TinyMCEWidget, <span style="color:#FBDE2D;">self</span>).__call__(*args, **kw)
        tinymce.need()
        <span style="color:#FBDE2D;">return</span> template % {<span style="color:#61CE3C;">'widget_html'</span>: widget_html,
                           <span style="color:#61CE3C;">'elements'</span>: <span style="color:#FBDE2D;">self</span>.name,
                           }</pre>
<p><strong>3</strong>. In your add/edit form use your custom widget for the field you want and off you go:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">form_fields[<span style="color:#61CE3C;">'content'</span>].custom_widget = TinyMCEWidget</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/100/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=100&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/24/tinymce-widget-in-grok/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Decode hex pairwise with zip</title>
		<link>http://ruslanspivak.com/2009/03/20/decode-hex-pairwise-with-zip/</link>
		<comments>http://ruslanspivak.com/2009/03/20/decode-hex-pairwise-with-zip/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 16:34:55 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=68</guid>
		<description><![CDATA[The other day I had to decode strings containing hex numbers into plain integers.
I could use built-in int([ x [, radix]]) with radix=16 to convert a string to an integer and forget about it, but I needed to decode pairs from the hex number so that in the end from the string &#8216;FFEEDD&#8217; I get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=68&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The other day I had to decode strings containing hex numbers into plain integers.</p>
<p>I could use built-in <strong><em>int([ x [, radix]])</em></strong> with <strong><em>radix=16</em></strong> to convert a string to an integer and forget about it, but I needed to decode pairs from the hex number so that in the end from the string &#8216;FFEEDD&#8217; I get 255, 238, 221</p>
<p>But wouldn&#8217;t you know it, there is a standard solution to get pairs in Python and it&#8217;s built-in <em>zip</em> function.</p>
<p>It&#8217;s a well known function for experienced developers, but there is one documented feature of it that doesn&#8217;t always catch one&#8217;s eye and it&#8217;s a general form for clustering a data series into n-length groups <strong>zip(*[iter(s)]*n)</strong> which is described in official docs for <a href="http://docs.python.org/library/functions.html">zip built-in</a>.</p>
<p>With that in mind solution to my problem boils down to a one-line decoder:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#00ff00;background-color:#0C1021;">&gt;&gt;&gt; </span><span style="font-weight:bold;">s = 'FFDDEE'</span>
<span style="color:#00ff00;background-color:#0C1021;">&gt;&gt;&gt; </span><span style="font-weight:bold;">[int(''.join(pair), 16) for pair in zip(*[iter(s)]*2)]</span>
[255, 221, 238]</pre>
<p>For those wondering how it works:</p>
<p>1) <em>iter(s)</em> creates iterable from the <em>s</em></p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#00ff00;background-color:#0C1021;">&gt;&gt;&gt; </span><span style="font-weight:bold;">iter(s)</span>
&lt;iterator object at 0x8a3c2cc&gt;</pre>
<p>2) <em>[iter(s)] * 2</em> creates list of 2 iterators that all use the same underlying iterable <em>iter(s)</em>. The important thing is that created iterators <strong><em>share the same iterable</em></strong>, so when some data is consumed by first iterator that data becomes unavailable for the second iterator and vice versa.</p>
<p>You can see from the output that iterator objects are located at the same address. If you are new to this behavior you can read on about <a href="http://docs.python.org/library/stdtypes.html#typesseq">shallow copies</a>.</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#00ff00;background-color:#0C1021;">&gt;&gt;&gt; </span><span style="font-weight:bold;">[iter(s)]*2</span>
[&lt;iterator object at 0x8a3c2cc&gt;, &lt;iterator object at 0x8a3c2cc&gt;]</pre>
<p>3) leading <strong>*</strong> in zip&#8217;s parameter unpacks list from step (2) into two separate parameters for zip function. Basically it becomes <em>zip(iterator, iterator)</em>.</p>
<p>More about unpacking argument list you can read in official <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists">docs</a>.</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="color:#00ff00;background-color:#0C1021;">&gt;&gt;&gt; </span><span style="font-weight:bold;">zip(*[iter(s)]*2)</span>
[('F', 'F'), ('D', 'D'), ('E', 'E')]</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=68&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/20/decode-hex-pairwise-with-zip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Refresh Firefox page from Emacs</title>
		<link>http://ruslanspivak.com/2009/03/16/refresh-firefox-page-from-emacs/</link>
		<comments>http://ruslanspivak.com/2009/03/16/refresh-firefox-page-from-emacs/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 18:26:04 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[grok]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=57</guid>
		<description><![CDATA[I often need to refresh page in Firefox when I edit page template or javascript file. This is especially true when working on grok-awesome.
Though I use tiling window manager StumpWM and it&#8217;s very easy to switch to running Firefox with keyboard shortcut and make refresh, it&#8217;s even easier not to leave focus from Emacs window [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=57&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I often need to refresh page in Firefox when I edit page template or javascript file. This is especially true when working on <a href="http://ruslanspivak.com/2009/03/12/grok-awesome/">grok-awesome</a>.</p>
<p>Though I use tiling window manager <a href="http://www.nongnu.org/stumpwm/">StumpWM</a> and it&#8217;s very easy to switch to running Firefox with keyboard shortcut and make refresh, it&#8217;s even easier not to leave focus from Emacs window and just send command to Firefox to refresh itself.<br />
For that I use:</p>
<ul>
<li> <a href="http://wiki.github.com/bard/mozrepl">MozRepl</a> firefox plugin to allow connect to Firefox&#8217;s REPL. After installation in Tools -&gt; MozRepl menu I chose &#8216;Activate on startup&#8217; for convenience</li>
<li> MozRepl Emacs <a href="http://wiki.github.com/bard/mozrepl/emacs-integration">integration</a> (If you use <a href="http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html">nXhtml</a> package in Emacs you already have that integration and can skip this part)</li>
</ul>
<p>Command to refresh Firefox is <strong>BrowserReload();</strong></p>
<p>Final touch is small anonymous function to send that command to mozrepl, keybinding to <strong>C-x p</strong> and we&#8217;re all set:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">(global-set-key (kbd <span style="color:#61CE3C;">"C-x p"</span>)
                (<span style="color:#FBDE2D;">lambda</span> ()
                  (interactive)
                  (comint-send-string (inferior-moz-process)
                                      <span style="color:#61CE3C;">"BrowserReload();"</span>)))</pre>
<p>Now anytime just press <strong>C-x p</strong> and refresh command will be sent to Firefox starting along the way mozrepl session in your Emacs if it&#8217;s not been already started.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=57&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/16/refresh-firefox-page-from-emacs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Grok Awesome</title>
		<link>http://ruslanspivak.com/2009/03/12/grok-awesome/</link>
		<comments>http://ruslanspivak.com/2009/03/12/grok-awesome/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 20:15:07 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[grok]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=49</guid>
		<description><![CDATA[I&#8217;ve started developing blog software for &#8220;A Smashing Web Framework&#8221; Grok.
The reasons behind that:

There is no full-featured blog software for Grok. There is a simple version Grokstar, but as for me it doesn&#8217;t fit the bill.
I created simple blog for Zope3 several years ago and let it languish. Now it&#8217;s time to revive it taking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=49&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve started developing blog software for &#8220;A Smashing Web Framework&#8221; <a href="http://grok.zope.org/">Grok</a>.</p>
<p>The reasons behind that:</p>
<ul>
<li>There is no full-featured blog software for Grok. There is a simple version <a href="http://svn.zope.org/Grokstar/">Grokstar</a>, but as for me it doesn&#8217;t fit the bill.</li>
<li>I created simple blog for Zope3 several years ago and let it languish. Now it&#8217;s time to revive it taking into account how Grok simplifies development with Zope3 technologies.</li>
<li>I&#8217;m not completely happy with WordPress. For one thing, I&#8217;d like to have easy-to-use REST API so I can use it in my Emacs to make posts.</li>
<li>I simply love <a href="http://grok.zope.org/">Grok</a>. You should try it and you&#8217;ll love it too.</li>
</ul>
<p>My fledgling project lives on GitHub and it&#8217;s called <a href="http://github.com/rspivak/grok-awesome/tree/master">grok-awesome</a> :)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=49&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/12/grok-awesome/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs dark theme + IPython colors</title>
		<link>http://ruslanspivak.com/2009/03/09/emacs-dark-theme-ipython-colors/</link>
		<comments>http://ruslanspivak.com/2009/03/09/emacs-dark-theme-ipython-colors/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 07:15:09 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=39</guid>
		<description><![CDATA[Ever wondered how to make IPython colors be nice on dark background of your dark (no pun intended) Emacs theme like blackboard ?
Just add to your .emacs
(setq py-python-command-args '("-pylab" "-colors" "Linux"))
before you load ipython package
(setq py-python-command-args '("-pylab" "-colors" "Linux"))
(require 'ipython)
Now IPython uses &#8216;Linux&#8217; color scheme which is suitable for dark background with light fonts instead [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=39&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ever wondered how to make IPython colors be nice on dark background of your dark (no pun intended) Emacs theme like <a href="http://blog.jdhuntington.com/2008/11/emacs-color-theme-blackboard.html">blackboard </a>?</p>
<p>Just add to your .emacs</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;"><span style="background-color:#4f94cd;">(</span>setq py-python-command-args '(<span style="color:#61CE3C;">"-pylab"</span> <span style="color:#61CE3C;">"-colors"</span> <span style="color:#61CE3C;">"Linux"</span>)<span style="background-color:#4f94cd;">)</span></pre>
<p>before you load ipython package</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">(setq py-python-command-args '(<span style="color:#61CE3C;">"-pylab"</span> <span style="color:#61CE3C;">"-colors"</span> <span style="color:#61CE3C;">"Linux"</span>))
(<span style="color:#FBDE2D;">require</span> '<span style="color:#D8FA3C;">ipython</span>)</pre>
<p>Now IPython uses &#8216;Linux&#8217; color scheme which is suitable for dark background with light fonts instead of default &#8216;LightBG&#8217;.</p>
<p>Here it is:</p>
<pre style="color:#F8F8F8;background-color:#0C1021;font-size:8pt;">Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
Type "copyright", "credits" or "license" for more information.

IPython 0.9.1 -- An enhanced Interactive Python.
?         -&gt; Introduction and overview of IPython's features.
%quickref -&gt; Quick reference.
help      -&gt; Python's own help system.
object?   -&gt; Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

<span style="color:#00ff00;background-color:#0C1021;">In [</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">1</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">]: </span><span style="font-weight:bold;">d = dict()</span>

<span style="color:#00ff00;background-color:#0C1021;">In [</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">2</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">]: </span><span style="font-weight:bold;">?d</span>
<span style="color:#ff0000;font-weight:bold;">Type:           </span>dict
<span style="color:#ff0000;font-weight:bold;">Base Class:     </span>&lt;type 'dict'&gt;
<span style="color:#ff0000;font-weight:bold;">String Form:</span>    {}
<span style="color:#ff0000;font-weight:bold;">Namespace:      </span>Interactive
<span style="color:#ff0000;font-weight:bold;">Length:         </span>0
<span style="color:#ff0000;font-weight:bold;">Docstring:
</span>    dict() -&gt; new empty dictionary.
    dict(mapping) -&gt; new dictionary initialized from a mapping object's
        (key, value) pairs.
    dict(seq) -&gt; new dictionary initialized as if via:
        d = {}
        for k, v in seq:
            d[k] = v
    dict(**kwargs) -&gt; new dictionary initialized with the name=value pairs
        in the keyword argument list.  For example:  dict(one=1, two=2)

<span style="color:#00ff00;background-color:#0C1021;">In [</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">3</span><span style="color:#00ff00;background-color:#0C1021;font-weight:bold;">]: </span></pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=39&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/09/emacs-dark-theme-ipython-colors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Release It!&#8221; is just what the doctor ordered</title>
		<link>http://ruslanspivak.com/2009/03/02/release-it-is-just-what-the-doctor-ordered/</link>
		<comments>http://ruslanspivak.com/2009/03/02/release-it-is-just-what-the-doctor-ordered/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 19:34:37 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[book]]></category>

		<guid isPermaLink="false">http://ruslanspivak.com/?p=30</guid>
		<description><![CDATA[I&#8217;ve just finished reading excellent book Release It!: Design and Deploy Production-Ready Software
If you are involved or plan to be involved in developing any system that must be available 24 x 7 x 365 then you owe it to yourself to read this book.
The key ideas you should understand are:

system will fail


life of software only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=30&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve just finished reading excellent book <a href="http://www.pragprog.com/titles/mnee/release-it"><em>Release It!: Design and Deploy Production-Ready Software</em></a></p>
<p>If you are involved or plan to be involved in developing any system that must be available 24 x 7 x 365 then you owe it to yourself to read this book.</p>
<p>The key ideas you should understand are:</p>
<ul>
<li>system will fail</li>
</ul>
<ul>
<li>life of software only begins when you release it into production</li>
</ul>
<p>With that in mind the book is a treasure trove of useful advices how to make your system scale and succeed in production.</p>
<p>The book resonates with my own personal experience in developing and maintaining critical Python application and many things that Michael Nygard describes I learned the hard way: blocked threads, socket timeouts, integration point failures and latency, asynchronous handling, caching, database growth and of course &#8220;cold shivers&#8221; you get when the system goes down.</p>
<p>While book is sprinkled with notes about Java related issues it&#8217;s nevertheless technology agnostic which makes it a valuable source of information for every developer.</p>
<p>It gets two thumbs up from me.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=30&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2009/03/02/release-it-is-just-what-the-doctor-ordered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Autovivication and Y Combinator in Python</title>
		<link>http://ruslanspivak.com/2008/04/14/autovivication-and-y-combinator-in-python/</link>
		<comments>http://ruslanspivak.com/2008/04/14/autovivication-and-y-combinator-in-python/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 22:45:55 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ruslanspivak.wordpress.com/?p=29</guid>
		<description><![CDATA[Sometimes you may need to have nested dictionaries initialized without much hassle.
&#8220;Autovivication&#8221; comes in handy. What you want to achieve is:

&#62;&#62;&#62; d = dict()
&#62;&#62;&#62; d['q']['w']['r'] = 777

Of course what you&#8217;ll get will be:

&#62;&#62;&#62; d['q']['w']['r'] = 777
Traceback (most recent call last):
  File "&#60;stdin&#62;", line 1, in &#60;module&#62;
KeyError: 'q'

If you don&#8217;t need deeply nested dictionaries defaultdict [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=29&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes you may need to have nested dictionaries initialized without much hassle.</p>
<p>&#8220;Autovivication&#8221; comes in handy. What you want to achieve is:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d = dict()</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r'] = 777</span>
</pre>
<p>Of course what you&#8217;ll get will be:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r'] = 777</span>
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
<span style="color:#87cefa;">KeyError</span>: 'q'
</pre>
<p>If you don&#8217;t need deeply nested dictionaries <strong>defaultdict </strong> with <em>dict default factory</em> will do the job:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">from collections import defaultdict</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d = defaultdict(dict)</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;type 'dict'&gt;, {})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['a']['b'] = 33</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;type 'dict'&gt;, {'a': {'b': 33}})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['a']['b']</span>
33
</pre>
<p>Here are another ways to have unlimited level of nested dictionaries.<br />
<strong>1)</strong> Define custom class inheriting from built-in <strong>dict</strong>:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">class</span> <span style="color:#98fb98;">default_dict</span>(dict):
    <span style="color:#00ffff;">def</span> <span style="color:#87cefa;">__missing__</span>(<span style="color:#00ffff;">self</span>, key):
        <span style="color:#00ffff;">self</span>[key] = value = <span style="color:#00ffff;">self</span>.__class__()
        <span style="color:#00ffff;">return</span> value
</pre>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d = default_dict()</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
{}
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r'] = 777</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
{'q': {'w': {'r': 777}}}
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r']</span>
777
</pre>
<p><strong>2)</strong> Recursive function + <strong>defaultdict</strong>:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">def</span> <span style="color:#87cefa;">make_dict</span>():
    <span style="color:#00ffff;">return</span> defaultdict(make_dict)
</pre>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">from collections import defaultdict</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d = defaultdict(make_dict)</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;function make_dict at 0xb7c5295c&gt;, {})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r'] = 777</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;function make_dict at 0xb7c5295c&gt;, {'q': defaultdict(&lt;function make_dict at 0xb7c5295c&gt;, {'w': defaultdict(&lt;function make_dict at 0xb7c5295c&gt;, {'r': 777})})})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r']</span>
777
</pre>
<p><strong>3)</strong> And for fun you can use <a href="http://en.wikipedia.org/wiki/Y_combinator">Y Combinator</a> (in short &#8211; making anonymous lambda recursive) which is actually as (2) but you don&#8217;t have to have recursive function defined:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">def</span> <span style="color:#87cefa;">Y</span>(g):
    <span style="color:#00ffff;">return</span> ((<span style="color:#00ffff;">lambda</span> f: f(f))
            (<span style="color:#00ffff;">lambda</span> f:
                 g(<span style="color:#00ffff;">lambda</span> x: f(f)
                   (x))))

<span style="color:#eedd82;">defdict</span> = Y(<span style="color:#00ffff;">lambda</span> mk_dict:
                <span style="color:#00ffff;">lambda</span> x=<span style="color:#00ffff;">None</span>: defaultdict(<span style="color:#00ffff;">lambda</span> x=<span style="color:#00ffff;">None</span>: mk_dict(x)))
</pre>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d = defdict()</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;function &lt;lambda&gt; at 0xb7c52a74&gt;, {})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r'] = 777</span>
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d</span>
defaultdict(&lt;function &lt;lambda&gt; at 0xb7c52a74&gt;, {'q': defaultdict(&lt;function &lt;lambda&gt; at 0xb7c56c6c&gt;, {'w': defaultdict(&lt;function &lt;lambda&gt; at 0xb7c56a74&gt;, {'r': 777})})})
<span style="color:#00ffff;">&gt;&gt;&gt; </span><span style="font-weight:bold;">d['q']['w']['r']</span>
777
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ruslanspivak.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ruslanspivak.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=29&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2008/04/14/autovivication-and-y-combinator-in-python/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
		<item>
		<title>Array module in Erlang</title>
		<link>http://ruslanspivak.com/2008/04/13/array-module-in-erlang/</link>
		<comments>http://ruslanspivak.com/2008/04/13/array-module-in-erlang/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 03:47:14 +0000</pubDate>
		<dc:creator>Ruslan Spivak</dc:creator>
				<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://ruslanspivak.wordpress.com/?p=28</guid>
		<description><![CDATA[Recent Erlang releases (since R12B) have array module included.
Now binary search algorithm can be implemented quite  efficiently with functional arrays:

-module(bsa).
-export([binsearch/2]).

binsearch(Arr, Key) -&#62;
    binsearch(Arr, Key, 0, array:size(Arr)).

binsearch(Arr, Key, LowerBound, UpperBound) -&#62;
    Mid = (LowerBound + UpperBound) div 2,
    Item = array:get(Mid, Arr),
    if
 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=28&subd=ruslanspivak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recent Erlang releases (since R12B) have <a href="http://www.erlang.org/doc/man/array.html">array module</a> included.</p>
<p>Now <a href="http://ruslanspivak.com/2007/08/15/my-erlang-binary-search/">binary search</a> algorithm can be implemented quite  <a href="http://ruslanspivak.com/2007/08/17/more-about-binary-search-in-erlang/">efficiently</a> with functional arrays:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;">
<span style="color:#87cefa;">-module</span>(bsa).
<span style="color:#87cefa;">-export</span>([binsearch/2]).

<span style="color:#87cefa;">binsearch</span>(<span style="color:#eedd82;">Arr</span>, <span style="color:#eedd82;">Key</span>) -&gt;
    binsearch(<span style="color:#eedd82;">Arr</span>, <span style="color:#eedd82;">Key</span>, 0, array:<span style="color:#00ffff;">size</span>(<span style="color:#eedd82;">Arr</span>)).

<span style="color:#87cefa;">binsearch</span>(<span style="color:#eedd82;">Arr</span>, <span style="color:#eedd82;">Key</span>, <span style="color:#eedd82;">LowerBound</span>, <span style="color:#eedd82;">UpperBound</span>) -&gt;
    <span style="color:#eedd82;">Mid</span> = (<span style="color:#eedd82;">LowerBound</span> + <span style="color:#eedd82;">UpperBound</span>) div 2,
    <span style="color:#eedd82;">Item</span> = array:<span style="color:#00ffff;">get</span>(<span style="color:#eedd82;">Mid</span>, <span style="color:#eedd82;">Arr</span>),
    <span style="color:#00ffff;">if</span>
        <span style="color:#eedd82;">UpperBound</span> &lt; <span style="color:#eedd82;">LowerBound</span> -&gt;<span style="color:#87cefa;"> </span>-1;
        <span style="color:#eedd82;">Key</span> &lt; <span style="color:#eedd82;">Item</span> -&gt;
            binsearch(<span style="color:#eedd82;">Arr</span>, <span style="color:#eedd82;">Key</span>, <span style="color:#eedd82;">LowerBound</span>, <span style="color:#eedd82;">Mid</span>-1);
        <span style="color:#eedd82;">Key</span> &gt; <span style="color:#eedd82;">Item</span> -&gt;
            binsearch(<span style="color:#eedd82;">Arr</span>, <span style="color:#eedd82;">Key</span>, <span style="color:#eedd82;">Mid</span>+1, <span style="color:#eedd82;">UpperBound</span>);
        true -&gt;
            <span style="color:#eedd82;">Mid</span>
    <span style="color:#00ffff;">end</span>.
</pre>
<p>Running time for <em>lists based</em> binary search (just for comparison):</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;"><span style="color:#00ffff;">56&gt; </span><span style="font-weight:bold;">{Time, Val} = timer:tc(search, binsearch,</span>
<span style="color:#00ffff;">56&gt; </span><span style="font-weight:bold;">                       [lists:seq(1, 1000000), 1000000]).</span>
{506513,  1000000}</pre>
<p>Running time for <em>array based</em> binary search:</p>
<pre style="color:#ffffff;background-color:#000000;font-size:8pt;"><span style="color:#00ffff;">57&gt; </span><span style="font-weight:bold;">f().</span>
ok
<span style="color:#00ffff;">58&gt; </span><span style="font-weight:bold;">{Time, Val} = timer:tc(bsa, binsearch,</span>
<span style="color:#00ffff;">58&gt; </span><span style="font-weight:bold;">              [array:from_list(lists:seq(1, 1000000)), 1000000]).</span>
{17,  999999}</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ruslanspivak.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ruslanspivak.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ruslanspivak.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ruslanspivak.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ruslanspivak.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ruslanspivak.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ruslanspivak.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ruslanspivak.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ruslanspivak.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ruslanspivak.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ruslanspivak.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ruslanspivak.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ruslanspivak.com&blog=1522719&post=28&subd=ruslanspivak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ruslanspivak.com/2008/04/13/array-module-in-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4d73d92d1e35b86c5c45667b7a036da3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">alienoid</media:title>
		</media:content>
	</item>
	</channel>
</rss>