<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Advogato blog for avassalotti</title>
    <link>http://www.advogato.org/person/avassalotti/</link>
    <description>Advogato blog for avassalotti</description>
    <language>en-us</language>
    <generator>mod_virgule</generator>
    <pubDate>Mon, 13 Oct 2008 23:31:18 GMT</pubDate>
    <item>
      <pubDate>Mon, 31 Dec 2007 00:06:01 GMT</pubDate>
      <title>How to not switch to Dvorak</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=36</link>
      <guid>http://peadrop.com/blog/2007/12/30/how-to-not-switch-to-dvorak/</guid>
      <description>&lt;p&gt;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 &amp;#8212; i.e., how it&amp;#8217;s supposedly more efficient and
more comfortable than the Qwerty layout. Being a curious person, I
wanted to test this out.&lt;/p&gt;

&lt;p&gt;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 pace and accuracy &amp;#8212;
i.e., about 210 characters per minute with a 95% accuracy. About at
the fifth or sixth lesson, I said to myself: &amp;#8220;Wow, I must have been a
Dvorak typist in another life.&amp;#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.&lt;/p&gt;

&lt;p&gt;Shortly after, I was sold. At this point, I was thinking how
was going to remap my Emacs key bindings. :-)&lt;/p&gt;

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

&lt;p&gt;I stop typing for a second&amp;#8230;&lt;/p&gt;

&lt;p&gt;&amp;#8230;and look at the keyboard displayed on the screen.&lt;/p&gt;

&lt;p&gt;&amp;#8220;asdf asdf asdf&amp;#8221;&lt;/p&gt;

&lt;p&gt;Oops! I had forgot the change the actual layout of my keyboard. So, I
was still using Qwerty.&lt;/p&gt;

&lt;p&gt;Now, I realize that I have been victim of what they call the &amp;#8220;placebo
effect&amp;#8221;. This little anecdote has certainly thought me to be more
careful, in the future, when trying something new sold has &amp;#8220;better&amp;#8221;.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 14 Dec 2007 22:06:11 GMT</pubDate>
      <title>Changing</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=35</link>
      <guid>http://peadrop.com/blog/2007/12/14/changing/</guid>
      <description>&lt;p&gt;It been a while since I have written a blog post. It&amp;#8217;s not that I
haven&amp;#8217;t tried, or that I am lacking of ideas. It&amp;#8217;s just that these
things take forever to write. I found the hard way that
perfectionism is the enemy of getting things done (or in fact to get
them started in the first place).&lt;/p&gt;

&lt;p&gt;So now that I got a bunch of half-finished blog posts that I won&amp;#8217;t ever
finish, what should I do with them?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debian Packaging 101 (Part 2)&lt;/li&gt;
&lt;li&gt;Great books for young programmers&lt;/li&gt;
&lt;li&gt;Playing with memory&lt;/li&gt;
&lt;li&gt;ICFP 2007: Entangled in strings&lt;/li&gt;
&lt;li&gt;Summer of Code 2007: Final thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, I guess that is my chance to start breaking my perfectionism habits
and put them &lt;a href="http://peadrop.com/unwritten/" &gt;on the web&lt;/a&gt;. (When I said &amp;#8220;half-finished&amp;#8221; I really meant it, by the way).&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 18 Oct 2007 17:04:52 GMT</pubDate>
      <title>Shell tricks: shorthands</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=34</link>
      <guid>http://peadrop.com/blog/2007/10/18/shell-tricks-shorthands/</guid>
      <description>&lt;p&gt;Even with tab completion, typing long commands is tedious. But,
there&amp;#8217;s something even worst: typing the same long commands again, and
again, and again&amp;#8230; So how do you solve that? It&amp;#8217;s simple: you shorten
them. Surprising, uh? Okay enough theory, let me show you some
examples.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a tedious command of Type-A:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% sudo aptitude install zsh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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. &lt;code&gt;~/.bashrc&lt;/code&gt; for Bash, &lt;code&gt;~/.zshrc&lt;/code&gt; for Zsh, etc). Then, add the
following:&lt;/p&gt;

&lt;pre&gt;&lt;code class="prettyprint"&gt;alias spkgi="sudo aptitude install"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reload your shell and finally, enjoy:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% spkgi zsh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now I can introduce, as you can deduce, other shorten commands that
you can produce and reproduce:&lt;/p&gt;

&lt;pre&gt;&lt;code class="prettyprint"&gt;# 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 &lt;img src='http://peadrop.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /&gt; 
alias alli="cat /usr/share/dict/words | grep"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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&amp;#8217;s some examples of the Type-S monstrosity:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% 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/
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;% rgrep --include='*.c' ^PyErr Lib/
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code class="prettyprint"&gt;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'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is lovely to use:&lt;/p&gt;

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

&lt;p&gt;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 &lt;code&gt;find -name&lt;/code&gt; with an alias:&lt;/p&gt;

&lt;pre&gt;&lt;code class="prettyprint"&gt;alias fname="noglob find -name"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using this alias, you can rewrite the second example as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% fname *.html -print0 | xargs -0 rename 's/\.html$/.var/'
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code class="prettyprint"&gt;alias each="-print0 | xargs -0"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Unfortunately, that doesn&amp;#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.&lt;/p&gt;

&lt;pre&gt;&lt;code class="prettyprint"&gt;alias -g each="-print0 | xargs -0"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With this feature of Zsh, the second example become:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% fname *.html each rename 's/\.html$/.var/'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, we can also attack the third one:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% fname *.patch each -I {} cp {} patches/
&lt;/code&gt;&lt;/pre&gt;

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

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

&lt;pre&gt;&lt;code&gt;% 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
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To reduce these, you don&amp;#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:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% gcc -o stackgrow{,.c}
% pkg show emacs-snapshot{{-bin,}-common,-gtk,}
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;% echo 'cat ../{lispref,lwlib,etc}.patch | patch -p1' | wc -c
45
% echo 'cat ../lispref.patch ../lwlib.patch ../etc.patch | patch -p1' | wc -c
61
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;% echo 'cat ../li\t ../lw\t ../et\t | patch -p1' | wc -c
37
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;And that&amp;#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.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 17 Sep 2007 06:07:37 GMT</pubDate>
      <title>Pretty Emacs Reloaded</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=33</link>
      <guid>http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/feed/</guid>
      <description>&lt;p&gt;My popular&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" rel="footnote" &gt;1&lt;/a&gt;&lt;/sup&gt; &lt;a href="http://peadrop.com/blog/2007/01/06/pretty-emacs/" &gt;Pretty Emacs&lt;/a&gt; package just got a tad better.  I
transferred the package to the brand new &lt;a href="https://help.launchpad.net/PPAQuickStart" &gt;PPA service&lt;/a&gt; provided by
Launchpad. So, what&amp;#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.&lt;/p&gt;

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

&lt;pre&gt;&lt;code&gt;deb     http://ppa.launchpad.net/avassalotti/ubuntu edgy main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu edgy main
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;deb     http://ppa.launchpad.net/avassalotti/ubuntu feisty main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu feisty main
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;deb     http://ppa.launchpad.net/avassalotti/ubuntu gutsy main
deb-src http://ppa.launchpad.net/avassalotti/ubuntu gutsy main
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;After adding the repository to your software source list, upgrade your
version of the package with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo aptitude upgrade
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;sudo aptitude install emacs-snapshot emacs-snapshot-el
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Please note, my package does not have multi-tty support. If you want
multi-tty support and don&amp;#8217;t mind about using bitmap fonts, use Romain
Francoise&amp;#8217;s excellent &lt;a href="http://emacs.orebokech.com/" &gt;package of the CVS trunk&lt;/a&gt; for Debian. Also,
when upgrading the package you might get the following warning
message:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

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

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

&lt;div class="footnotes"&gt;
&lt;hr /&gt;
&lt;ol&gt;

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

&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 2 Aug 2007 20:09:33 GMT</pubDate>
      <title>Protected: Installation scripts review</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=32</link>
      <guid>http://peadrop.com/blog/2007/08/02/installation-scripts-review/feed/</guid>
      <description>&lt;form action="http://peadrop.com/blog/wp-pass.php" method="post"&gt;
    &lt;p&gt;This post is password protected. To view it please enter your password below:&lt;/p&gt;
    &lt;p&gt;&lt;label&gt;Password: &lt;input name="post_password" type="password" size="20" /&gt;&lt;/label&gt; &lt;input type="submit" name="Submit" value="Submit" /&gt;&lt;/p&gt;
    &lt;/form&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 6 Jul 2007 22:05:23 GMT</pubDate>
      <title>Minor annoyance with Planet</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=31</link>
      <guid>http://peadrop.com/blog/2007/07/06/minor-annoyance-with-planet/feed/</guid>
      <description>&lt;div&gt;&lt;/div&gt;

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

&lt;p&gt;I do edit some of my posts,  in particular the &lt;a href="http://peadrop.com/blog/2007/01/06/pretty-emacs/" &gt;Pretty Emacs&lt;/a&gt; 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.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 6 Jul 2007 20:05:57 GMT</pubDate>
      <title>Summer of Code Weekly #4</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=30</link>
      <guid>http://peadrop.com/blog/2007/07/06/summer-of-code-weekly-4/feed/</guid>
      <description>&lt;div&gt;&lt;/div&gt;

&lt;p&gt;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 &lt;code&gt;pickle&lt;/code&gt; module and thinking how I will clean up
cPickle.  My current plan is:&lt;/p&gt;

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

&lt;p&gt;Hopefully, cPickle/pickle merge will be as smooth (and as fun) as the
cStringIO/StringIO merge.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 18 Jun 2007 19:07:45 GMT</pubDate>
      <title>Pickle: An interesting stack language</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=29</link>
      <guid>http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/</guid>
      <description>&lt;p&gt;The &lt;code&gt;pickle&lt;/code&gt; 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
&lt;code&gt;pickle&lt;/code&gt; is a &amp;#8220;program&amp;#8221; able to create Python data-structures.  A
limited stack language is used to write these programs.  By limited, I
mean you can&amp;#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.&lt;/p&gt;

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

&lt;pre&gt;&lt;code class="prettyprint"&gt;import code
import pickle
import sys

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

class PikConsole(code.InteractiveConsole):
    def runsource(self, source, filename="&amp;lt;stdin&amp;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)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then, launch it with Python:&lt;/p&gt;

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

&lt;p&gt;So, nothing crazy &lt;em&gt;yet&lt;/em&gt;.  The easiest objects to create are the empty
one.  For example, to create a empty list:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pik&amp;gt; ].
[]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Similarly, you can also create a dictionary and a tuple:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pik&amp;gt; }.
{}
pik&amp;gt; ).
()
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;pik&amp;gt; I1
...&amp;gt; I2
...&amp;gt; I3
...&amp;gt; .
3
&lt;/code&gt;&lt;/pre&gt;

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

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

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

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

&lt;p&gt;There is two new symbols in this example, &amp;#8216;(&amp;#8217; and &amp;#8216;t&amp;#8217;. The &amp;#8216;(&amp;#8217; is
simply a marker.  It is a object in the stack that tells the tuple
builder, &amp;#8216;t&amp;#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:&lt;/p&gt;

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

&lt;p&gt;You use a similar method to build a list or a dictionary:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pik&amp;gt; (I0
...&amp;gt; I1
...&amp;gt; I2
...&amp;gt; l.
[0, 1, 2]
pik&amp;gt; (S'red'
...&amp;gt; I00
...&amp;gt; S'blue'
...&amp;gt; I01
...&amp;gt; d.
{'blue': True, 'red': False}
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;Like tuples, you can nest lists and dictionaries:&lt;/p&gt;

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

&lt;p&gt;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:&lt;/p&gt;

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

&lt;p&gt;The symbols &amp;#8216;a&amp;#8217; means &amp;#8220;append&amp;#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:&lt;/p&gt;

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

&lt;p&gt;If this is not cryptic enough for you, consider this:&lt;/p&gt;

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

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

&lt;p&gt;Like lists, dictionaries can be constructed using a similar method:&lt;/p&gt;

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

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

&lt;p&gt;You can build recursive data-structures, too:&lt;/p&gt;

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

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

&lt;p&gt;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 &lt;code&gt;set()&lt;/code&gt; on a list (or a tuple):&lt;/p&gt;

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

&lt;p&gt;There is a few new things here.  The &amp;#8216;c&amp;#8217; symbol retrieves an object
from a module and puts it on the stack.  And the reduce symbol, &amp;#8216;R&amp;#8217;,
apply a tuple to a function.  Same semantic again, &amp;#8216;R&amp;#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:&lt;/p&gt;

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

&lt;p&gt;Or, using the star notation:&lt;/p&gt;

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

&lt;p&gt;And, that is the same thing as writing:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; set(['a', 'a', 'b'])
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or shorter even, using the set notation from the upcoming Python 3000:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; {'a', 'a', 'b'}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These two new symbols, &amp;#8216;t&amp;#8217; and &amp;#8216;R&amp;#8217;, allows us to execute arbitrary
code from the standard library.  So, you must be careful to &lt;em&gt;never&lt;/em&gt;
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:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pik&amp;gt; cos
...&amp;gt; system
...&amp;gt; (S'xclock'
...&amp;gt; tR.
&lt;/code&gt;&lt;/pre&gt;

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

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

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

&lt;pre&gt;&lt;code class="prettyprint"&gt;def my_if(cond, then_val, else_val):
    if cond:
        return then_val
    else:
        return else_val&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That works well for simple cases:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; my_if(True, 1, 0)
1
&amp;gt;&amp;gt;&amp;gt; my_if(False, 1, 0)
0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, you run into some problems if mix that with recursion:&lt;/p&gt;

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

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

&lt;p&gt;That is about all I had to say about this simple stack language.
There is a few things haven&amp;#8217;t told you about, but I sure you will be
able figure them out.  Just read the source code of the &lt;code&gt;pickle&lt;/code&gt;
module.  And, take a look at the &lt;code&gt;pickletools&lt;/code&gt; module,
which provides a disassembler for pickle streams.  As always, comments
are welcome.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 8 Jun 2007 01:06:41 GMT</pubDate>
      <title>Summer of Code Weekly #3</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=28</link>
      <guid>http://peadrop.com/blog/2007/06/07/summer-of-code-weekly-3/</guid>
      <description>&lt;p&gt;During this third week of the Summer of Code, I found very
difficult to concentrate on my work &amp;#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 &lt;code&gt;gdb&lt;/code&gt;; the basics of the
design of the Linux kernel; etc, etc.&lt;/p&gt;

&lt;p&gt;I also read the book &amp;#8220;Producing Open Source Software&amp;#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
&lt;a href="http://producingoss.com/" &gt;online&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 1 Jun 2007 00:06:00 GMT</pubDate>
      <title>Summer of Code Weekly #2</title>
      <link>http://www.advogato.org/person/avassalotti/diary.html?start=27</link>
      <guid>http://peadrop.com/blog/2007/05/31/summer-of-code-weekly-2/</guid>
      <description>&lt;p&gt;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&amp;#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.&lt;/p&gt;

&lt;p&gt;Now, I will need to attack the cPickle and cProfile modules. I don&amp;#8217;t
know yet which I work on first. cPickle still seems very scary to me,
and unlike cStringIO it&amp;#8217;s huge. It&amp;#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?&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
