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

<channel>
	<title>Arg and gah and ap and pa</title>
	<atom:link href="http://argandgahandapandpa.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://argandgahandapandpa.wordpress.com</link>
	<description>Another blog with random computer-related musings</description>
	<lastBuildDate>Thu, 27 Aug 2009 13:08:00 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='argandgahandapandpa.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/fb277ac6dd131d371770c3fdbadad380?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Arg and gah and ap and pa</title>
		<link>http://argandgahandapandpa.wordpress.com</link>
	</image>
			<item>
		<title>Why might a set API be useful</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/08/03/why-might-a-set-api-be-useful/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/08/03/why-might-a-set-api-be-useful/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 17:02:43 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=167</guid>
		<description><![CDATA[Why use a set api rather than a list API if one doesn&#8217;t care about performance
In most languages in built set classes have better performance than lists. But suppose one doesn&#8217;t care about performance &#8211; why would you use a set rather than a list.
Broadly speaking a set is distinguished from a list by the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=167&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Why use a set api rather than a list API if one doesn&#8217;t care about performance</strong></p>
<p>In most languages in built set classes have better performance than lists. But suppose one doesn&#8217;t care about performance &#8211; why would you use a set rather than a list.</p>
<p>Broadly speaking a set is distinguished from a list by the lack of </p>
<p>a) Ordering<br />
b) Duplication of elements.</p>
<p>How can these properties be useful. In a sense it isn&#8217;t true that sets don&#8217;t have an ordering, since in most languages you can iterate over the members of a set &#8211; rather they just don&#8217;t have a very good ordering. So this is not really of any use to us.</p>
<p>So the <strong>only thing that could be useful about a set api is that it allows one to avoid duplication of items</strong> without writing any code to do this. This will be useful for any problems in which you explicitly want to avoid duplication, examples of this include:</p>
<p>* Only wanting to email a number of people once<br />
* Only wanting to rerun tests once<br />
* Only wanting to list each result once (but having an algorithm that generates duplicates).</p>
<p><strong>This concept of avoiding duplication can be generalised </strong></p>
<p>A dictionary allows one to avoid duplication of parts of an object. That is, if we consider two objects to be near enough identical only parts of them match then we can use these parts as keys in a dictionary &#8211; and thereby avoid duplication.</p>
<p>In fact we can encapsulate this behaviour in an equivalence set &#8211; a collection with ensures uniqueness up to some equivalence function (if our elements are immutable we could use the following).</p>
<p>class EquivalenceSet(object):<br />
    def __init__(self, getRepr):<br />
         self.getRepr = getRepr # get representation of equivalence class<br />
         self.mapping = {}</p>
<p>    def add(self, el):<br />
          self.mapping[self.getRepr(el)] = el</p>
<p>    def __iter__(self, el):<br />
          return self.mapping.itervalues()</p>
<p>This assumes that out &#8220;uniqueness&#8221; can somehow be represented by a function such that f(x) = f(y) implies x and y are equivalent . However, sometimes we have more interesting notions of not &#8220;unique&#8221; for example if we are representing objects in a plane &#8211; two objects might only be considered &#8220;unique&#8221; if they do not intersect. If we are in this situation it may not be clear what we should do when elements are not unique.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=167&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/08/03/why-might-a-set-api-be-useful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript: keyCode versus charCode</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/07/26/javascript-keycode-versus-charcode/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/07/26/javascript-keycode-versus-charcode/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 23:35:47 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[for the benefit of google]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/2009/07/26/javascript-keycode-versus-charcode/</guid>
		<description><![CDATA[Javascript key press events have both a keyCode and a charCode property. These are mutually exclusive &#8211; whenever one is non-zero the other is zero.
Which one is set depends on the type of event: keydown and keyup events give one events with keyCode set (they produce corresponding character) whilst keypress events give one events with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=166&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Javascript key press events have both a keyCode and a charCode property. These are mutually exclusive &#8211; whenever one is non-zero the other is zero.</p>
<p>Which one is set depends on the type of event: keydown and keyup events give one events with keyCode set (they produce corresponding character) whilst keypress events give one events with charCode set.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=166&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/07/26/javascript-keycode-versus-charcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatically loading a truecrypt share at startup</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/05/22/automatically-loading-a-truecrypt-share-at-startup/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/05/22/automatically-loading-a-truecrypt-share-at-startup/#comments</comments>
		<pubDate>Fri, 22 May 2009 22:16:47 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=163</guid>
		<description><![CDATA[I&#8217;m toying with the idea of moving all of my data into the cloud, or rather, keeping all of my data dropbox so that I can access if from 2 different machines and have those changes synced without thinking, and so that I&#8217;m less dependent on any single piece of hardwire.
However, although I want some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=163&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m toying with the idea of moving all of my data into the cloud, or rather, keeping all of my data dropbox so that I can access if from 2 different machines and have those changes synced without thinking, and so that I&#8217;m less dependent on any single piece of hardwire.</p>
<p>However, although I want some data to be present on all the machines I use, I don&#8217;t want all data to be present on every machine I use, and I don&#8217;t think I can easily have several dropbox shares. </p>
<p>One solution is to keep some of the data in a truecrypt volume which is automatically mounted on some machines but not on others. </p>
<p>For this purpose I adapted the following bash init script from <a href="http://notes.lokorin.org/2007/1/9/mounting-truecrypt-partitions-on-boot">here</a>. This takes a truecrypt file, reads a password from disk and mounts the file in my home directory.  I&#8217;m suspicious that there might be problems with conflicts when dropbox updates the truecrypt file whilst it is already mounted&#8230; but we&#8217;ll see. (dropbox has version control so I should be moderately safe).</p>
<p>Note that this approach may place your volume password into the list of processes &#8211; so you might prefer not to use this on shared machines. Also, you probably would want to change the umask and the owner of the share.</p>
<pre>
#!/bin/bash
#
#   /etc/rc.d/init.d/truecrypt
#
# Mounts the /home partition with truecrypt.
#
# chkconfig: 2345 90 10
# description: Truecrypt

# processname: truecrypt

[ -x /usr/bin/truecrypt ] || (echo "truecrypt can't be found" ; exit 1)

RETVAL=0
prog="truecrypt"
desc="Truecrypt" 

start() {
   echo -n "Mounting encrypted volume..."
   uid=$(cat /etc/passwd | grep moment | cut -d ':' -f 3)
   truecrypt -t --fs-options='umask=000,user' --non-interactive VOLUMNE_FILE VOLUME_MOUNT_POINT -p "$(cat PASSWORD_FILE)"
   RETVAL=$?
   [ "$RETVAL" == "0" ] || (echo "FAIL" ; exit 1)
   echo "OK"
}

stop() {
   echo  -n  "Unmounting encrypted volume..."
   truecrypt -t -d /home/moment/cryptshare
   RETVAL=$?
   if [ "$RETVAL" == "0" ]; then
        echo "OK";
   else
      echo "FAIL";
   fi;
}

case "$1" in
  start)
   start
   ;;
  stop)
   stop
   ;;
  restart)
   stop
   start
   RETVAL=$?
   ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] &amp;&amp; restart
   RETVAL=$?
   ;;
  *)
   echo $"Usage: $0 {start|stop|restart|condrestart}"
   RETVAL=1
esac

exit $RETVAL
</pre>
<p>Not sure whether this is a good use of time&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=163&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/05/22/automatically-loading-a-truecrypt-share-at-startup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Reading files in factor</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/04/10/reading-files-in-factor/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/04/10/reading-files-in-factor/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 19:08:20 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[code samples]]></category>
		<category><![CDATA[factor]]></category>
		<category><![CDATA[for the benefit of google]]></category>
		<category><![CDATA[minimal code samples]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=154</guid>
		<description><![CDATA[Working code for the impatient
The following factor code reads and counts the number of words in the file &#8220;/etc/fstab&#8221;

USING: io.encodings.ascii io io.files prettyprint splitting sequences ;
"/etc/fstab" ascii file-contents " \n\t" split length .

See also
Official api docs.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=154&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Working code for the impatient</strong></p>
<p>The following factor code reads and counts the number of words in the file &#8220;/etc/fstab&#8221;</p>
<pre>
USING: io.encodings.ascii io io.files prettyprint splitting sequences ;
"/etc/fstab" ascii file-contents " \n\t" split length .
</pre>
<p><strong>See also</strong></p>
<p>Official <a href="http://docs.factorcode.org/content/article-io.files.html">api docs</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=154&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/04/10/reading-files-in-factor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>De-nesting decorators in python</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/04/06/de-nesting-decorators-in-python/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/04/06/de-nesting-decorators-in-python/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 21:45:19 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=151</guid>
		<description><![CDATA[Definitions of decorators are quite nested

def decorate(f):
    def patched(*args, **kwargs):
        # do stuff involving f
    return patched

About 25% I also forget to write the final &#8220;return patched&#8221;.
One way to work around this is to write a &#8216;denest decorator decorator&#8217; so you can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=151&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Definitions of decorators are quite nested</p>
<pre>
def decorate(f):
    def patched(*args, **kwargs):
        # do stuff involving f
    return patched
</pre>
<p>About 25% I also forget to write the final &#8220;return patched&#8221;.</p>
<p>One way to work around this is to write a &#8216;denest decorator decorator&#8217; so you can write the following as an alternative to the above:</p>
<pre>
@denest
def decorate(f, *args, *kwargs):
    # do stuff involving f
</pre>
<p>This has the disadvantage that you can&#8217;t perform operations at the time of decoration &#8211; but it simplifies code slightly for the standard case (at the cost of making your code less idiomatic).</p>
<p>The denest decorator is defined like this:</p>
<pre>
def denest(func):
     def decorate(f):
           def patched(*args, **kwargs):
               return func(f, *args, **kwargs)
            return patched
     return decorate
</pre>
<p><b>Example usage:</b></p>
<p>A decorator that converts converts a function which could raise an Excpetion into a function which returns None on error.</p>
<pre>
@denest
def makeIntoTry(f, *args, **kwargs):
    try:
        return f(*args, **kwargs)
    except Exception:
        return None
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=151&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/04/06/de-nesting-decorators-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Python generator to list decorator</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/03/29/python-generator-to-list-decorator/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/03/29/python-generator-to-list-decorator/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 15:42:19 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[decorator]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[listify]]></category>
		<category><![CDATA[note for self]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=139</guid>
		<description><![CDATA[Python generators can be evil because of the implicit state. How many time have you written done this?

items = get_items()
print items
f(items, x)

It might prevent confusion if generators are only used when you need lazy iteration. 
However, creating a list, appending to it several times and then returning it is an effort &#8211; which is probably [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=139&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Python generators can be evil because of the implicit state. How many time have you written done this?</p>
<pre>
items = get_items()
print items
f(items, x)
</pre>
<p>It might prevent confusion if generators are only used when you need lazy iteration. </p>
<p>However, creating a list, appending to it several times and then returning it is an effort &#8211; which is probably why I want to use generators when I don&#8217;t need to.</p>
<p>One workaround is to create a python generator to list decorator like so</p>
<pre>
def listify(gen):
    "Convert a generator into a function which returns a list"
    def patched(*args, **kwargs):
        return list(gen(*args, **kwargs))
    return patched

@listify
def f(x):
     for i in range(x):
        yield "item" + str(i)

assert f(5) == "item0 item1 item2 item3 item4".split()
</pre>
<p>One can also define a dictate decorator as follows</p>
<pre>
from functools import wraps

def dictate(func):
    @wraps(func)
    def patched(*args, **kwargs):
        return dict(*func(*args, **kwargs))
    return patched
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=139&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/03/29/python-generator-to-list-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Automatically populating a gcal event with reminders</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/03/22/automatically-populating-a-gcal-event-with-reminders/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/03/22/automatically-populating-a-gcal-event-with-reminders/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 20:56:58 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=133</guid>
		<description><![CDATA[I find it irritating to have to set reminders for google events by hand, so in the theme of efficient-over-effective here is a the urls.py of a django project which will create a new event in google calendar with several reminders and redirect you to a page for editing its details. If you have a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=133&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I find it irritating to have to set reminders for google events by hand, so in the theme of efficient-over-effective here is a the <em>urls.py</em> of a django project which will create a new event in google calendar with several reminders and redirect you to a page for editing its details. If you have a virtual server you could host this project there. You can then bookmark this url on the machines you use.</p>
<p>A little (if any) adaptation would make this work on google app engine (and might even allow you to login without hard coding a password).</p>
<p>Alternatives would be to write a greasemonkey script for google reader or write a ubiquity command that does this and redirects you to the page &#8211; but both these things seem more difficult to debug.</p>
<pre>
from django.conf.urls.defaults import patterns
from django.http import HttpResponseRedirect

import atom
import datetime
from gdata.calendar import CalendarEventEntry, When, Reminder
from gdata.calendar.service import CalendarService

def create_reminder(req):
    S = CalendarService()
    S.email = "EMAIL@ADDRESS"
    S.password = "password1"
    S.ProgrammaticLogin()

    event = CalendarEventEntry()
<ol>
<li>starttime is manditory - tomorrow seems as good a day as any</li>
</ol>

    def make_google_dt(dt):
      return dt.strftime('%Y-%m-%dT%H:%M:%S.000Z')

    now = datetime.datetime.now()

    start_datetime = now + datetime.timedelta(days=1)
    start_time = make_google_dt(start_datetime)
    end_time = make_google_dt(start_datetime + datetime.timedelta(minutes=30))

    occurence = When(start_time=start_time, end_time=end_time)
    occurence.reminder = [
        Reminder(hours=3, extension_attributes={'method':'sms'}),
        Reminder(days=2, extension_attributes={'method':'email'}), 
<ol>
<li>to feel happily surprised but not panic</li>
</ol>

        Reminder(days=7, extension_attributes={'method':'email'}),
        Reminder(days=14, extension_attributes={'method':'email'}),
        ]
    event.when.append(occurence)

    new_event = S.InsertEvent(event, '/calendar/feeds/default/private/full')
    edit_link = new_event.GetHtmlLink().href
    return HttpResponseRedirect(edit_link)

urlpatterns = patterns('',
    (r'', create_reminder)
)
</pre>
<p>Note that this is a slighlty evil &#8211; insofar as a GET request is having side effects&#8230; but POST commands are slightly troublesome to book mark, and adding a layer of indirection slightly defeats the purpose. </p>
<p><b> Technical notes </b></p>
<ul>
<li> Underneath the python library this is constructing and xml command and sending this to a google webservice.</li>
<li>
The python library does really support email reminders. It does however support adding arbitrary attributes to the xml element representing the reminder:</p>
<pre>
Reminder(days=7, extension_attributes={'method':'email'})
</pre>
<p>this add method=&#8221;email&#8221; to the reminder tag. (One can also set method=sms).</p>
<p>This is not documented in the google python documentation. It is (I think) documented in the gdata plain xml documentation.
</li>
<li>
For a working reference implementation in javascript using plain xml see the <a href="http://userscripts.org/scripts/show/7676">gtd tickler</a> greasemonkey gmail plugin.
</li>
</ul>
<p><b> Useful references </b><br />
<a href="http://code.google.com/apis/calendar/docs/1.0/developers_guide_python.html"> Google calendar interface from python &lt;/a</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=133&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/03/22/automatically-populating-a-gcal-event-with-reminders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting python argspecs</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/03/22/getting-python-argspecs/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/03/22/getting-python-argspecs/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 19:57:55 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[argspec]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=131</guid>
		<description><![CDATA[For the benefit of google:

def f(x, *args, **kwargs):
    return x
import inspect
print inspect.getargspec(f)

       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=131&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For the benefit of google:</p>
<pre>
def f(x, *args, **kwargs):
    return x
import inspect
print inspect.getargspec(f)
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=131&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/03/22/getting-python-argspecs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Human string comparison in python</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/03/18/human-string-comparison-in-python/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/03/18/human-string-comparison-in-python/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 00:35:23 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=126</guid>
		<description><![CDATA[
 NOTE: An alternative way to do this 
I&#8217;ve found a possible alternative to this. If you only want to sort strings in your current locale you can use locale.strcoll, which is a cmp function in your current locale. 

import locale
["one", "two", "three"].sort(locale.strcoll)
l

On my machine this still isn&#8217;t a very human friendly sort but depending [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=126&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div style="background:yellow;padding:5px;">
<strong> NOTE: An alternative way to do this </strong></p>
<p>I&#8217;ve found a possible alternative to this. If you only want to sort strings in your current locale you can use locale.strcoll, which is a cmp function in your current locale. </p>
<pre>
import locale
["one", "two", "three"].sort(locale.strcoll)
l
</pre>
<p>On my machine this still isn&#8217;t a very human friendly sort but depending on your LC_COLLATE environment variable it may be. This is very much less of a reinvent-the-wheel-because-buying-one-is-too-hard approach &#8211; though I suspect it might take one 4 times as long to get working&#8230;</p>
<p>Of course at times what you want your commadline to do isn&#8217;t what you want all other programs to do&#8230;
</p></div>
<hr />
<p>The string comparison in python does not order lists as one would expect:</p>
<pre>
&gt;&gt;&gt; l.sort(weird_strcmp)
&gt;&gt;&gt; l
['hello', '?', '}']
&gt;&gt;&gt; l = ["1", "Hello", "abc", "?", "}"]
&gt;&gt;&gt; l.sort()
&gt;&gt;&gt; l
['1', '?', 'Hello', 'abc', '}']
&gt;&gt;&gt;
</pre>
<p>python sorts strings as sequences of bytes.</p>
<p>I couldn&#8217;t find any easy way to sort strings in a more friendly fashion (Though surely one must exist?!) So here is an quick implementation of one (use this code as you wish):</p>
<pre>
from itertools import chain

letters = list(chain(*zip(range(0x41, 0x41 + 26),
               range(0x61, 0x61 + 26)))) # interspersed upper and lower

numbers = range(0x30, 0x30 + 10)

symbols = sorted(list(
        set(range(0x80)) - set(letters) - set(numbers)))

weird_order = list(chain(letters, numbers, symbols))

assert set(weird_order) == set(range(0x80)), "Didn't get every character"

def weird_strcmp(a, b):
    """Compare strings for lists for English humans who hate
         unicode and aren't using python 3k any time soon."""

    a = map(ord, a)
    b = map(ord, b)

    for x in chain(a, b):
        assert x &lt; 0x80, "%s is not in the ascii character range" % x

    a = map(weird_order.index, a)
    b = map(weird_order.index, b)
    return cmp(a, b)
</pre>
<pre>
&gt;&gt;&gt; l.sort(weird_strcmp)
&gt;&gt;&gt; l
['abc', 'Hello', '1', '?', '}']
</pre>
<p>Be aware that this isn&#8217;t really tested and may not order symbols how you think they should be. It, however, has the advantage of not taking you 15-30 minutes to write and debug. Say if you can think of any foibles and I&#8217;ll fix them.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=126&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/03/18/human-string-comparison-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging Wifi on Ubuntu Linux</title>
		<link>http://argandgahandapandpa.wordpress.com/2009/03/07/debugging-wifi-on-ubuntu-linux/</link>
		<comments>http://argandgahandapandpa.wordpress.com/2009/03/07/debugging-wifi-on-ubuntu-linux/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 17:14:28 +0000</pubDate>
		<dc:creator>existentiality</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wifi]]></category>

		<guid isPermaLink="false">http://argandgahandapandpa.wordpress.com/?p=117</guid>
		<description><![CDATA[To actually get ubuntu to give you some logging when connecting to wifi (you know so that you can act according to some information rather than at random):

Become superuser
Run killall NetworkManager 
Run NetworkManager &#8211;no-daemon

This will then give you output for every stage of the connection process.
Network manager is (I believe) the tool that handles the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=117&subd=argandgahandapandpa&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>To actually get ubuntu to give you some logging when connecting to wifi (you know so that you can act according to some information rather than at random):</p>
<ol>
<li>Become superuser</li>
<li>Run killall NetworkManager </li>
<li>Run NetworkManager &#8211;no-daemon</li>
</ol>
<p>This will then give you output for every stage of the connection process.</p>
<p>Network manager is (I believe) the tool that handles the overall process of opening a wifi connection using different processes (iwlist, iwconfig, wpa_supplicant etc) to do the actual connection.</p>
<p><b> Notes </b></p>
<p>Messages of the form &#8220;supplication connection state change number -&gt; number&#8221; are (i think) from wpa_supplicant. Someone who isn&#8217;t me should change NetworkManager so that these are written in english. For now note that the states mean the following:</p>
<p>0 &#8211; WPA is disconnected<br />
1 &#8211; WPA is inactive (no enabled connections and wpa isn&#8217;t trying to connect<br />
2 &#8211; WPA is scanning<br />
3 &#8211; WPA is associating (a loose-form of connection)<br />
4 &#8211; WPA is associated<br />
5 &#8211; WPA 4-way hand shake<br />
6 &#8211; WPA group handshake<br />
7 &#8211; WPA completed</p>
<p>I was seeing a lot of 3 -&gt; 0 state changes when I was debugging. [This was taken from the wpa_supplicant source code in src/common/defs.h]</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/argandgahandapandpa.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/argandgahandapandpa.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/argandgahandapandpa.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/argandgahandapandpa.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/argandgahandapandpa.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/argandgahandapandpa.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/argandgahandapandpa.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/argandgahandapandpa.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/argandgahandapandpa.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/argandgahandapandpa.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=argandgahandapandpa.wordpress.com&blog=2356703&post=117&subd=argandgahandapandpa&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://argandgahandapandpa.wordpress.com/2009/03/07/debugging-wifi-on-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da1c6e03b2ed78782c80a244a985b2b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Anon</media:title>
		</media:content>
	</item>
	</channel>
</rss>