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

<channel>
	<title>TikiRobot! &#187; code code</title>
	<atom:link href="http://www.tikirobot.net/wp/tag/code-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tikirobot.net/wp</link>
	<description>Mai Tais and Blinky Lights, Ahoy!</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:14:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hardware volume key support on XFCE</title>
		<link>http://www.tikirobot.net/wp/2010/07/20/hardware-volume-key-support-on-xfce/</link>
		<comments>http://www.tikirobot.net/wp/2010/07/20/hardware-volume-key-support-on-xfce/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 18:21:09 +0000</pubDate>
		<dc:creator>shag</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[beats]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[commandline]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=3165</guid>
		<description><![CDATA[XFCE4 from Debian unstable (&#8220;sid&#8221;) does not seem to bind the hardware volume-up, volume-down, and mute keyboard buttons on my ThinkPad to any actions.  It&#8217;s convenient to be able to control the sound card with these dedicated buttons &#8211; no twiddling around with the mouse to reach for a volume slider when NWA hits your playlist [...]]]></description>
			<content:encoded><![CDATA[<p>XFCE4 from Debian unstable (&#8220;sid&#8221;) does not seem to bind the hardware volume-up, volume-down, and mute keyboard buttons on my ThinkPad to any actions.  It&#8217;s convenient to be able to control the sound card with these dedicated buttons &#8211; no twiddling around with the mouse to reach for a volume slider when NWA hits your playlist and the boss walks over.  I suppose this is just a rough edge with the current XFCE integration; Gnome seems to handle this pretty well out of the box, but then again, Gnome is a bloated pig compared to XFCE.  So here&#8217;s one way to make the buttons work in XFCE.</p>
<p>First, you&#8217;ll need to make sure some prerequisite packages are installed: the package that provides the &#8220;amixer&#8221; binary, and some variant of awk.  Open an XFCE terminal window by clicking on the XFCE &#8220;mouse&#8221; logo in the XFCE panel, then clicking &#8220;Terminal&#8221;.  Become root by running the following and entering your root password:</p>
<p><code><br />
su -<br />
</code></p>
<p>Then install the appropriate packages &#8212; here&#8217;s how to do it in Debian:</p>
<p><code><br />
apt-get install alsa-utils mawk<br />
</code></p>
<p>Once the packages are installed, drop root privileges:</p>
<p><code><br />
exit<br />
</code></p>
<p>Then let&#8217;s pick a place for our scripts to live.  This example will assume that they will go into a &#8216;bin&#8217; directory underneath your home directory; so, let&#8217;s make sure that exists:</p>
<p><code><br />
mkdir ~/bin<br />
</code></p>
<p>Now, on to the scripts. Copy and paste the following script as &#8220;~/bin/alsa-toggle-mute&#8221;.  Probably the easiest way to do this with a stock Debian system is to start the &#8216;nano&#8217; editor with:</p>
<p><code><br />
nano ~/bin/alsa-toggle-mute<br />
</code></p>
<p>highlighting the script below, and then using your middle mouse button to paste the script into the nano terminal window, then using &#8220;Ctrl-x y ENTER&#8221; to save the file:</p>
<p><code><br />
&#35;!/bin/sh<br />
&#35;<br />
&#35; alsa-toggle-mute<br />
&#35;<br />
&#35;#########################################################<br />
&#35;<br />
&#35; AMIXER: path to your 'amixer' binary<br />
AMIXER=/usr/bin/amixer<br />
&#35;<br />
&#35; CONTROL: sound card control to adjust: run 'amixer' to find this<br />
CONTROL="Master,0"<br />
&#35;<br />
&#35; LEVELKEY: pattern on 'amixer' output lines to search for that provides<br />
&#35;           the current control level<br />
LEVELKEY=Mono:<br />
&#35;<br />
&#35;#########################################################<br />
&#35;<br />
$AMIXER sset $CONTROL \<br />
`$AMIXER sget $CONTROL |<br />
awk "(/$LEVELKEY/) { if (\\$NF == \\"[on]\\") { print \\"mute\\" } else { print \\"unmute\\" } }"` &gt; /dev/null<br />
</code></p>
<p>Make the script executable:</p>
<p><code><br />
chmod 700 ~/bin/alsa-toggle-mute<br />
</code></p>
<p>Then attach it to the hardware mute button with the XFCE keyboard settings manager GUI.  Click on the XFCE &#8220;mouse&#8221; logo that should be on the edge of your XFCE panel; click &#8220;Settings&#8221; from the pop-up menu; then click &#8220;Keyboard&#8221;.  Click on the &#8220;Application Shortcuts&#8221; tab.  Then click &#8220;Add&#8221;.  XFCE will ask for a path to the command; enter the full path to your alsa-toggle-mute script, e.g., &#8220;/home/username/bin/alsa-toggle-mute&#8221; &#8212; of course, you will have to substitute your username in that command.  XFCE will then pop up a box waiting for the &#8220;Command Shortcut&#8221; &#8212; at this point, press your hardware mute button.</p>
<p>That should be it! Your mute button should now work.</p>
<p>Now let&#8217;s add support for the volume-up button.  Save this script to &#8220;~/bin/alsa-volume-up&#8221;:</p>
<p><code><br />
&#35;!/bin/sh<br />
&#35;<br />
&#35; alsa-volume-up<br />
&#35;<br />
&#35;#########################################################<br />
&#35;<br />
&#35; OFFSET: amount to increment/decrement the control level: e.g., -1<br />
&#35;         decrements the volume, 1 increments the volume; values with<br />
&#35;         a greater absolute magnitude will decrement or increment the<br />
&#35;         control level more quickly.  Use "$1" if you wish to pass<br />
&#35;         the offset in from command line parameters<br />
OFFSET=1<br />
&#35;<br />
&#35; AMIXER: path to your 'amixer' binary<br />
AMIXER=/usr/bin/amixer<br />
&#35;<br />
&#35; CONTROL: sound control to adjust: run 'amixer' to find this<br />
CONTROL="Master,0"<br />
&#35;<br />
&#35; LEVELKEY: pattern on 'amixer' output lines to search for that provides<br />
&#35;           the current control level<br />
LEVELKEY=Mono:<br />
&#35;<br />
&#35; LEVELFIELD: awk field number of the current control level<br />
LEVELFIELD=3<br />
&#35;<br />
&#35;#########################################################<br />
&#35;<br />
$AMIXER sset $CONTROL \<br />
`$AMIXER sget $CONTROL | \<br />
awk "(/$LEVELKEY/) { print \\$$LEVELFIELD + $OFFSET }"` &gt; /dev/null<br />
</code></p>
<p>Make it executable:</p>
<p><code><br />
chmod 700 ~/bin/alsa-volume-up<br />
</code></p>
<p>Attach it to the hardware volume up button by following the same instructions as for the mute script (above), but in place of &#8220;/home/username/bin/alsa-toggle-mute&#8221;, use &#8220;/home/username/bin/alsa-volume-up&#8221;.  And rather than pressing the hardware mute button, press the hardware volume up button.</p>
<p>Then let&#8217;s handle the hardware volume down button.  This time we will take a shortcut.  Rather than copying and pasting another script, we&#8217;ll just copy and edit the volume-up script that you&#8217;ve already saved:</p>
<p><code><br />
cp ~/bin/alsa-volume-up ~/bin/alsa-volume-down<br />
</code></p>
<p>Then edit the ~/bin/alsa-volume-down script in nano to change the line that reads &#8220;OFFSET=1&#8243; to &#8220;OFFSET=-1&#8243;:</p>
<p><code><br />
nano ~/bin/alsa-volume-down<br />
</code></p>
<p>.. edit the script, then use &#8220;CTRL-x y ENTER&#8221; to save.</p>
<p>Then, as before, attach the script to the hardware volume down button by following the same instructions as for the mute script (above), but in place of &#8220;/home/username/bin/alsa-toggle-mute&#8221;, use &#8220;/home/username/bin/alsa-volume-down&#8221;.  And rather than pressing the hardware mute button, press the hardware volume down button.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2010/07/20/hardware-volume-key-support-on-xfce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Signing Amazon Web Services API Requests in Python</title>
		<link>http://www.tikirobot.net/wp/2010/01/24/signing-amazon-web-services-api-requests-in-python/</link>
		<comments>http://www.tikirobot.net/wp/2010/01/24/signing-amazon-web-services-api-requests-in-python/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:33:09 +0000</pubDate>
		<dc:creator>rajbot</dc:creator>
				<category><![CDATA[amazon]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2915</guid>
		<description><![CDATA[I wanted to ping the &#8220;Amazon Product Advertising API&#8221; which now requires an HMAC signature, and the pyAWS library doesn&#8217;t sign requests and is no longer maintained. Here is some Python code to create a signed request: # pyAWS no longer works with the AWS signed request requirement # Sign an AWS REST request using [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to ping the &#8220;Amazon Product Advertising API&#8221; which now requires an HMAC signature, and the pyAWS library doesn&#8217;t sign requests and is no longer maintained. Here is some Python code to create a signed request:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># pyAWS no longer works with the AWS signed request requirement</span>
<span style="color: #808080; font-style: italic;"># Sign an AWS REST request using the method described here</span>
<span style="color: #808080; font-style: italic;"># http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?RequestAuthenticationArticle.html</span>
<span style="color: #808080; font-style: italic;">#_______________________________________________________________________________</span>
<span style="color: #ff7700;font-weight:bold;">def</span> getSignedUrl<span style="color: black;">&#40;</span>accessKey, secretKey, params<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 0: add accessKey, Service, Timestamp, and Version to params</span>
    params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'AWSAccessKeyId'</span><span style="color: black;">&#93;</span> = accessKey
    params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Service'</span><span style="color: black;">&#93;</span>        = <span style="color: #483d8b;">'AWSECommerceService'</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Amazon adds hundredths of a second to the timestamp (always .000), so we do too.</span>
    <span style="color: #808080; font-style: italic;">#(see http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html)</span>
    params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Timestamp'</span><span style="color: black;">&#93;</span>      = <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y-%m-%dT%H:%M:%S.000Z&quot;</span>, <span style="color: #dc143c;">time</span>.<span style="color: black;">gmtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Version'</span><span style="color: black;">&#93;</span>        = <span style="color: #483d8b;">'2009-03-31'</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 1a: sort params</span>
    paramsList = params.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    paramsList.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 1b-d: create canonicalizedQueryString</span>
    <span style="color: #808080; font-style: italic;"># This code comes from http://blog.umlungu.co.uk/blog/2009/jul/12/pyaws-adding-request-authentication/</span>
    <span style="color: #808080; font-style: italic;"># and the resulting discussion</span>
    canonicalizedQueryString = <span style="color: #483d8b;">'&amp;'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'%s=%s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>k,<span style="color: #dc143c;">urllib</span>.<span style="color: black;">quote</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>k,v<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> paramsList <span style="color: #ff7700;font-weight:bold;">if</span> v<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 2: create string to sign</span>
    host          = <span style="color: #483d8b;">'ecs.amazonaws.com'</span>
    requestUri    = <span style="color: #483d8b;">'/onca/xml'</span>
    stringToSign  = <span style="color: #483d8b;">'GET<span style="color: #000099; font-weight: bold;">\n</span>'</span>
    stringToSign += host +<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
    stringToSign += requestUri+<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
    stringToSign += canonicalizedQueryString.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'utf-8'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 3: create HMAC</span>
    digest = <span style="color: #dc143c;">hmac</span>.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>secretKey, stringToSign, hashlib.<span style="color: black;">sha256</span><span style="color: black;">&#41;</span>.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 4: base64 the hmac</span>
    sig = <span style="color: #dc143c;">base64</span>.<span style="color: black;">b64encode</span><span style="color: black;">&#40;</span>digest<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">#Step 5: append signature to query</span>
    url  = <span style="color: #483d8b;">'http://'</span> + host + requestUri + <span style="color: #483d8b;">'?'</span>
    url += canonicalizedQueryString + <span style="color: #483d8b;">&quot;&amp;Signature=&quot;</span> + <span style="color: #dc143c;">urllib</span>.<span style="color: black;">quote</span><span style="color: black;">&#40;</span>sig<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> url</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2010/01/24/signing-amazon-web-services-api-requests-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast manipulation of tar files using 7zip</title>
		<link>http://www.tikirobot.net/wp/2010/01/20/fast-manipulation-of-tar-files-using-7zip/</link>
		<comments>http://www.tikirobot.net/wp/2010/01/20/fast-manipulation-of-tar-files-using-7zip/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 01:43:32 +0000</pubDate>
		<dc:creator>rajbot</dc:creator>
				<category><![CDATA[archive]]></category>
		<category><![CDATA[code code]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2903</guid>
		<description><![CDATA[tar always reads every byte in an archive (never calles seek()) and is very slow when trying to extract a single file from a large archive. One solution is to use 7z instead, which is found in the p7zip-full debian package. For some operations, 7z is three orders of magnitude faster than tar. Here are [...]]]></description>
			<content:encoded><![CDATA[<p><strong>tar</strong> always reads every byte in an archive (never calles seek()) and is <strong>very</strong> slow when trying to extract a single file from a large archive.</p>
<p>One solution is to use 7z instead, which is found in the p7zip-full debian package. For some operations, 7z is three orders of magnitude faster than tar. Here are some timings that illustrate how much faster 7z is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#4.5GB archive listing using tar</span>
<span style="color: #000000; font-weight: bold;">time</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> tvf fifteenthcensus00reel2149_jp2.tar 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#40;</span>output suppressed, timing stable whether <span style="color: #c20cb9; font-weight: bold;">file</span> cache is warmed or not<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
real	2m1.876s
user	0m0.444s
sys	0m7.740s
&nbsp;
<span style="color: #666666; font-style: italic;">#4.5GB archive listing using 7z with cold file cache</span>
<span style="color: #000000; font-weight: bold;">time</span> 7z l fifteenthcensus00reel2149_jp2.tar 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#40;</span>output suppressed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
real	0m10.419s
user	0m0.080s
sys	0m0.124s
<span style="color: #000000;">5</span>:<span style="color: #000000;">28</span> PM
&nbsp;
<span style="color: #666666; font-style: italic;">#4.5GB archive listing using 7z with hot file cache</span>
<span style="color: #000000; font-weight: bold;">time</span> 7z l fifteenthcensus00reel2149_jp2.tar 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#40;</span>output suppressed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
real	0m0.145s
user	0m0.052s
sys	0m0.040s
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#extraction of last file in a 4.5GB archive using tar</span>
<span style="color: #000000; font-weight: bold;">time</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xvf fifteenthcensus00reel2149_jp2.tar fifteenthcensus00reel2149_jp2<span style="color: #000000; font-weight: bold;">/</span>fifteenthcensus00reel2149_0185.jp2
&nbsp;
real	2m3.545s
user	0m0.436s
sys	0m7.824s
&nbsp;
<span style="color: #666666; font-style: italic;">#extraction of last file in a 4.5GB archive using 7z and a hot file cache</span>
<span style="color: #000000; font-weight: bold;">time</span> 7z e fifteenthcensus00reel2149_jp2.tar fifteenthcensus00reel2149_jp2<span style="color: #000000; font-weight: bold;">/</span>fifteenthcensus00reel2149_0185.jp2
&nbsp;
real	0m0.104s
user	0m0.036s
sys	0m0.036s</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2010/01/20/fast-manipulation-of-tar-files-using-7zip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zaggle Gets You There with Personalized Event Newsletter</title>
		<link>http://www.tikirobot.net/wp/2009/11/10/zaggle-gets-you-there-with-personalized-event-newsletter/</link>
		<comments>http://www.tikirobot.net/wp/2009/11/10/zaggle-gets-you-there-with-personalized-event-newsletter/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:25:40 +0000</pubDate>
		<dc:creator>peliom</dc:creator>
				<category><![CDATA[upcoming]]></category>
		<category><![CDATA[bay area]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[lifehacking]]></category>
		<category><![CDATA[tiki lifestyle]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2802</guid>
		<description><![CDATA[Over at the Zaggle Togetherness Blog we have a very important announcement :-) Our new personalized email newsletter aggregates all the events your friends are attending into one simple email digest. You can set the email frequency anywhere from once per day to once per week. Here is a short example of what the email [...]]]></description>
			<content:encoded><![CDATA[<p>Over at the <a href="http://blog.wezaggle.com/">Zaggle Togetherness Blog</a> we have a <a href="http://blog.wezaggle.com/2009/11/new-personalized-events-newsletter.html">very important announcement</a> :-)</p>
<blockquote><p>Our new personalized email newsletter aggregates all the events your friends are attending into one simple email digest. You can set the email frequency anywhere from once per day to once per week. Here is a short example of what the email might look like, most emails will have more events than this.</p></blockquote>
<p><a href="http://www.wezaggle.com/personal"><img src="http://www.tikirobot.net/wp/wp-content/uploads/2009/11/mock_300.png" alt="Example of Personalized Zaggle Events Newsletter" title="Example of Personalized Zaggle Events Newsletter" width="300" height="368" class="size-full wp-image-2803" /></a></p>
<blockquote><p>
If you think Zaggle is useful, please help spread the word by posting this link on Facebook, Twitter or anywhere else with lots of friends: <a href="http://bit.ly/zeemail">http://bit.ly/zeemail</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/11/10/zaggle-gets-you-there-with-personalized-event-newsletter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Pretty-Print a Python ElementTree Structure</title>
		<link>http://www.tikirobot.net/wp/2009/07/29/how-to-pretty-print-a-python-elementtree-structure/</link>
		<comments>http://www.tikirobot.net/wp/2009/07/29/how-to-pretty-print-a-python-elementtree-structure/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 19:59:06 +0000</pubDate>
		<dc:creator>rajbot</dc:creator>
				<category><![CDATA[code code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2611</guid>
		<description><![CDATA[ElementTree doesn&#8217;t support pretty-printing XML. lxml does, but isn&#8217;t installed on our system. minidom&#8216;s toprettyxml() is seriously fucked up. What to do? Turned out PyXML was installed, so I took some advice from here and came up with this function, which takes an ET node and returns a pretty-printed string: import xml.etree.ElementTree as ET &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.python.org/library/xml.etree.elementtree.html">ElementTree</a> doesn&#8217;t support pretty-printing XML. <a href="http://codespeak.net/lxml/">lxml</a> does, but isn&#8217;t installed on our system. <a href="http://docs.python.org/library/xml.dom.minidom.html">minidom</a>&#8216;s toprettyxml() is seriously fucked up. What to do? Turned out PyXML  was installed, so I took some advice <a href="http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/">from here</a> and came up with this function, which takes an ET node and returns a pretty-printed string:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">etree</span>.<span style="color: black;">ElementTree</span> <span style="color: #ff7700;font-weight:bold;">as</span> ET
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">dom</span>.<span style="color: black;">ext</span>.<span style="color: black;">reader</span> <span style="color: #ff7700;font-weight:bold;">import</span> Sax2
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">dom</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> PrettyPrint
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">StringIO</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> prettyPrintET<span style="color: black;">&#40;</span>etNode<span style="color: black;">&#41;</span>:
    reader = Sax2.<span style="color: black;">Reader</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    docNode = reader.<span style="color: black;">fromString</span><span style="color: black;">&#40;</span>ET.<span style="color: black;">tostring</span><span style="color: black;">&#40;</span>etNode<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    tmpStream = <span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    PrettyPrint<span style="color: black;">&#40;</span>docNode, stream=tmpStream<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> tmpStream.<span style="color: black;">getvalue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/07/29/how-to-pretty-print-a-python-elementtree-structure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Counting&#8230;</title>
		<link>http://www.tikirobot.net/wp/2009/07/15/counting/</link>
		<comments>http://www.tikirobot.net/wp/2009/07/15/counting/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 17:04:19 +0000</pubDate>
		<dc:creator>may</dc:creator>
				<category><![CDATA[binary]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[einstein]]></category>
		<category><![CDATA[spreadshirt]]></category>
		<category><![CDATA[tshirt]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2558</guid>
		<description><![CDATA[I made myself a tshirt a couple weeks ago on Spreadshirt. They&#8217;re awesome! A lot better than any other print-to-order service I&#8217;ve tried like Cafe Press and Zazzle. The shirt is based off of this one that I saw a friend wearing. I didn&#8217;t like what it said though so mine says something different :-) [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tikirobot.net/wp/wp-content/uploads/2009/07/einsteinshirt.jpg" alt="einsteinshirt" title="einsteinshirt" width="500" height="375" class="alignnone size-full wp-image-2557" /></p>
<p>I made myself a tshirt a couple weeks ago on <a href="http://www.spreadshirt.com/">Spreadshirt</a>.  They&#8217;re awesome! A lot better than any other print-to-order service I&#8217;ve tried like Cafe Press and Zazzle.  The shirt is based off of <a href="http://www.thinkgeek.com/tshirts-apparel/womens/38dd/">this one</a> that I saw a friend wearing.  I didn&#8217;t like what it said though so mine says something different :-)  You can&#8217;t see the whole phrase in the photo above but you can see it below (in a different font).</p>
<p><img src="http://www.tikirobot.net/wp/wp-content/uploads/2009/07/einstein03.gif" alt="einstein03" title="einstein03" width="500" height="750" class="alignnone size-full wp-image-2556" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/07/15/counting/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Zaggle: A Social Calendar For You and Your Friends</title>
		<link>http://www.tikirobot.net/wp/2009/07/08/zaggle-a-social-calendar-for-you-and-your-friends/</link>
		<comments>http://www.tikirobot.net/wp/2009/07/08/zaggle-a-social-calendar-for-you-and-your-friends/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 11:07:55 +0000</pubDate>
		<dc:creator>peliom</dc:creator>
				<category><![CDATA[upcoming]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[lifehacking]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2542</guid>
		<description><![CDATA[Well, here it is, the first rough cut of a Facebook Connect website that gathers all your Facebook events into one handy place. Check it out! and let us know what you think &#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.wezaggle.com/?ref=trP1img"><img src="http://www.tikirobot.net/wp/wp-content/uploads/2009/07/Picture-76.png" alt="Zaggle" title="Zaggle" width="362" height="127" class="alignnone size-full wp-image-2543" /></a></p>
<p>Well, here it is, the first rough cut of a Facebook Connect website that gathers all your Facebook events into one handy place.  <a href="http://www.wezaggle.com/?ref=trP1txt">Check it out!</a> and let us know what you think &#8230;<br />
<a href="http://www.wezaggle.com/?ref=trP1preview"><img src="http://www.tikirobot.net/wp/wp-content/uploads/2009/07/Picture-75-500x408.png" alt="Zaggle Preview Screenshot" title="Zaggle Preview Screenshot" width="500" height="408" class="alignnone size-medium wp-image-2545" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/07/08/zaggle-a-social-calendar-for-you-and-your-friends/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>fotobook widget and plugin for wordpress</title>
		<link>http://www.tikirobot.net/wp/2009/05/24/fotobook-widget-and-plugin-for-wordpress/</link>
		<comments>http://www.tikirobot.net/wp/2009/05/24/fotobook-widget-and-plugin-for-wordpress/#comments</comments>
		<pubDate>Mon, 25 May 2009 06:36:24 +0000</pubDate>
		<dc:creator>tracey pooh</dc:creator>
				<category><![CDATA[photos]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[ddAdd new tag]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2508</guid>
		<description><![CDATA[Make your facebook photos magically appear on your wordpress site OK I&#8217;m certainly not all that and a bag of chips, but set to roll out in one week for a 565 mile bike trip to LA (over 7 days &#8212; I&#8217;m not *that* crazy 8-) I wanted to see if there was a nice/cute [...]]]></description>
			<content:encoded><![CDATA[<h3>Make your facebook photos magically appear on your wordpress site</h3>
<p>OK I&#8217;m certainly not all that and a bag of chips, but set to roll out in one week for a 565 mile bike trip to LA (over 7 days &#8212; I&#8217;m not *that* crazy 8-) I wanted to see if there was a nice/cute way to make me:</p>
<ul>
<li>take pictures with my ifone</li>
<li>use the facebook app (to either take a picture or select one from ifone)</li>
<li>upload to facebook</li>
<li>have it automatically show up on my site</li>
</ul>
<p>the first 3 are easy-peasy.  you throw money at the problem and get the ifone with its legendarily crappy cell service and the free facebook app.</p>
<p>for the last point, i searched around wordpress plugins and <strong>found</strong><strong> &#8220;fotobook&#8221; plugin</strong> (which also comes with two default disabled widgets).</p>
<p>it&#8217;s a liddle scary &#8212; you login to facebook while it&#8217;s &#8220;bugging&#8221; you, but once you done that (and given it your car keys) it figures out all your photo albums.   you can pick which albums you want to show/hide.   you can login/auth more accounts/people too (but so far I only love myself).  to make my left-hand column &#8220;NEW TRACEY PIX&#8221; on</p>
<p><a href="http://www.dumbbunny.org/">my wordpress site</a></p>
<p>show up, I enabled the &#8220;photos widget&#8221;, set it to &#8220;most recent&#8221;, and tweaked the underlying PHP code to make a simple link to my facebook &#8220;mobile uploads&#8221; public page.</p>
<p>I think there&#8217;s an &#8220;update all albums&#8221; button somewhere, but there&#8217;s also simple instruction to &#8220;cron a get of url [X]&#8221; every X period of time so I did that.  Next, I tested it and &#8220;voila!&#8221; 5 minutes later, and then a few hours later when Hunter tagged me in some pictures, the left-hand widget updated as if by magic.</p>
<p>I guess this sort of thing excites me.  May be old hat.  I know raj got tikirobot auto-posting the twitter feeds so maybe he&#8217;s figured something like this out already too.</p>
<p>neat, no?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/05/24/fotobook-widget-and-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TikiTV In Action</title>
		<link>http://www.tikirobot.net/wp/2009/04/12/tikitv-in-action/</link>
		<comments>http://www.tikirobot.net/wp/2009/04/12/tikitv-in-action/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 05:29:47 +0000</pubDate>
		<dc:creator>rajbot</dc:creator>
				<category><![CDATA[photos]]></category>
		<category><![CDATA[san francisco]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[beats]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[code code]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[tikitv]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2440</guid>
		<description><![CDATA[Here are some old pics of Sam and Peliom vj-ing with the open source TikiTV software at the Timothy Leary Archives event at 111 Minna. Way fun!]]></description>
			<content:encoded><![CDATA[<p>Here are some old pics of Sam and Peliom vj-ing with the open source <a href="http://tikitv.net/">TikiTV</a> software at the <a href="http://www.timothylearyarchives.org/">Timothy Leary Archives</a> event at 111 Minna. Way fun!</p>
<p><a href="http://www.flickr.com/photos/rkumar/3351915417/" title="IMG_5628"><img src="http://farm4.static.flickr.com/3644/3351915417_755f56a989.jpg" width="500" height="375" alt="IMG_5628" /></a></p>
<p><a href="http://www.flickr.com/photos/rkumar/3352740860/" title="IMG_5631"><img src="http://farm4.static.flickr.com/3448/3352740860_07527e9899.jpg" width="500" height="375" alt="IMG_5631" /></a></p>
<p><a href="http://www.flickr.com/photos/rkumar/3351915359/" title="IMG_5629"><img src="http://farm4.static.flickr.com/3620/3351915359_113596ec03.jpg" width="500" height="375" alt="IMG_5629" /></a></p>
<p><a href="http://www.flickr.com/photos/rkumar/3352741290/" title="IMG_5633 by rkumar, on Flickr"><img src="http://farm4.static.flickr.com/3540/3352741290_72260bb1bb.jpg" width="375" height="500" alt="IMG_5633" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/04/12/tikitv-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to run lighttpd under upstart</title>
		<link>http://www.tikirobot.net/wp/2009/03/28/how-to-run-lighttpd-under-upstart/</link>
		<comments>http://www.tikirobot.net/wp/2009/03/28/how-to-run-lighttpd-under-upstart/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 04:23:51 +0000</pubDate>
		<dc:creator>rajbot</dc:creator>
				<category><![CDATA[code code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[upstart]]></category>

		<guid isPermaLink="false">http://www.tikirobot.net/wp/?p=2385</guid>
		<description><![CDATA[Upstart is Ubuntu&#8217;s init.d replacement. It greatly simplifies writing init.d scripts and has a great respawn feature similar to daemontool&#8217;s supervise or monit. And it comes with Ubuntu by default. For some reason, almost no one uses upstart. Even Ubuntu&#8217;s services use traditional /etc/init.d scripts instead of upstart scripts. I think this might be due [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://upstart.ubuntu.com/">Upstart</a> is Ubuntu&#8217;s init.d replacement. It greatly simplifies writing init.d scripts and has a great respawn feature similar to daemontool&#8217;s supervise or monit. And it comes with Ubuntu by default.</p>
<p>For some reason, almost no one uses upstart. Even Ubuntu&#8217;s services use traditional /etc/init.d scripts instead of upstart scripts. I think this might be due to upstart&#8217;s non-existent documentation. There is no man page for upstart, and multiple people I know who have read <a href="http://upstart.ubuntu.com/getting-started.html">the online docs</a> somehow missed the three important commands that control upstart jobs: <strong>/sbin/start</strong>, <strong>/sbin/stop</strong>, and <strong>/sbin/status</strong>!</p>
<p>Here is how it works: put an upstart script in /etc/event.d. Let&#8217;s call it /etc/event.d/foo. This script is now immediately available under upstart. Just type <tt><strong>sudo start foo</strong></tt>. That&#8217;s it.</p>
<p>I converted Ubuntu&#8217;s /etc/init.d/lighttpd script to a much shorter upstart script. The big advantage of this is upstart will restart lighttpd if it dies for some reason. This is what the upstart script looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this is an upstart script that  starts lighttpd</span>
&nbsp;
start on runlevel <span style="color: #000000;">2</span>
start on runlevel <span style="color: #000000;">3</span>
start on runlevel <span style="color: #000000;">4</span>
start on runlevel <span style="color: #000000;">5</span>
&nbsp;
stop on runlevel <span style="color: #000000;">0</span>
stop on runlevel <span style="color: #000000;">1</span>
stop on runlevel <span style="color: #000000;">6</span>
&nbsp;
respawn
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> www-data lighttpd <span style="color: #660033;">-D</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>lighttpd-infobase.conf</pre></div></div>

<p>That&#8217;s it! Save this script as /etc/event.d/OL-lighttpd, and then type <tt><strong>sudo start OL-lighttpd</strong></tt>. You can kill off the lighttpd process and it will get restarted.</p>
<p>If you want to configure your lighttpd to write out a pid file, you can use pre-start and post-stop script to prepare and clean up the pid file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this is an upstart script that  starts lighttpd</span>
&nbsp;
start on runlevel <span style="color: #000000;">2</span>
start on runlevel <span style="color: #000000;">3</span>
start on runlevel <span style="color: #000000;">4</span>
start on runlevel <span style="color: #000000;">5</span>
&nbsp;
stop on runlevel <span style="color: #000000;">0</span>
stop on runlevel <span style="color: #000000;">1</span>
stop on runlevel <span style="color: #000000;">6</span>
&nbsp;
&nbsp;
pre-start script
    <span style="color: #666666; font-style: italic;">#make sure there is a place to write the pid file (optional):</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>lighttpd <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
    <span style="color: #c20cb9; font-weight: bold;">chown</span> www-data:www-data <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>lighttpd
    <span style="color: #c20cb9; font-weight: bold;">chmod</span> 0750 <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>lighttpd
end script
&nbsp;
respawn
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> www-data lighttpd <span style="color: #660033;">-D</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>lighttpd-infobase.conf
&nbsp;
post-stop script
    <span style="color: #666666; font-style: italic;">#remove pid file (optional)</span>
    <span style="color: #666666; font-style: italic;">#add server.pid-file = &quot;/var/run/lighttpd/lighttpd.pid&quot; to lighttpd.conf file to have it generate the pid file</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>lighttpd<span style="color: #000000; font-weight: bold;">/</span>lighttpd.pid
end script</pre></div></div>

<p>If you want to stop lighttpd, just type <tt><strong>sudo stop OL-lighttpd</strong></tt>. You can also type <tt><strong>sudo initctl list</strong></tt> for a list of all jobs under upstart.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tikirobot.net/wp/2009/03/28/how-to-run-lighttpd-under-upstart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

