<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/"/>

<title>Jeff Epler's blog</title>
<modified>2012-04-04T12:54:44Z</modified>
<tagline>Photos, electronics, cnc, and more</tagline>
<author><name>Jeff Epler</name><email>jepler@unpythonic.net</email></author>
<entry>
<title>dusub: Subtract two 'du'-style listings</title>
<issued>2012-04-04T12:54:44Z</issued>
<modified>2012-04-04T12:54:44Z</modified>
<id>http://emergent.unpythonic.net/01333544084</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01333544084"/>
<content type="text/html" mode="escaped">
Life is a constant war against the limited size of backup media.  Here
is my next weapon in the fight: dusub.  Save a &lt;tt&gt;du&lt;/tt&gt; listing
today, then find out tomorrow or next week what's been growing:
&lt;pre&gt;dusub olddu newdu&lt;/pre&gt;
Positive numbers in the output represent an item that grew since olddu;
negative numbers represent a decrease in size since olddu.

&lt;p&gt;Presently, dusub only knows how to deal with plain du, not 'du -h'.
&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;http://media.unpythonic.net/emergent-files/01333544084/dusub.py&quot;&gt;dusub.py&lt;/a&gt;&lt;/td&gt;&lt;td&gt;1.4kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;</content>
</entry>
<entry>
<title>Every once in a while, ssh is too slow</title>
<issued>2012-03-06T01:35:28Z</issued>
<modified>2012-03-06T01:35:28Z</modified>
<id>http://emergent.unpythonic.net/01330997728</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01330997728"/>
<content type="text/html" mode="escaped">

I'm using my OLPC XO-1 as a music server which allows anyone in the household
the ability to play, stop, pause, adjust volume, and so on.  This was first
done by 'ssh olpc ...', but there's a substantial delay between issuing
the action and its effect.  So I wrote a simple web service that does the same
thing.  It turns out that most of the time is ssh overhead that's not present
in a http connection.

&lt;p&gt;&lt;pre&gt;
$ time ssh olpc /home/olpc/bin/cmus-playpause
real  0m0.522s
$ time wget -O /dev/null http://olpc:8000/playpause
real  0m0.066s
&lt;/pre&gt;

&lt;p&gt;It's nothing like the &lt;a href=&quot;http://emergent.unpythonic.net/01330399156&quot;&gt;384x speedup I got&lt;/a&gt;
the last time I was complaining about the olpc's performance, but it's still
nothing to sneeze at.
</content>
</entry>
<entry>
<title>Half-maximize script for Linux</title>
<issued>2012-02-29T15:42:38Z</issued>
<modified>2012-02-29T15:42:38Z</modified>
<id>http://emergent.unpythonic.net/01330530158</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01330530158"/>
<content type="text/html" mode="escaped">
A number of times, I've said that I like the Windows 7 feature that allows
a window to easily be half-maximized.  I got tired of waiting for it to be
added to my favorite window manager, so I wrote a script that uses
the program &lt;tt&gt;wmctrl&lt;/tt&gt; to half-maximize windows, then bound it
to key presses in my window manager.  Now, with a press of ctrl+alt+[QWER],
I can half-maximize a window into 4 locations on my dual-monitor setup.</content>
</entry>
<entry>
<title>Every once in a while, Python is too slow</title>
<issued>2012-02-28T03:19:16Z</issued>
<modified>2012-02-28T03:19:16Z</modified>
<id>http://emergent.unpythonic.net/01330399156</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01330399156"/>
<content type="text/html" mode="escaped">

I recently acquired a USB-connected relay that controls a standard power outlet,
called the &amp;quot;USB NET POWER 8800&amp;quot;.  I'd ordered this with the knowledge that
there was a Python implementation of the control program that was said to run
on Linux.

&lt;p&gt;It does work, but I was stunned at how long it took to switch the outlet on
or off: a couple of seconds!  I should disclaim that it's running on a rather
underpowered machine (the OLPC XO-1 with a Geode x86 CPU @ 430MHz), but this
was way too long to be acceptable:
&lt;pre&gt;
$ time py-usbpower query
Power: on

real    0m2.690s
user    0m1.484s
sys     0m0.096s
&lt;/pre&gt;
With some detective work, I discovered that ctypes is doing things like running
the compiler, objdump(!) and ldconfig(!), several times (!!), at each
invocation of the program. (this is python2.5, but it looks like Python 2.7's
ctypes still does essentially the same thing, unfortunately)

&lt;p&gt;I set about to code this in C.  For my reward, I got a very fast-executing
program:
&lt;pre&gt;
$ time c-usbpower status
ON

real    0m0.007s
user    0m0.000s
sys     0m0.000s
&lt;/pre&gt;

&lt;p&gt;That's something like a 384x speedup.  Lesson?  ctypes has some very
substantial startup costs for loading a library.  It may be enough to make it
unsuitable for a short-lived program.

&lt;p&gt;In case it's useful to you, I enclose a copy of my usbpower program.  It's
under the terms of the GNU GPLv2.

&lt;p&gt;&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;http://media.unpythonic.net/emergent-files/01330399156/usbpower.c&quot;&gt;usbpower.c&lt;/a&gt;&lt;/td&gt;&lt;td&gt;3.4kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;
</content>
</entry>
<entry>
<title>sorttop: show the biggest values as a program runs</title>
<issued>2012-02-19T16:54:33Z</issued>
<modified>2012-02-19T16:54:33Z</modified>
<id>http://emergent.unpythonic.net/01329670473</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01329670473"/>
<content type="text/html" mode="escaped">
When I am looking for big disk users, I don't care about all the little items.
What would be great is to continuously see the biggest items encountered so
far.

&lt;p&gt;To this end, I've written a Python program I call 'sorttop'; it continually
reads stdin, sorts the first column according to magic (i.e., human numbers like from &amp;quot;du -h&amp;quot; work as expected), and shows the top items
read so far.  Example usage: &lt;tt&gt;du -hx / | python sorttop.py&lt;/tt&gt;

&lt;p&gt;&lt;b&gt;Update, Feb 20, 2012&lt;/b&gt;: Revised the script to work for more terminals;
fixes a traceback on the line 'bol = curses.tparm(ti_hpa, 0)' when TERM=screen.

&lt;p&gt;&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;http://media.unpythonic.net/emergent-files/01329670473/sorttop.py&quot;&gt;sorttop.py&lt;/a&gt;&lt;/td&gt;&lt;td&gt;3.3kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;</content>
</entry>
<entry>
<title>20 years of computers</title>
<issued>2012-01-20T13:51:22Z</issued>
<modified>2012-01-20T13:51:22Z</modified>
<id>http://emergent.unpythonic.net/01327067482</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01327067482"/>
<content type="text/html" mode="escaped">During some downtime, I made a list of all the computers I could
remember owning.  The list is surprisingly long, and goes back to 1992
(before which I had a Commodore 64 but that barely counts, does it?)  I came up
with 10 desktops and 7 laptops, or a new machine nearly every year.  The last 5
years have only seen 3 new machines, though, so the pace at which I buy
computers may be slowing.</content>
</entry>
<entry>
<title>Transfer of contacts from LG Remarq to Debian GNU/Linux</title>
<issued>2012-01-18T01:11:28Z</issued>
<modified>2012-01-18T01:11:28Z</modified>
<id>http://emergent.unpythonic.net/01326849088</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01326849088"/>
<content type="text/html" mode="escaped">

The device would pair with Linux, but would not appear when &amp;quot;transfer
contacts&amp;quot; was invoked.  The secret:
&lt;pre&gt;
sudo /usr/sbin/hciconfig hci0 class 0x5a020c
&lt;/pre&gt;

&lt;p&gt;After this, I was able to transfer using the facilities built into gnome; I got a bunch of &amp;quot;.vcf&amp;quot; files in ~/Downloads.

&lt;p&gt;Apparently the Remarq won't transfer to a device that is &amp;quot;Unknown&amp;quot;; this sets
the computer to a &amp;quot;phone&amp;quot; bluetooth device.

&lt;p&gt;I'm not sure whether this setting will &amp;quot;stick&amp;quot; or be required before each
transfer, after a reboot, or what…
</content>
</entry>
<entry>
<title>It's gratifying when the compiler is right</title>
<issued>2011-12-27T20:35:02Z</issued>
<modified>2011-12-27T20:35:02Z</modified>
<id>http://emergent.unpythonic.net/01325018102</id>
<link rel="alternate" type="text/html" href="http://emergent.unpythonic.net/01325018102"/>
<content type="text/html" mode="escaped">I've been playing with &lt;a href=&quot;http://clang.llvm.org&quot;&gt;clang&lt;/a&gt;
because I'd like to use its &lt;a href=&quot;http://clang-analyzer.llvm.org/&quot;&gt;static analyzer&lt;/a&gt; on the code at $DAY_JOB.  Unfortunately, it frequently bombs
while building our code.  Fortunately, many of the bombs are due to our bugs,
not theirs.  Here's one example:</content>
</entry>
</feed>

