<?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"
	>

<channel>
	<title>Alexandre Vassalotti</title>
	<atom:link href="http://peadrop.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://peadrop.com/blog</link>
	<description>Random Computer Musings</description>
	<pubDate>Sat, 07 Jun 2008 19:32:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>How to not switch to Dvorak</title>
		<link>http://peadrop.com/blog/2007/12/30/how-to-not-switch-to-dvorak/</link>
		<comments>http://peadrop.com/blog/2007/12/30/how-to-not-switch-to-dvorak/#comments</comments>
		<pubDate>Sun, 30 Dec 2007 23:52:38 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Me]]></category>

		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/12/30/how-to-not-switch-to-dvorak/</guid>
		<description><![CDATA[Once in a while, I practice to improve my touch typing skills. Most of
the time, I just find some online stuff or use KTouch. But today, I
wanted to try something different. I always hear good things about the
Dvorak keyboard layout &#8212; i.e., how it&#8217;s supposedly more efficient and
more comfortable than the Qwerty layout. Being a [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while, I practice to improve my touch typing skills. Most of
the time, I just find some online stuff or use KTouch. But today, I
wanted to try something different. I always hear good things about the
Dvorak keyboard layout &#8212; i.e., how it&#8217;s supposedly more efficient and
more comfortable than the Qwerty layout. Being a curious person, I
wanted to test this out.</p>

<p>So when I opened up KTouch, I selected the Dvorak lecture, instead of
the typical Qwerty one. The first lessons were fairly easy. As I went
through the lecture, I managed to keep a fairly high pace and accuracy &#8211;
i.e., about 210 characters per minute with a 95% accuracy. About at
the fifth or sixth lesson, I said to myself: &#8220;Wow, I must have been a
Dvorak typist in another life.&#8221; I was really impressed how quickly I
had learnt the basics of the layout and I was indeed starting to
believe that the Dvorak layout was vastly superior to Qwerty.</p>

<p>Shortly after, I was sold. At this point, I was thinking how
was going to remap my Emacs key bindings. <img src='http://peadrop.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>However, when I got to the tenth lesson, I found something strange,
very strange. The letter &#8216;q&#8217; on the Dvorak layout was in the upper row
on the left &#8212; exactly where it is on the Qwerty layout.</p>

<p>I stopped typing for a second&#8230;</p>

<p>&#8230;and look at the keyboard displayed on the screen.</p>

<p>&#8220;asdf asdf asdf&#8221;</p>

<p>Oops! I had forgot the change the actual layout of my keyboard. So, I
was still using Qwerty.</p>

<p>Now, I realize that I have been victim of what they call the &#8220;placebo
effect&#8221;. This little anecdote has certainly thought me to be more
careful, in the future, when trying something new sold has &#8220;better&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/12/30/how-to-not-switch-to-dvorak/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Shell tricks: shorthands</title>
		<link>http://peadrop.com/blog/2007/10/18/shell-tricks-shorthands/</link>
		<comments>http://peadrop.com/blog/2007/10/18/shell-tricks-shorthands/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 16:20:55 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Tutorials]]></category>

		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/10/18/shell-tricks-shorthands/</guid>
		<description><![CDATA[Even with tab completion, typing long commands is tedious. But,
there&#8217;s something even worst: typing the same long commands again, and
again, and again&#8230; So how do you solve that? It&#8217;s simple: you shorten
them. Surprising, uh? Okay enough theory, let me show you some
examples.

Here&#8217;s a tedious command of Type-A:

% sudo aptitude install zsh


Look at it carefully since [...]]]></description>
			<content:encoded><![CDATA[<p>Even with tab completion, typing long commands is tedious. But,
there&#8217;s something even worst: typing the same long commands again, and
again, and again&#8230; So how do you solve that? It&#8217;s simple: you shorten
them. Surprising, uh? Okay enough theory, let me show you some
examples.</p>

<p>Here&#8217;s a tedious command of Type-A:</p>

<pre><code>% sudo aptitude install zsh
</code></pre>

<p>Look at it carefully since you will need to hunt these long commands
down until none remains. Now, let me explain how you execute a such
command. Open up your personal shell initialization file
(e.g. <code>~/.bashrc</code> for Bash, <code>~/.zshrc</code> for Zsh, etc). Then, add the
following:</p>

<pre><code class="prettyprint">alias spkgi="sudo aptitude install"</code></pre>

<p>Reload your shell and finally, enjoy:</p>

<pre><code>% spkgi zsh
</code></pre>

<p>Now I can introduce, as you can deduce, other shorten commands that
you can produce and reproduce:</p>

<pre><code class="prettyprint"># Package Management
alias pkg="aptitude"
alias spkg="sudo aptitude"
alias spkgi="sudo aptitude install"
alias spkgu="sudo aptitude safe-upgrade"
alias spkgr="sudo aptitude remove"
alias spkgd="sudo apt-get build-dep"

# Miscellaneous Helpers
alias nc="rlwrap nc"
alias e=$EDITOR
alias se=sudoedit
alias reload="source ~/.zshrc"
alias g=egrep

# To produce annoying alliterations <img src='http://peadrop.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> alias alli="cat /usr/share/dict/words | grep"</code></pre>

<p>Next after Type-A tedious commands, we have the Type-S ones. To
execute these, you will you need some sort of special shell
support. So, here&#8217;s some examples of the Type-S monstrosity:</p>

<pre><code>% find Lib/ -name '*.c' -print0 | xargs -0 grep ^PyErr
% find -name '*.html' -print0 | xargs -0 rename 's/\.html$/.var/'
% find -name '*.patch' -print0 | xargs -0 -I {} cp {} patches/
</code></pre>

<p>I hope you start to see some patterns (if you don&#8217;t, then try
harder). The first one could (and should) be rewritten as:</p>

<pre><code>% rgrep --include='*.c' ^PyErr Lib/
</code></pre>

<p>But that isn&#8217;t short enough for me, so I have a short helper:</p>

<pre><code class="prettyprint">rg()
{
    filepat="$1"
    pat="$2"
    shift 2
    grep -Er --include=$filepat $pat ${@:-.}
}
# In Zsh, 'noglob' turns off globing.
# (e.g, "noglob echo *" outputs "*")
alias rg='noglob rg'</code></pre>

<p>It is lovely to use:</p>

<pre><code>% rg *.c ^PyErr Lib/
% rg *.c PyErr_Restore . -C 10 | less
% rg *.[ch] stringlib
% rg *.c ^[a-zA-Z]*_dealloc Modules/ Objects/
</code></pre>

<p>The second example is quite similar to the previous one. However, the
find/rename combination is much less common (at least for me) than the
find/grep one. This one needs to be broken in pieces. One obvious thing
to factor out is the <code>find -name</code> with an alias:</p>

<pre><code class="prettyprint">alias fname="noglob find -name"</code></pre>

<p>Using this alias, you can rewrite the second example as:</p>

<pre><code>% fname *.html -print0 | xargs -0 rename 's/\.html$/.var/'
</code></pre>

<p>It&#8217;s better, but it&#8217;s not short enough yet. The ugly part of this
command is the <code>-print0 | xargs -0</code>. I hate to type that. Wouldn&#8217;t
it be nice if we could define an alias for it? How about:</p>

<pre><code class="prettyprint">alias each="-print0 | xargs -0"</code></pre>

<p>Unfortunately, that doesn&#8217;t work since aliases are only expanded if
they are in the command position. Luckly, Zsh has that neat feature
called global aliases, which does exactly what we want.</p>

<pre><code class="prettyprint">alias -g each="-print0 | xargs -0"</code></pre>

<p>With this feature of Zsh, the second example become:</p>

<pre><code>% fname *.html each rename 's/\.html$/.var/'
</code></pre>

<p>Now, we can also attack the third one:</p>

<pre><code>% fname *.patch each -I {} cp {} patches/
</code></pre>

<p>It is possible to shorten a bit by defining another alias combining
<code>each</code> and <code>-I {}</code>, but that won&#8217;t make a big difference.</p>

<p>Finally, there are the Type-R tedious commands. These are hard to
avoid, unless you&#8217;re careful. Here&#8217;s again some ridiculous examples to
help you recognize these redundant commands:</p>

<pre><code>% gcc -o stackgrow stackgrow.c
% pkg show emacs-snapshot-bin-common emacs-snapshot-common emacs-snapshot-gtk emacs-snapshot
% cat ../lispref.patch ../lwlib.patch ../etc.patch | patch -p1
</code></pre>

<p>To reduce these, you don&#8217;t need change your shell configuration; you
change your habits instead. Using alternations (which are
non-standard, but supported by most shells), you can rewrite the two
first example as:</p>

<pre><code>% gcc -o stackgrow{,.c}
% pkg show emacs-snapshot{{-bin,}-common,-gtk,}
</code></pre>

<p>Now, you are surely asking yourself: &#8220;what is different about the
third one?&#8221; Well, think about it. Got it? No? Ah, come on, it is
easy. Here&#8217;s a hint:</p>

<pre><code>% echo 'cat ../{lispref,lwlib,etc}.patch | patch -p1' | wc -c
45
% echo 'cat ../lispref.patch ../lwlib.patch ../etc.patch | patch -p1' | wc -c
61
</code></pre>

<p>You like my hint, don&#8217;t you? Here&#8217;s the answer:</p>

<pre><code>% echo 'cat ../li\t ../lw\t ../et\t | patch -p1' | wc -c
37
</code></pre>

<p>Tab completion doesn&#8217;t work well with prefix alternations. Even if the
command using alternation is shorter, it still doesn&#8217;t beat good old
tab completion.</p>

<p>And that&#8217;s all folks. I surely have plenty of other tricks to show,
but that will be for the other posts of this short series.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/10/18/shell-tricks-shorthands/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pretty Emacs Reloaded</title>
		<link>http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/</link>
		<comments>http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 05:08:47 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Emacs]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/</guid>
		<description><![CDATA[My popular1 Pretty Emacs package just got a tad better.  I
transferred the package to the brand new PPA service provided by
Launchpad. So, what&#8217;s new about the package? First, I glad to announce
the long-awaited amd64 support. Also, I am adding Gutsy Gibbon to the
list of supported distributions.

To use the updated package on Ubuntu 6.10 &#8220;Edgy [...]]]></description>
			<content:encoded><![CDATA[<p>My popular<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> <a href="http://peadrop.com/blog/2007/01/06/pretty-emacs/">Pretty Emacs</a> package just got a tad better.  I
transferred the package to the brand new <a href="https://help.launchpad.net/PPAQuickStart">PPA service</a> provided by
Launchpad. So, what&#8217;s new about the package? First, I glad to announce
the long-awaited amd64 support. Also, I am adding Gutsy Gibbon to the
list of supported distributions.</p>

<p>To use the updated package on Ubuntu 6.10 &#8220;Edgy Eft&#8221;, add the
following lines to your <code>/etc/apt/sources.list</code> file:</p>

<pre><code>deb     http://ppa.launchpad.net/avassalotti/ubuntu edgy main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu edgy main
</code></pre>

<p>To use the package on Ubuntu 7.04 &#8220;Feisty Fawn&#8221;, add the following
lines to your <code>/etc/apt/sources.list</code> file:</p>

<pre><code>deb     http://ppa.launchpad.net/avassalotti/ubuntu feisty main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu feisty main
</code></pre>

<p>To use the package on the development version of Ubuntu &#8220;Gutsy
Gibbon&#8221;, add the following lines to your <code>/etc/apt/sources.list</code> file:</p>

<pre><code>deb     http://ppa.launchpad.net/avassalotti/ubuntu gutsy main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu gutsy main
</code></pre>

<p>Unfortunately, if you still use Ubuntu 6.06 &#8220;Dapper Drake&#8221;, you will
have to keep using the older package release from my orignal
repository. I still support Ubuntu 6.06, but I won&#8217;t update the
package with newer snapshots.</p>

<p>After adding the repository to your software source list, upgrade your
version of the package with:</p>

<pre><code>sudo aptitude upgrade
</code></pre>

<p>If you do not have a previous version of the package already installed
and you desire to install it, do this instead:</p>

<pre><code>sudo aptitude install emacs-snapshot emacs-snapshot-el
</code></pre>

<p>When upgrading the package you might get the following warning
message:</p>

<pre><code>WARNING: untrusted versions of the following packages will be installed!

Untrusted packages could compromise your system's security.
You should only proceed with the installation if you are certain that
this is what you want to do.
</code></pre>

<p>This is due to <a href="https://bugs.launchpad.net/soyuz/+bug/125103">a bug</a> in the PPA system. I believe that it will be
resolved quickly. So, you can safely ignore the warning message for
the moment.</p>

<p>Final note, thank you everyone for trusting me and giving me some
great feedback about the package. I like to give special thanks to
<a href="http://orebokech.com/">Romain Francoise</a> and <a href="http://mwolson.org/">Michael Olson</a> for their work respectively on
emacs-snapshot and emacs22, during this summer.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>A rough estimate tell me there is over 30&#8197;000 people using my
package, where 88% of them are Feisty Fawn users and 11% are Edgy Eft
users.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Minor annoyance with Planet</title>
		<link>http://peadrop.com/blog/2007/07/06/minor-annoyance-with-planet/</link>
		<comments>http://peadrop.com/blog/2007/07/06/minor-annoyance-with-planet/#comments</comments>
		<pubDate>Fri, 06 Jul 2007 21:31:44 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/07/06/minor-annoyance-with-planet/</guid>
		<description><![CDATA[

Do you know how to fix Planet or Wordpress, so when I edit an old post it does not pop back on Planet?

I do edit some of my posts,  in particular the Pretty Emacs one, fairly often. I love to have my blog aggregated, but I would hate spamming Planet Ubuntu readers with my [...]]]></description>
			<content:encoded><![CDATA[<div></div>

<p>Do you know how to fix Planet or Wordpress, so when I edit an old post it does not pop back on Planet?</p>

<p>I do edit some of my posts,  in particular the <a href="http://peadrop.com/blog/2007/01/06/pretty-emacs/">Pretty Emacs</a> one, fairly often. I love to have my blog aggregated, but I would hate spamming Planet Ubuntu readers with my old posts. Therefore if I cannot fix this little annoyance, I will have no other choice to remove myself from Planet Ubuntu.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/07/06/minor-annoyance-with-planet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Summer of Code Weekly #4</title>
		<link>http://peadrop.com/blog/2007/07/06/summer-of-code-weekly-4/</link>
		<comments>http://peadrop.com/blog/2007/07/06/summer-of-code-weekly-4/#comments</comments>
		<pubDate>Fri, 06 Jul 2007 19:16:35 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/07/06/summer-of-code-weekly-4/</guid>
		<description><![CDATA[

All is well for me and my project.  I finished the merge of
cStringIO and StringIO, and I am now moving to the more challenging
cPickle/pickle merge.  During the last two weeks, I mostly spend my
time analyzing the pickle module and thinking how I will clean up
cPickle.  My current plan is:


Make cPickle&#8217;s source code [...]]]></description>
			<content:encoded><![CDATA[<div></div>

<p>All is well for me and my project.  I finished the merge of
cStringIO and StringIO, and I am now moving to the more challenging
cPickle/pickle merge.  During the last two weeks, I mostly spend my
time analyzing the <code>pickle</code> module and thinking how I will clean up
cPickle.  My current plan is:</p>

<ol>
<li>Make cPickle&#8217;s source code conform to <a href="http://www.python.org/dev/peps/pep-0007/">PEP-7</a>.</li>
<li>Remove the dependency on the now obsolete cStringIO.</li>
<li>Benchmark cPickle and pickle.</li>
<li>Add subclassing support to Pickler/Unpickler.</li>
<li>Reduce the size of cPickle&#8217;s source code based on the bottlenecks
  found by the benchmarks.</li>
</ol>

<p>Hopefully, cPickle/pickle merge will be as smooth (and as fun) as the
cStringIO/StringIO merge.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/07/06/summer-of-code-weekly-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pickle: An interesting stack language</title>
		<link>http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/</link>
		<comments>http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 18:14:17 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/</guid>
		<description><![CDATA[The pickle module provides a convenient method to add data
persistence to your Python programs.  How it does that, is pure magic
to most people.  However, in reality, it is simple.  The output of a
pickle is a &#8220;program&#8221; able to create Python data-structures.  A
limited stack language is used to write these programs.  [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>pickle</code> module provides a convenient method to add data
persistence to your Python programs.  How it does that, is pure magic
to most people.  However, in reality, it is simple.  The output of a
<code>pickle</code> is a &#8220;program&#8221; able to create Python data-structures.  A
limited stack language is used to write these programs.  By limited, I
mean you can&#8217;t write anything fancy like a for-loop or an
if-statement.  Yet, I found it interesting to learn.  That is why I
would like to share my little discovery.</p>

<p>Throughout this post, I use a simple interpreter to load pickle
streams.  Just copy-and-paste the following code in a file:</p>

<pre><code class="prettyprint">import code
import pickle
import sys

sys.ps1 = "pik> "
sys.ps2 = "...> "
banner = "Pik -- The stupid pickle loader.\nPress Ctrl-D to quit."

class PikConsole(code.InteractiveConsole):
    def runsource(self, source, filename="&lt;stdin&gt;"):
        if not source.endswith(pickle.STOP):
            return True  # more input is needed
        try:
            print repr(pickle.loads(source))
        except:
            self.showsyntaxerror(filename)
        return False

pik = PikConsole()
pik.interact(banner)</code></pre>

<p>Then, launch it with Python:</p>

<pre><code>$ python pik.py
Pik -- The stupid pickle loader.
Press Ctrl-D to quit.
pik&gt;
</code></pre>

<p>So, nothing crazy <em>yet</em>.  The easiest objects to create are the empty
ones.  For example, to create an empty list:</p>

<pre><code>pik&gt; ].
[]
</code></pre>

<p>Similarly, you can also create a dictionary and a tuple:</p>

<pre><code>pik&gt; }.
{}
pik&gt; ).
()
</code></pre>

<p>Remark that every pickle stream ends with a period.  That symbol pops
the topmost object from the stack and returns it.  So, let&#8217;s say you
pile up a series of integers and end the stream. Then, the result will
be last item you entered:</p>

<pre><code>pik&gt; I1
...&gt; I2
...&gt; I3
...&gt; .
3
</code></pre>

<p>As you see, an integer starts with the symbol &#8216;I&#8217; and end with a
newline. Strings, and floating-point number are represented in a
similar fashion:</p>

<pre><code>pik&gt; F1.0
...&gt; .
1.0
pik&gt; S'abc'
...&gt; .
'abc'
pik&gt; Vabc
...&gt; .
u'abc'
</code></pre>

<p>Now that you know the basics, we can move to something slightly more
complex &#8212; constructing compound objects. As you will see later,
tuples are everywhere in Python, so let&#8217;s begin with that one:</p>

<pre><code>pik&gt; (I1
...&gt; S'abc'
...&gt; F2.0
...&gt; t.
(1, 'abc', 2.0)
</code></pre>

<p>There is two new symbols in this example, &#8216;(&#8217; and &#8216;t&#8217;. The &#8216;(&#8217; is
simply a marker.  It is a object in the stack that tells the tuple
builder, &#8216;t&#8217;, when to stop.  The tuple builder pops items from
the stack until it reaches a marker.  Then, it creates a tuple with
these items and pushes this tuple back on the stack.  You can use
multiple markers to construct a nested tuple:</p>

<pre><code>pik&gt; (I1
...&gt; (I2
...&gt; I3
...&gt; tt.
(1, (2, 3))
</code></pre>

<p>You use a similar method to build a list or a dictionary:</p>

<pre><code>pik&gt; (I0
...&gt; I1
...&gt; I2
...&gt; l.
[0, 1, 2]
pik&gt; (S&#8217;red&#8217;
&#8230;&gt; I00
&#8230;&gt; S&#8217;blue&#8217;
&#8230;&gt; I01
&#8230;&gt; d.
{&#8217;blue&#8217;: True, &#8216;red&#8217;: False}
</code></pre>

<p>The only difference is that dictionary items are packed by key/value
pairs.  Note that I slipped in the symbols for <code>True</code> and <code>False</code>,
which looks like the integers 0 and 1, but with an extra zero.</p>

<p>Like tuples, you can nest lists and dictionaries:</p>

<pre><code>pik&gt; ((I1
...&gt; I2
...&gt; t(I3
...&gt; I4
...&gt; ld.
{(1, 2): [3, 4]}
</code></pre>

<p>There is another method for creating lists or dictionaries.  Instead
of using a marker to delimit a compound object, you create an empty one
and add stuff to it:</p>

<pre><code>pik&gt; ]I0
...&gt; aI1
...&gt; aI2
...&gt; a.
[0, 1, 2]
</code></pre>

<p>The symbols &#8216;a&#8217; means &#8220;append&#8221;.  It pops an item and a list; appends
the item to the list; and finally, pushes the list back on the stack.
Here how you do a nested list with this method:</p>

<pre><code>pik&gt; ]I0
...&gt; a]I1
...&gt; aI2
...&gt; aa.
[0, [1, 2]]
</code></pre>

<p>If this is not cryptic enough for you, consider this:</p>

<pre><code>pik&gt; (lI0
...&gt; a(lI1
...&gt; aI2
...&gt; aa.
[0, [1, 2]]
</code></pre>

<p>Instead of using the empty list symbol, &#8216;]&#8217;, I used a marker
immediately followed by a list builder to create an empty list.  That
is the notation the <code>Pickler</code> object uses, by default, when dumping
objects.</p>

<p>Like lists, dictionaries can be constructed using a similar method:</p>

<pre><code>pik&gt; }S'red'
...&gt; I1
...&gt; sS'blue'
...&gt; I2
...&gt; s.
{'blue': 2, 'red': 1}
</code></pre>

<p>However, to set items to a dictionary you use the symbol &#8217;s&#8217;, not &#8216;a&#8217;.
Unlike &#8216;a&#8217;, it takes a key/value pair instead of a single item.</p>

<p>You can build recursive data-structures, too:</p>

<pre><code>pik&gt; (Vzoom
...&gt; lp0
...&gt; g0
...&gt; a.
[u'zoom', [...]]
</code></pre>

<p>The trick is to use a &#8220;register&#8221; (or as called in <code>pickle</code>, a memo).
The &#8216;p&#8217; symbol (for &#8220;put&#8221;) copies the top item of the stack in a memo.
Here, I used &#8216;0&#8242; for the name of the memo, but it could have been
anything.  To get the item back, you use the symbol &#8216;g&#8217;.  It will
copy an item from a memo and put it on top of the stack.</p>

<p>But, what about sets?  Now, we have a small problem, since there is no
special notation for building sets.  The only way to build a set is to
call the built-in function <code>set()</code> on a list (or a tuple):</p>

<pre><code>pik&gt; c__builtin__
...&gt; set
...&gt; ((S'a'
...&gt; S'a'
...&gt; S'b'
...&gt; ltR.
set(['a', 'b'])
</code></pre>

<p>There is a few new things here.  The &#8216;c&#8217; symbol retrieves an object
from a module and puts it on the stack.  And the reduce symbol, &#8216;R&#8217;,
apply a tuple to a function.  Same semantic again, &#8216;R&#8217; pops a tuple
and a function from the stack, then pushes the result back on it.  So,
the above example is roughly the equivalent of the following in
Python:</p>

<pre><code>&gt;&gt;&gt; import __builtin__
&gt;&gt;&gt; apply(__builtin__.set, (['a', 'a', 'b'],))
</code></pre>

<p>Or, using the star notation:</p>

<pre><code>&gt;&gt;&gt; __builtin__.set(*(['a', 'a', 'b'],))
</code></pre>

<p>And, that is the same thing as writing:</p>

<pre><code>&gt;&gt;&gt; set(['a', 'a', 'b'])
</code></pre>

<p>Or shorter even, using the set notation from the upcoming Python 3000:</p>

<pre><code>&gt;&gt;&gt; {'a', 'a', 'b'}
</code></pre>

<p>These two new symbols, &#8216;t&#8217; and &#8216;R&#8217;, allows us to execute arbitrary
code from the standard library.  So, you must be careful to <em>never</em>
load untrusted pickle streams.  Someone malicious could easily slip in
the stream a command to delete your data.  Meanwhile, you can use that
power for something less evil, like launching a clock:</p>

<pre><code>pik&gt; cos
...&gt; system
...&gt; (S'xclock'
...&gt; tR.
</code></pre>

<p>Even if the language doesn&#8217;t support looping directly, that doesn&#8217;t
stop you from using the implicit loops:</p>

<pre><code>pik&gt; c__builtin__
...&gt; map
...&gt; (cmath
...&gt; sqrt
...&gt; c__builtin__
...&gt; range
...&gt; (I1
...&gt; I10
...&gt; tRtR.
[1.0, 1.4142135623730951, 1.7320508075688772, 2.0, 2.2360679774997898,
2.4494897427831779, 2.6457513110645907, 2.8284271247461903, 3.0]
</code></pre>

<p>I am sure you could you fake an if-statement by defining it as a
function, and then load it from a module.</p>

<pre><code class="prettyprint">def my_if(cond, then_val, else_val):
    if cond:
        return then_val
    else:
        return else_val</code></pre>

<p>That works well for simple cases:</p>

<pre><code>&gt;&gt;&gt; my_if(True, 1, 0)
1
&gt;&gt;&gt; my_if(False, 1, 0)
0
</code></pre>

<p>However, you run into some problems if mix that with recursion:</p>

<pre><code>&gt;&gt;&gt; def factorial(n):
...     return my_if(n == 1,
...                  1, n * factorial(n - 1))
...
&gt;&gt;&gt; factorial(2)
RuntimeError: maximum recursion depth exceeded in cmp
</code></pre>

<p>On the other hand, I don&#8217;t think you really want to create recursive
pickle streams, unless you want to win an obfuscated code contest.</p>

<p>That is about all I had to say about this simple stack language.
There is a few things haven&#8217;t told you about, but I sure you will be
able figure them out.  Just read the source code of the <code>pickle</code>
module.  And, take a look at the <code>pickletools</code> module,
which provides a disassembler for pickle streams.  As always, comments
are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Summer of Code Weekly #3</title>
		<link>http://peadrop.com/blog/2007/06/07/summer-of-code-weekly-3/</link>
		<comments>http://peadrop.com/blog/2007/06/07/summer-of-code-weekly-3/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 00:55:14 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/06/07/summer-of-code-weekly-3/</guid>
		<description><![CDATA[During this third week of the Summer of Code, I found very
difficult to concentrate on my work &#8212; I been a lightbulb
instead of a laser. The result was little code done. On the other
hand, I learned a lot about other things. For example, I now finally
understand assembly language; how to use gdb; the basics of [...]]]></description>
			<content:encoded><![CDATA[<p>During this third week of the Summer of Code, I found very
difficult to concentrate on my work &#8212; I been a lightbulb
instead of a laser. The result was little code done. On the other
hand, I learned a lot about other things. For example, I now finally
understand assembly language; how to use <code>gdb</code>; the basics of the
design of the Linux kernel; etc, etc.</p>

<p>I also read the book &#8220;Producing Open Source Software&#8221;, by Karl Fogel.
It is really good primer to the world of free software. If you have a
burning desire to contribute open source projects, just like me, I
highly recommend that you get your own copy, or read it
<a href="http://producingoss.com/">online</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/06/07/summer-of-code-weekly-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Summer of Code Weekly #2</title>
		<link>http://peadrop.com/blog/2007/05/31/summer-of-code-weekly-2/</link>
		<comments>http://peadrop.com/blog/2007/05/31/summer-of-code-weekly-2/#comments</comments>
		<pubDate>Thu, 31 May 2007 23:51:29 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/05/31/summer-of-code-weekly-2/</guid>
		<description><![CDATA[I can confirm it now, this second week of coding was even better. It
was harder on my brain cells, though. I am mostly done with the
StringIO merge. I now have working implementations in C of the BytesIO
and the StringIO objects. The only thing remaining to do, for these
two modules, is polishing the unit tests. And [...]]]></description>
			<content:encoded><![CDATA[<p>I can confirm it now, this second week of coding was even better. It
was harder on my brain cells, though. I am mostly done with the
StringIO merge. I now have working implementations in C of the BytesIO
and the StringIO objects. The only thing remaining to do, for these
two modules, is polishing the unit tests. And that shouldn&#8217;t that me
very long to do. So, in basically one week of work, I completed the
merge of cStringIO. I am certainly proud of that.</p>

<p>Now, I will need to attack the cPickle and cProfile modules. I don&#8217;t
know yet which I work on first. cPickle still seems very scary to me,
and unlike cStringIO it&#8217;s huge. It&#8217;s about five or six times bigger.
cProfile, on the other hand, is about the same size of cStringIO and
well documented. I even wonder if I need to code anything for
cProfile. It will be a piece of cake to merge. Now, one question
remains: should I take the cake now, or keep it for the end?</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/05/31/summer-of-code-weekly-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Summer of Code Weekly #1</title>
		<link>http://peadrop.com/blog/2007/05/24/summer-of-code-weekly-1/</link>
		<comments>http://peadrop.com/blog/2007/05/24/summer-of-code-weekly-1/#comments</comments>
		<pubDate>Fri, 25 May 2007 03:14:37 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/05/24/summer-of-code-weekly-1/</guid>
		<description><![CDATA[During this summer, I will post each week a short summary of what I
did, the challenges I encountered and what I learned during
my Summer of Code project. I am doing this for helping me to keep track of my
progresses.

So how was my first week? It was great. I don&#8217;t know why but I
love programming in [...]]]></description>
			<content:encoded><![CDATA[<p>During this summer, I will post each week a short summary of what I
did, the challenges I encountered and what I learned during
<a href="http://code.google.com/soc/psf/appinfo.html?csaid=C6768E09BEF7CCE2">my Summer of Code project</a>. I am doing this for helping me to keep track of my
progresses.</p>

<p>So how was my first week? It was great. I don&#8217;t know why but I
love programming in C. It is just plain fun. I thought learning Python
C API was going to be hard, but it is quite easy after all. I just read the
code in Python itself and check the <a href="http://docs.python.org/api/">reference manual</a> for the things
I don&#8217;t know. My biggest surprise, this week, was really learning how to do
subclassable types. It is strikingly easy, however it&#8217;s quite verbose.
You can look at <a href="http://peadrop.com/files/spammodule.c.html">my scratch extension module</a>, if you want a minimal
working example.</p>

<p>Other than learning the C API, I started working on the
cStringIO/StringIO merge. My current plan is to separate the cStringIO
module into two private submodules, <code>_bytes_io</code> and <code>_string_io</code>. One will
be for bytes literals (ASCII), and the other for Unicode.
This will reflect the changes made to the I/O subsystem in Python 3000.
These two submodules will provide optional implementations for the
speed-critical methods, like <code>.read()</code> and <code>.write()</code>.</p>

<p>One the best things, of this week, was the great feedback I got
from other Python developers, and particularly from my mentor Brett
Cannon, who cheerfully answers all my questions. Now, I just hope the
following week will be as fun, or even more, as this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/05/24/summer-of-code-weekly-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Blogging with Emacs</title>
		<link>http://peadrop.com/blog/2007/05/11/blogging-with-emacs/</link>
		<comments>http://peadrop.com/blog/2007/05/11/blogging-with-emacs/#comments</comments>
		<pubDate>Sat, 12 May 2007 04:08:43 +0000</pubDate>
		<dc:creator>Alexandre</dc:creator>
		
		<category><![CDATA[Emacs]]></category>

		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://peadrop.com/blog/2007/05/11/blogging-with-emacs/</guid>
		<description><![CDATA[This is my first blog entry with my brand new toy, the weblogging
mode for Emacs. It uses the XML-RPC interface of your favorite
blogging platform to manage your blog. In other words, it transformes
Emacs into a thermonuclear blog editor.

Even better, the installation is simple and easy. Here&#8217;s the instructions
how to get it working. First, check out
the [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first blog entry with my brand new toy, the <a href="http://savannah.nongnu.org/projects/emacsweblogs">weblogging
mode</a> for Emacs. It uses the <a href="http://www.xmlrpc.com/">XML-RPC</a> interface of your favorite
blogging platform to manage your blog. In other words, it transformes
Emacs into a thermonuclear blog editor.</p>

<p>Even better, the installation is simple and easy. Here&#8217;s the instructions
how to get it working. First, check out
the source code of weblogger into your <code>.emacs.d</code> directory:</p>

<pre><code>cd ~/.emacs.d/
cvs -z3 -d:pserver:anonymous@cvs.savannah.nongnu.org:/sources/emacsweblogs \
  co -d weblogger weblogger/lisp
</code></pre>

<p>Then, make Emacs load this mode on startup by adding these two lines to your
<code>.emacs</code> configuration:</p>

<pre><code>(add-to-list 'load-path "~/.emacs.d/weblogger")
(require 'weblogger)
</code></pre>

<p>Now, you probably want to reload your configuration with <code>M-x
eval-buffer</code> (assuming your <code>.emacs</code> is still open). Finally, setup
weblogger for your blog with <code>M-x weblogger-setup-weblog</code>. This
command will ask you a few simple questions, like your username and
password for your blog. It will also ask you for the location of the
XML-RPC interface of your blog. If you&#8217;re using Wordpress, it will be
somewhere like <code>http://example.com/blog/xmlrpc.php</code>. If you&#8217;re using
another blog publishing platform like Blogger or MovableType, it will
be somewhere else, so check your documentation.</p>

<p>And you&#8217;re done! You can now start new a new post with <code>M-x
weblogger-start-entry</code>. Weblogger also includes a whole set of other
commands for managing your blog. Look them up, with <code>C-h a weblogger
RET</code>. Happy blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://peadrop.com/blog/2007/05/11/blogging-with-emacs/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.038 seconds -->
<!-- Cached page served by WP-Cache -->
