<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Peter Hoffmann</title>
  <id>http://peter-hoffmann.com/feed/atom.xml</id>
  <updated>2012-05-01T00:00:00Z</updated>
  <link href="http://peter-hoffmann.com" />
  <link href="http://peter-hoffmann.com/feed/atom.xml" rel="self" />
  <subtitle type="text">Atom Feed for peter-hoffmann.com</subtitle>
  <generator>Werkzeug</generator>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Neo4j Podcasts</title>
    <id>http://peter-hoffmann.com/2012/neo4j-podcasts.html</id>
    <updated>2012-05-01T00:00:00Z</updated>
    <published>2012-05-01T00:00:00Z</published>
    <link href="http://peter-hoffmann.com/2012/neo4j-podcasts.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;The IBM &lt;a href="http://www.ibm.com/developerworks/java/library/j-gloverpodcast4/index.html"&gt;Java technology zone technical podcast series&lt;/a&gt; has two nice
podcasts about the &lt;a href="http://neo4j.org/"&gt;Neo4j&lt;/a&gt; Graph Database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Emil Eifrem, the man behind Neo4j&lt;/strong&gt; (&lt;a href="http://www.ibm.com/developerworks/podcast/glover-eifrem-041012/glover-eifrem-041012.mp3"&gt;mp3&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Agile architect Peter Bell on Neo4j, a graph-oriented datastore built in
Java&lt;/strong&gt; (&lt;a href="http://www.ibm.com/developerworks/podcast/glover-bell-032112/glover-bell-032112.mp3"&gt;mp3&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole podcast series is worth listening, so subscribe to the &lt;a href="http://www.ibm.com/developerworks/podcast/channel-dwall.rss"&gt;RSS Feed&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Google Developer Weekend Hack and Tell</title>
    <id>http://peter-hoffmann.com/2011/google-developer-weekend-hack-and-tell.html</id>
    <updated>2011-11-18T00:00:00Z</updated>
    <published>2011-11-18T00:00:00Z</published>
    <link href="http://peter-hoffmann.com/2011/google-developer-weekend-hack-and-tell.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;The Google Developer Weekend started with a &lt;a href="http://www.meetup.com/berlin-hack-and-tell/"&gt;Berlin Hack and Tell Special Google Edition&lt;/a&gt; at C-Base.&lt;/p&gt;

&lt;p&gt;Thanks to Deborah from &lt;a href="http://9flats.com"&gt;http://9flats.com&lt;/a&gt; for the Pizza.&lt;/p&gt;

&lt;p&gt;Here's a short list of the projects:&lt;/p&gt;

&lt;h1&gt;Friedger Muefke&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://open-accessories.com"&gt;http://open-accessories.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Friedger showed how to modify google docs with google appscript and access data
from a spreadsheet and send it to a blog.&lt;/p&gt;

&lt;h1&gt;Lean Engine&lt;/h1&gt;

&lt;p&gt;Mathias from &lt;a href="http://lean-engine.com/android.html"&gt;lean engine&lt;/a&gt; showed how to cloud enable your mobile apps. &lt;/p&gt;

&lt;h1&gt;Stefan Wehrmeyer&lt;/h1&gt;

&lt;p&gt;Stefan presentedhttp://mapnificent.net, a layer over google maps which tells
you what points in a city you can reach via public transport in a given time.&lt;/p&gt;

&lt;p&gt;Stefan uses &lt;a href="http://www.gtfs-data-exchange.com/"&gt;http://www.gtfs-data-exchange.com/&lt;/a&gt; to get the timetables for public
transport. Sadly the berlin transport organization BVG does not provide real
time data.&lt;/p&gt;

&lt;h1&gt;wheelmap.org&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://wheelmap.org"&gt;whellmap.org&lt;/a&gt; is a  map with wheelchair accessible
places. The presenter showed how to work around the android sqlite limitations
to work with lat/long positions.&lt;/p&gt;

&lt;h1&gt;Launchmode&lt;/h1&gt;

&lt;p&gt;Gonsala shode &lt;a href="http://github.com/gnorsilva"&gt;launchmode&lt;/a&gt;, an app to help visualize android activities.&lt;/p&gt;

&lt;h1&gt;xbounds.net&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://xbounds.net"&gt;xbounds&lt;/a&gt; is a great hack to add screensharing to mobile
devices.&lt;/p&gt;

&lt;h1&gt;andengine&lt;/h1&gt;

&lt;p&gt;Johannes presented how to use &lt;a href="http://andlabs.eu"&gt;andengine&lt;/a&gt; together with
&lt;a href="www.physicseditor.de/"&gt;Physics Editor&lt;/a&gt;. It's a simple way to add physics to
your games (like collition detection). Just load an image of your level to
Physics Editor and load the result to andengind.&lt;/p&gt;

&lt;h1&gt;komoot.de&lt;/h1&gt;

&lt;p&gt;Jonas and Jan talked about some design decisions for &lt;a href="http://komoot.de"&gt;http://komoot.de&lt;/a&gt; an
outdoor navigation and route planning app.&lt;/p&gt;

&lt;p&gt;They dropped a local database on the mobile phones in support for a thin
caching layer and now get all data from their servers.&lt;/p&gt;

&lt;h1&gt;Daniel Kurka&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://twitter.com/dankurka"&gt;@dankurka&lt;/a&gt; showed &lt;a href="http://m-gwt.com"&gt;m-gwt.com&lt;/a&gt;. It lets you
programm gwt applications for mobile phones. The gwt programm is compiled to
html5/css and runs via phone gap on your mobile phones&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Barcamp Stuttgart 2011</title>
    <id>http://peter-hoffmann.com/2011/Barcamp-Stuttgart.html</id>
    <updated>2011-10-02T19:25:25Z</updated>
    <published>2011-10-02T19:25:25Z</published>
    <link href="http://peter-hoffmann.com/2011/Barcamp-Stuttgart.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;
&lt;a href="http://bcs4.mixxt.de/"&gt;Barcamp Stuttgart 2011&lt;/a&gt; is over and it was
really nice, interesting and well organized (as always).
&lt;/p&gt;
&lt;p&gt;
&lt;a
href="http://www.timetabler.de/events/b66457f754bd49061bedf6438c15123532638cf7"&gt;&lt;img
src="http://peter-hoffmann.com/static/2011/bcs4.jpg" alt="Timetable"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;I chosed to participate in the following sessions:
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;b&gt;Identity Management&lt;/b&gt; I visited the slot because I thought it
    would be about online identiy management, but the slot was about the
    corporate world. Tobias talked about different identity sources in
    corporations like SAP HR, Microsoft AD/Exchange and the problems on how
    to keep them up-to-date and in sync.
    &lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Memotechnik&lt;/b&gt; &lt;a href="http://twitter.com/alomuc"&gt;Andreas
        Lohrum&lt;/a&gt; introduced us to the art of memory and showed us how to
    remember the first 30 digits of PI. So now I only have to remember 100
    words for the numbers 0 to 100 and than I should be able to remember
    telphone numbers. We'll see...
    &lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Startupscene Stuttgart&lt;/b&gt; What's the current status of the local
    startup scene and how to improve it. &lt;a
    href="http://twitter.com/ha75"&gt;Harald Amelung&lt;/a&gt; made some 
    &lt;a href="http://piratepad.net/bcs4startup"&gt;Notes&lt;/a&gt;.
    &lt;/li&gt;
    &lt;li&gt;&lt;b&gt;Geile Twitterbots&lt;/b&gt; &lt;a
        href="http://twitter.com/sauerstoff"&gt;Karsten Sauer&lt;/a&gt; showed us some
        of his twitter bots:
    &lt;ul&gt;
        &lt;li&gt;&lt;i&gt;&lt;a href="http://twitter.com/dblocator"&gt;@dblocator&lt;/a&gt;&lt;/i&gt; Who
        else is in your train.
        &lt;/li&gt;
        &lt;li&gt;&lt;i&gt;&lt;a href="http://twitter.com/dblocator"&gt;@einkaufsliste&lt;/a&gt;&lt;/i&gt;
        Manage your shopping list via twitter. 
        &lt;/li&gt;
        &lt;li&gt;&lt;i&gt;&lt;a href="http://twitter.com/meineliste"&gt;@meineliste&lt;/a&gt;&lt;/i&gt;
        Manage any list via twitter.
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;b&gt;#GO-NUTS&lt;/b&gt; Sven gave a short introduction into the &lt;a
        href="http://golang.org"&gt;go programming language&lt;/a&gt;
    &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There could have been some more technical sessions. The quality of the
speakers was very good.
&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">send notes to simplenote from the command line and vim</title>
    <id>http://peter-hoffmann.com/2011/send-notes-to-simplenote-from-command-line-and-vim.html</id>
    <updated>2011-08-13T10:50:44Z</updated>
    <published>2011-08-13T10:50:44Z</published>
    <link href="http://peter-hoffmann.com/2011/send-notes-to-simplenote-from-command-line-and-vim.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;sn.py is a command line app to send text to &lt;a class="reference external" href="http://simplenoteapp.com"&gt;simplenote&lt;/a&gt; service.
It uses the &lt;a class="reference external" href="http://readthedocs.org/docs/simplenotepy/"&gt;simplenote.py&lt;/a&gt; library.:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
#!/usr/bin/env python
&amp;quot;&amp;quot;&amp;quot;simplenote command line app&amp;quot;&amp;quot;&amp;quot;

import sys
import fileinput

from simplenote import Simplenote
sn = Simplenote(&amp;quot;XXX&amp;quot;, &amp;quot;XXX&amp;quot;)


def send(txt):
    note = {'content': txt}
    note, status = sn.add_note(note)

    if status != 0:
        print &amp;gt;&amp;gt; sys.stderr, note
        sys.exit(1)


def read_until_dot():
    line = raw_input()
    while line != &amp;quot;.&amp;quot;:
        yield line
        line = raw_input()

import sys
def main(argv=None):
    if argv is None:
        argv = sys.argv

    if len(argv) == 1:
        lines = read_until_dot()
    else:
        lines = fileinput.input()

    send(&amp;quot;\n&amp;quot;.join(lines))


if __name__ == '__main__':
    main()
&lt;/pre&gt;
&lt;div class="section" id="usage"&gt;
&lt;h1&gt;Usage&lt;/h1&gt;
&lt;p&gt;Enter a note:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ sn.py
write text
you want to send to simplenote
end note with one . in line
.
&lt;/pre&gt;
&lt;p&gt;Pipe the output from another commant to simplenote:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ echo &amp;quot;send output from command&amp;quot; | sn.py -
&lt;/pre&gt;
&lt;p&gt;Send the contents from a file to simplenote:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ sn.py some_text_file.txt
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class="section" id="vim"&gt;
&lt;h1&gt;Vim&lt;/h1&gt;
&lt;p&gt;There is the &lt;a class="reference external" href="http://mrtazz.github.com/simplenote.vim/"&gt;simplenote.vim&lt;/a&gt; plugin. It lets you interact with
simplenote. If you just want a quick way to send notes to simplenote use
the following commands:&lt;/p&gt;
&lt;p&gt;Send the current buffer to simplenote:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
:%w !sn.py -
&lt;/pre&gt;
&lt;p&gt;Send the current selection to simplenote:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
:'&amp;lt;,'&amp;gt;w !sn.py -
&lt;/pre&gt;
&lt;/div&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Adding a dict based interface to the python leveldb api</title>
    <id>http://peter-hoffmann.com/2011/adding-dict-interface-python-leveldb-api.html</id>
    <updated>2011-08-06T17:23:02Z</updated>
    <published>2011-08-06T17:23:02Z</published>
    <link href="http://peter-hoffmann.com/2011/adding-dict-interface-python-leveldb-api.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;In the last post I showed &lt;a class="reference external" href="http://peter-hoffmann.com/2011/installation-leveldb-ubuntu-python.html"&gt;how to install the python LevelDB bindings&lt;/a&gt;.
Here is how to wrap the &lt;a class="reference external" href="http://code.google.com/p/py-leveldb/"&gt;python LevelDB API&lt;/a&gt; into a dict like API with the
help of &lt;a class="reference external" href="http://docs.python.org/library/userdict.html#UserDict.DictMixin"&gt;UserDict.DictMixin&lt;/a&gt;. In a subclass we will extend the the simple
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;key&amp;lt;string&amp;gt;:value&amp;lt;string&amp;gt;&lt;/span&gt;&lt;/tt&gt; mapping to a dict with arbitrary JSON
serializablie values.&lt;/p&gt;
&lt;pre class="literal-block prettyprint lang-py"&gt;
from UserDict import DictMixin
import leveldb
import json


class LevelDict(DictMixin):
    &amp;quot;&amp;quot;&amp;quot;Dict Wrapper around the Google LevelDB Database&amp;quot;&amp;quot;&amp;quot;
    def __init__(self, path):
        &amp;quot;&amp;quot;&amp;quot;Constructor for LevelDict&amp;quot;&amp;quot;&amp;quot;
        self.path = path
        self.db = leveldb.LevelDB(self.path)

    def __getitem__(self, key):
        return self.db.Get(key)

    def __setitem__(self, key, value):
        self.db.Put(key, value)

    def __delitem__(self, key):
        self.db.Delete(key)

    def __iter__(self):
        for k, v in self.db.RangeIter():
            yield v

    def keys(self):
        return [k for k, v in self.db.RangeIter()]

    def iteritems(self):
        return self.db.RangeIter()

    def rangescan(self, start=None, end=None):
        if start is None and end is None:
            return self.db.RangeIter()
        elif end is None:
            return self.db.RangeIter(start)
        else:
            return self.db.RangeIter(start, end)
&lt;/pre&gt;
&lt;p&gt;To store more than just strings we will add JSON serialization to a
subclass:&lt;/p&gt;

&lt;pre class="literal-block prettyprint lang-py"&gt;
class LevelJsonDict(LevelDict):
    &amp;quot;&amp;quot;&amp;quot;Dict Wrapper around the Google LevelDB Database with JSON serialization&amp;quot;&amp;quot;&amp;quot;
    def __getitem__(self, key):
        return json.loads(LevelDict.__getitem__(self, key))

    def __setitem__(self, key, value):
        LevelDict.__setitem__(self, key, json.dumps(value))

    def iteritems(self):
        for k, v in LevelDict.iteritems(self):
            yield k, json.loads(v)

    def rangescan(self, start=None, end=None):
        for k, v in LevelDict.rangescan(self, start, end):
            yield k, json.loads(v)
&lt;/pre&gt;

&lt;p&gt;Now you have a fast JSON Store with a Dict based Interface and a LevelDB
backend.&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Install LevelDB and the python bindings py-leveldb on ubuntu</title>
    <id>http://peter-hoffmann.com/2011/installation-leveldb-ubuntu-python.html</id>
    <updated>2011-07-31T13:00:00Z</updated>
    <published>2011-07-31T13:00:00Z</published>
    <link href="http://peter-hoffmann.com/2011/installation-leveldb-ubuntu-python.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;Google has
&lt;a href="http://google-opensource.blogspot.com/2011/07/leveldb-fast-persistent-key-value-store.html"&gt;
open sourced&lt;/a&gt; &lt;a href="http://code.google.com/p/leveldb/ "&gt;LevelDB&lt;/a&gt;, a fast and
lightweight key/value store.  Chromium/Chrome uses LevelDB to power its
IndexedD and there are bindings for Riak and Kyoto Tycoon (see
&lt;a href="http://www.quora.com/What-projects-are-using-LevelDB "&gt;Gabors Response on
quora.com&lt;/a&gt;). The
&lt;a href="http://leveldb.googlecode.com/svn/trunk/doc/benchmark.html "&gt;LevelDB
Benchmark&lt;/a&gt; shows some impressive numbers compared against SQLite and Kyoto
TreeDB.
&lt;/p&gt;&lt;p&gt;Here are my installation notes on how to get LevelDB and the python
bindings working on a fresh Ubuntu 11.04 installation.
&lt;/p&gt;&lt;p&gt;Install development environment and get the
&lt;a href="http://code.google.com/p/leveldb/"&gt; LevelDB&lt;/a&gt; and
&lt;a href="http://code.google.com/p/py-leveldb/ "&gt; py-leveldb&lt;/a&gt; source.
&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
~$ sudo aptitude install build-essential python-dev
~$ mkdir ~/svn
~$ cd ~/svn
~/svn$ svn checkout http://py-leveldb.googlecode.com/svn/trunk/ py-leveldb-read-only
~/svn$ cd py-leveldb-read-only
&lt;/pre&gt;

&lt;p&gt;After checking out the source I had to build leveldb by hand and than run
the normal &lt;tt&gt;python setup.py install&lt;/tt&gt;
&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
~/svn/py-leveldb-read-only$ cd leveldb-read-only
~/svn/py-leveldb-read-only/leveldb-read-only$ make
~/svn/py-leveldb-read-only/leveldb-read-only$ cd ..
~/svn/py-leveldb-read-only$ sudo python setup.py install
&lt;/pre&gt;
&lt;p&gt;Now you can fire up ipython and play around with the python api:
&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
In [1]: import leveldb

In [2]: db = leveldb.LevelDB('/tmp/testdb')

In [3]: db.Put('some key', 'some val')

In [4]: db.Put('another key', 'another val')

In [5]: db.Get('some key')
Out[5]: 'some val'

In [6]: for a in db.RangeIter():
   ...:     print a
   ...:     
('another key', 'another val')
('some key', 'some val')
&lt;/pre&gt;

&lt;p&gt;I'm going to do some micro benchmarks with the python bindings soon and
add a &lt;tt&gt;UserDict&lt;/tt&gt; based wrapper to the api. Until then there are some
worth reading commments on the implementation and datastructures on &lt;a
href="http://news.ycombinator.com/item?id=2526032"&gt;news.ycombinator&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">asq - a simple implementation of a LINQ-inspired API for python</title>
    <id>http://peter-hoffmann.com/2011/asq-linq-inspired-api-for-python.html</id>
    <updated>2011-06-06T23:15:29Z</updated>
    <published>2011-06-06T23:15:29Z</published>
    <link href="http://peter-hoffmann.com/2011/asq-linq-inspired-api-for-python.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;&lt;a href="http://www.smallshire.org.uk"&gt;Robert Smallshire&lt;/a&gt; has released version
1.0 of &lt;a href="http://code.google.com/p/asq/"&gt;asq&lt;/a&gt;:
&lt;/p&gt;&lt;p&gt;asq is simple implementation of a LINQ-inspired API for Python which
operates over Python iterables, including a parallel version implemented in
terms of the Python standard library multiprocessing module.
&lt;/p&gt;&lt;p&gt;An example what you can do with asq from the nice
&lt;a href="http://docs.asq.googlecode.com/hg/1.0/html/narrative.html"&gt;documentation&lt;/a&gt;
&lt;/p&gt;&lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; students = [dict(firstname='Joe', lastname='Blogs', scores=[56, 23, 21, 89]),
            dict(firstname='John', lastname='Doe', scores=[34, 12, 92, 93]),
            dict(firstname='Jane', lastname='Doe', scores=[33, 94, 91, 13]),
            dict(firstname='Ola', lastname='Nordmann', scores=[98, 23, 98, 87]),
            dict(firstname='Kari', lastname='Nordmann', scores=[86, 37, 88, 87]),
            dict(firstname='Mario', lastname='Rossi', scores=[37, 95, 45, 18])]

&amp;gt;&amp;gt;&amp;gt; query(students).order_by(lambda s: query(s['scores']).average()) \
...                 .where(lambda student: student['firstname'].startswith('J')) \
...                 .select(lambda s: s['firstname'] + ' ' + s['lastname']) \
...                 .to_list()
['Joe Blogs', 'John Doe', 'Jane Doe']
&lt;/pre&gt;&lt;p&gt;You can do the same with list comprehension/generator expressions:
&lt;/p&gt;&lt;pre&gt;
def avgscore(s):
	return avg(s['scores'])

[s['firstname']+' '+s['lastname'] for s in sorted(students, key=avgscore) if s['firstname'].startswith('J')]
&lt;/pre&gt;&lt;p&gt;But as discussed on
&lt;a href="http://www.reddit.com/r/Python/comments/hso2k/asq_10_linq_style_queries_over_python_iterables/"&gt;reddit&lt;/a&gt;
asq has some nice features like partial sorting and support
for performing queries in parallel across multiple cores.
&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Authenticate Trac against a MySQL Table</title>
    <id>http://peter-hoffmann.com/2011/apache2-authenticate-trac-against-mysql-table.html</id>
    <updated>2011-05-28T18:00:00Z</updated>
    <published>2011-05-28T18:00:00Z</published>
    <link href="http://peter-hoffmann.com/2011/apache2-authenticate-trac-against-mysql-table.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;Recently I had to set up a &lt;a href="http://trac.edgewall.org/"&gt;trac&lt;/a&gt; instance which had to reuse
authentification from an existing application. &lt;/p&gt;

&lt;p&gt;Using Apache2 with Auth_MySQL it's really easy:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ScriptAlias /trac /var/www-trac/deploy/cgi-bin/trac.fcgi/
    &amp;lt;Location &amp;quot;/trac&amp;quot;&amp;gt;
            AuthName &amp;quot;Please Authenticate&amp;quot;
            AuthType Basic
            require valid-user
            AuthUserFile /dev/null
            AuthBasicAuthoritative Off

            Auth_MySQL On
            Auth_MySQL_Host localhost
            Auth_MySQL_User dbuser 
            Auth_MySQL_Password dbpw
            Auth_MySQL_DB dbname
            Auth_MySQL_Password_Table Users
            Auth_MySQL_Username_Field username
            Auth_MySQL_Password_Field passwd
            Auth_MySQL_Encryption_Types Plaintext
            Auth_MySQL_Authoritative Off
    &amp;lt;/Location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Microsoft Sho Word Histogram and the Python Standard Library</title>
    <id>http://peter-hoffmann.com/2011/microsoft-sho-word-histogram-python-standard-library.html</id>
    <updated>2011-01-27T19:00:04Z</updated>
    <published>2011-01-27T19:00:04Z</published>
    <link href="http://peter-hoffmann.com/2011/microsoft-sho-word-histogram-python-standard-library.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;Through a
&lt;a href="http://www.johndcook.com/blog/2011/01/26/python-based-datascience-environment-from-microsoft/"&gt;
blog post from John D. Cook&lt;/a&gt; on &lt;a href="http://planet.python.org"&gt;planet python&lt;/a&gt;
I beacame aware of the
&lt;a href="http://blogs.msdn.com/b/the_blog_of_sho/archive/2011/01/26/introducing-sho.aspx"&gt;Microsoft
Sho Project&lt;/a&gt; for data analysis and scientific computing. I haven't
installed it yet, but it looks promising and I always love to see progress
and usage of IronPython on Windows.
&lt;/p&gt;&lt;p&gt;Here's the 
&lt;a href="http://research.microsoft.com/en-us/projects/sho/screenshots.aspx#46b19b28-768e-4707-b78a-155c3a6a2ac6"&gt;Computing
a Word Histogramm Example&lt;/a&gt;:
&lt;/p&gt;&lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; fp = System.IO.File.ReadAllText("./declarationofindependence.txt")
&amp;gt;&amp;gt;&amp;gt; table = System.Collections.Hashtable()
&amp;gt;&amp;gt;&amp;gt; for word in fp.split():
    if table.ContainsKey(word):
        table[word] +=1
    else:
        table[word] = 1
&amp;gt;&amp;gt;&amp;gt; pairs = zip(list(table.Keys), list(table.Values))
&amp;gt;&amp;gt;&amp;gt; pairs.sort(lambda a,b: a[1]&amp;lt;b[1])
&amp;gt;&amp;gt;&amp;gt; bar([elt[0] for elt in pairs[0:10]], [elt[1] for elt in pairs[0:10]])
&lt;/pre&gt;&lt;p&gt;&lt;img src="http://research.microsoft.com/en-us/projects/sho/wordhistogram.jpg" alt="http://research.microsoft.com/en-us/projects/sho/wordhistogram.jpg" /&gt;
&lt;/p&gt;&lt;p&gt;I've used a hashtable for counting in the past too, but the
&lt;a href="http://docs.python.org/py3k/library/collections.html#collections.Counter"&gt;
Counter Datastructure&lt;/a&gt; from the python standard library (added in
2.7) is much better suited for this kind of task:
&lt;/p&gt;&lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; from collections import Counter
&amp;gt;&amp;gt;&amp;gt; table = Counter()
&amp;gt;&amp;gt;&amp;gt; table(fp.split())
&amp;gt;&amp;gt;&amp;gt; pairs = table.most_common(10)
&lt;/pre&gt;&lt;p&gt;It's shorter and more readable. 
&lt;/p&gt;&lt;p&gt;For sorting a list of lists based on a specific element I
prefer using
&lt;a href="http://docs.python.org/library/operator.html#operator.itemgetter"&gt;
operator.itemgetter&lt;/a&gt; instead of a lambda expression.
&lt;/p&gt;&lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; from operator import itemgetter
&amp;gt;&amp;gt;&amp;gt; lst = [('orange', 5), ('banana', 7), ('apple', 2)]
&amp;gt;&amp;gt;&amp;gt; lst.sort(key=itemgetter(1))
&amp;gt;&amp;gt;&amp;gt; lst
[('apple', 2), ('orange', 5), ('banana', 7)]
&lt;/pre&gt;&lt;p&gt;The bottom line is that python has a great standard library and it is worth
knowing it well.
&lt;/p&gt;
</content>
  </entry>
  <entry xml:base="http://peter-hoffmann.com/feed/atom.xml">
    <title type="text">Atom feed for Google Reader liked items</title>
    <id>http://peter-hoffmann.com/2011/atom-feed-for-google-reader-liked-items.html</id>
    <updated>2011-01-06T06:29:29Z</updated>
    <published>2011-01-06T06:29:29Z</published>
    <link href="http://peter-hoffmann.com/2011/atom-feed-for-google-reader-liked-items.html" />
    <author>
      <name>Peter Hoffmann</name>
      <uri>http://peter-hoffmann.com</uri>
    </author>
    <content type="html">&lt;p&gt;While you can make your Google Reader starred and shared items public
available, I found no way to do the same for my liked items. There isn't
even a link from inside Google Reader to view your liked items. 
&lt;/p&gt;

&lt;p&gt;
But you can
view your liked items if you open the following url 
&lt;a href="http://www.google.com/reader/view/user/-/state/com.google/like"&gt;
http://www.google.com/reader/view/user/-/state/com.google/like&lt;/a&gt;. And
there is even an Atom feed available 
&lt;a href="http://www.google.com/reader/atom/user/-/state/com.google/like"&gt;
http://www.google.com/reader/atom/user/-/state/com.google/like&lt;/a&gt;. The
problem is that you have to be logged in to view the feed. So here is a
small script to do a Google ClientLogin and dump the atom feed.
&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
import httplib2
from urllib import urlencode
client = httplib2.Http('cache')

def request_auth_token(email, passwd):
    """request auth token from google

    see: http://code.google.com/apis/accounts/
         http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
    """
    url = 'https://www.google.com/accounts/ClientLogin'
    headers = {'Content-type': 'application/x-www-form-urlencoded'}
    body = urlencode({'Email': email, 'Passwd': passwd, 'service': 'reader'})
    response, content = client.request(url, 'POST', headers=headers,  body=body)
    assert response['status'] == '200'
    #if status == 403 check for Error=CaptchaRequired
    resp_data = dict(x.split('=') for x in content.split('\n') if x)
    return resp_data["Auth"]

def likes_feed(auth):
    url = "http://www.google.com/reader/atom/user/-/state/com.google/like"
    headers = {'Authorization': 'GoogleLogin auth=%s' % auth}
    response, content = client.request(url, 'GET', headers=headers)
    return content


if __name__ == '__main__':
    email = "XXX@gmail.com"
    passwd = "XXX"
    auth  = request_auth_token(email, passwd)
    print likes_feed(auth)
&lt;/pre&gt;

&lt;p&gt;The same method should work to get the content of private folders in
Google Reader.&lt;/p&gt;
</content>
  </entry>
</feed>

