<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>random ramblings, mostly about programming by David Jensen</description><title>burning broccoli</title><generator>Tumblr (3.0; @burningbroccoli)</generator><link>http://burningbroccoli.se/</link><item><title>Simple video streaming with apache to Samsung Galaxy Tab</title><description>&lt;p&gt;Ok, so I&amp;#8217;d like to watch videos on my Samsung Galaxy Tab without the hassle of copying them from my computer. I thought streaming with VLC would be a nice option. It probably is, but I didn&amp;#8217;t get it to work. The tab has great support for media formats which means I only need streaming - no converting, so I thought why not use plain old apache? And it worked pretty well, playback is smooth and I can jump around nearly instantaneously.  This is my setup:&lt;/p&gt;

&lt;p&gt;First if you don&amp;#8217;t have it install apache2 and symlink your video folder into /var/www. Then check your servers ip adress with ifconfig&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ sudo apt-get install apache2
$ sudo ln -s /home/bb/Video /var/www/video
$ ifconfig
&lt;/pre&gt;

&lt;p&gt;After that just open up the browser in the tab (with your servers ip adress of course)&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
&lt;a href="http://192.168.1.100/video" target="_blank"&gt;http://192.168.1.100/video&lt;/a&gt;
&lt;/pre&gt;

&lt;p&gt;Depending on file type I get a choice of programs to handle the file, for some reason .mp4 files triggers a dialog with just &lt;em&gt;Android-system&lt;/em&gt; and &lt;em&gt;Browser&lt;/em&gt;, just choose &lt;em&gt;Android-system&lt;/em&gt; and you&amp;#8217;ll get a proper dialog of choices. One problem I got was that the standard video player can&amp;#8217;t handle all the formats, I use &lt;a href="https://play.google.com/store/apps/details?id=com.inisoft.mediaplayer.trial&amp;amp;feature=search_result" target="_blank"&gt;Dice Player&lt;/a&gt; which works very well for me.&lt;/p&gt;</description><link>http://burningbroccoli.se/post/20186549327</link><guid>http://burningbroccoli.se/post/20186549327</guid><pubDate>Fri, 30 Mar 2012 23:15:18 +0200</pubDate><category>samsung galaxy tab</category><category>android</category><category>apache</category></item><item><title>Cucumber testing with Kyuri in a browser</title><description>&lt;p&gt;&lt;a href="http://cukes.info/" target="_blank"&gt;Cucumber&lt;/a&gt; is a really nice testing framework, but I dislike having to implement the step definitions in ruby when the project itself is not in ruby, but what (web) project use javascript so why not do cucumber testing with javascript?&lt;/p&gt;

&lt;p&gt;There are a couple of solutions for this, &lt;a href="https://github.com/cucumber/cucumber-jvm" target="_blank"&gt;Cucumber JVM&lt;/a&gt; (former cuke4duke) is an official java based version of cucumber that let&amp;#8217;s you use any jvm language. That&amp;#8217;s cool, and probably a good way to go, but not fun enough for me. It messes with my mojo to start the jvm for something like this. And besides, there is no documentation on defining steps in javascript. &lt;a href="https://github.com/cucumber/cucumber-js" target="_blank"&gt;Cucumer-js&lt;/a&gt; is a pure javascript alternative that looks good, uses node  and seems very cool. But it lacks i18n support, it seems to be actively developed on so this is certainly something to keep an eye on. Cucumber-js also has support for running it in the browser via &lt;a href="https://github.com/substack/node-browserify" target="_blank"&gt;browserify&lt;/a&gt;. A third cool alternative is &lt;a href="https://github.com/nodejitsu/kyuri" target="_blank"&gt;Kyuri&lt;/a&gt;, another pure javascript implementation, and it has support for i18n! Kyuri is also node based, can it be used in a browser? This is the steps that I took to get it running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;
Install browserify and kyuri with npm.&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ sudo npm --global browserify
$ npm install kyuri
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Browserify&lt;/strong&gt;
Kyuri actually has two ways to define steps, as &amp;#8220;cucumber&amp;#8221; and  &lt;a href="http://vowsjs.org/" target="_blank"&gt;vows&lt;/a&gt;, vows seems to be the main target, but it doesn&amp;#8217;t translate well to the browser. It has dependencies that browserify can&amp;#8217;t handle. So we cut it out, which means a little bit of tweaking:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ browserify -r kyuri  -i /node_modules/kyuri/node_modules/vows/lib/vows.js -i ./kyuri/runners/vows -o kyuri-bundle.js
&lt;/pre&gt;

&lt;p&gt;This will give you a kyuri-bundle.js, it lacks vows.js and its runner but it still tries to require it so we need to edit it a bit. Remove this line (it&amp;#8217;s line 375)&lt;/p&gt;

&lt;pre class="sh_javascript"&gt;
kyuri.runners.vows = require('./kyuri/runners/vows');
&lt;/pre&gt;

&lt;p&gt;And these just below:&lt;/p&gt;

&lt;pre class="sh_javascript"&gt;
// Set default runner to vows
kyuri.runner = kyuri.runners.vows;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Browser&lt;/strong&gt;
This is a sample html page to test it:&lt;/p&gt;

&lt;pre class="sh_javascript"&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&amp;gt;
    &amp;lt;title&amp;gt;Kyuri&amp;lt;/title&amp;gt;
    &amp;lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" language="javascript" charset="utf-8" &amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="kyuri-bundle.js" type="text/javascript" language="javascript" charset="utf-8" &amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type="text/javascript" language="javascript" charset="utf-8"&amp;gt;
        var kyuri = require('kyuri');
        
        var Runner = kyuri.runners.cucumber;

        Runner.on('beforeTest', function (done) {
          console.log('beforeTest event');
          done();
        });

        Runner.on('beforeBackground', function (done) {
          console.log('beforeBackground event');
          done();
        });

        Runner.on('afterTest', function (done) {
          console.log('afterTest event');
          done();
        });
        
        $(document).ready(function(){
            
            //features
            var features = [];
            $('.feature').each(function(){
                console.log(kyuri.parse($(this).text()));
                features.push(kyuri.parse($(this).text()));
            });
            
            //step defitions
            var Steps = require('kyuri').Steps;

            Steps.Given(/^I have entered (\d+) into the calculator$/, function (step, num) {
              console.log('Calculator: ' + num);
              step.done();
            });
            
            var module = {};
            Steps.export(module);
            
            var steps  = module.exports;
            
            //run it
            kyuri.runners.cucumber.run(features, steps, function () {
                console.log("Done!");
            });
            
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    
&amp;lt;pre class="feature"&amp;gt;
Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers

    Scenario: Add two numbers
        Given I have entered 50 into the calculator
        And I have entered 70 into the calculator
        When I press add
        Then the result should be 120 on the screen
&amp;lt;/pre&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Caveats&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;This only works in Firefox for me, Chrome has a minor error (probably easy to fix).&lt;/li&gt;
&lt;li&gt;It logs console color codes&amp;#8230; looks weird&lt;/li&gt;
&lt;/ul&gt;</description><link>http://burningbroccoli.se/post/19572039439</link><guid>http://burningbroccoli.se/post/19572039439</guid><pubDate>Mon, 19 Mar 2012 15:01:56 +0100</pubDate><category>kyuri</category><category>cucumber</category><category>javascript</category><category>node</category><category>browserify</category></item><item><title>Chroot'd Ubuntu on Samsung Galaxy S (Android)</title><description>&lt;p&gt;So I got my hands on a &lt;a href="http://galaxys.samsungmobile.com/" target="_blank"&gt;Samsung Galaxy S&lt;/a&gt; (or SGS) a while ago, and it&amp;#8217;s a really nice phone using Android 2.1 as it OS. Before I settled on the SGS the Nokia N900 had caught my eye. The 900 has great hardware and its OS is more of a &amp;#8220;standard&amp;#8221; Linux. Its Maemo OS is really just a Linux distro with all that entails (X11,QT,GTK), this means you can easily run any Linux app you can compile, and since it&amp;#8217;s easy to install Debian or Ubuntu chroot&amp;#8217;d on it you can even run things like OpenOffice etc (But the speed and screen real estate won&amp;#8217;t be good). The problem is that Maemo is &lt;a href="http://meego.com/community/blogs/imad/2010/welcome-meego" target="_blank"&gt;being merged into to Meego&lt;/a&gt; and there is only one phone, the N900, which means no apps what so ever except open source ones.&lt;/p&gt;

&lt;p&gt;Android is linux based, but it doesn&amp;#8217;t use X11 and most applications are written in Java and executed on a custom JVM called &amp;#8216;Dalvik&amp;#8217;. Therefore I was a bit sceptical of buying a android device, it felt a bit stupid to not take advantage of the massive amount of open source programs, libraries and toolkits out there. I still do, but android struck me as a much more mature OS, an it&amp;#8217;s very nice to have lot&amp;#8217;s of apps :-)&lt;/p&gt;

&lt;p&gt;Anyway, having linux underneath means that we can easily install a chroot&amp;#8217;d Ubuntu in Android, giving us access to many nice applications&amp;#8230; like openssh, python, webservers, transsmission (with web gui) etc. This is nothing new, it has been done before, both with &lt;a href="http://www.saurik.com/id/10" target="_blank"&gt;Debian&lt;/a&gt; and &lt;a href="http://nexusonehacks.net/nexus-one-hacks/ubuntu-on-nexus-one-android/" target="_blank"&gt;Ubuntu&lt;/a&gt;, but here is how I did it on my SGS. If you don&amp;#8217;t know what chroot is, &lt;a href="http://en.wikipedia.org/wiki/Chroot" target="_blank"&gt;read up&lt;/a&gt; before you do anything. For X11 application there is a &lt;a href="http://forum.xda-developers.com/showthread.php?t=486247" target="_blank"&gt;trick with VNC&lt;/a&gt; to get them running, I haven&amp;#8217;t tried it yet though.&lt;/p&gt;

&lt;h2&gt;A couple of prerequisites:&lt;/h2&gt;

&lt;ul&gt;&lt;li&gt;Root access (su)&lt;/li&gt;
&lt;li&gt;busybox&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;I got both by rooting my phone after &lt;a href="http://www.swedroid.se/forum/showthread.php?t=15049" target="_blank"&gt;this guide&lt;/a&gt; .&lt;/p&gt;

&lt;h2&gt;Partition&lt;/h2&gt;

&lt;p&gt;First of we need somewhere to put the system, android uses FAT32 for the SD card and that&amp;#8217;s no good for us. We need a real file system, like ext4. Unfortunately the kernel in my SGS didn&amp;#8217;t support it. You can get a list of supported filesystems with &amp;#8216;cat /proc/filesystems&amp;#8217;. This is from my
SGS:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ cat /proc/filesystems
nodev   sysfs
nodev   rootfs
nodev   bdev
nodev   proc
nodev   cgroup
nodev   binfmt_misc
nodev   sockfs
nodev   pipefs
nodev   anon_inodefs
nodev   tmpfs
nodev   inotifyfs
nodev   devpts
    ext3
    ext2
    cramfs
nodev   ramfs
    vfat
    msdos
    romfs
    rfs
    j4fs

&lt;/pre&gt;

&lt;p&gt;So we settle for ext3. The easiest way to partition the SD card is to connect it to you&amp;#8217;re computer (not through the phone), and use gparted. I used the SD card reader on my laptop with the use of an adapter that came with the card when I bought it. It&amp;#8217;s best to just shrink the vfat partition because if you remove it your phone is going to complain that the card is broken or needs formatting. If your starting from scratch just make sure the vfat partition is the first partition.&lt;/p&gt;

&lt;p&gt;The size of the ext3 partition of course depends on the size of your SD card. But at least 1 gigabyte is probably a good idea. I used a 2 gigabyte card, 512 megabytes for the vfat, the rest for the ext3 partition. Don&amp;#8217;t forget to tell gparted to format your new partition.&lt;/p&gt;

&lt;h2&gt;Create a rootfs with rootstock&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://launchpad.net/project-rootstock" target="_blank"&gt;Rootstock&lt;/a&gt; is a great tool for building a basic ubuntu image to use with your ARM based device. It uses good old &lt;a href="http://wiki.debian.org/Debootstrap" target="_blank"&gt;debootstrap&lt;/a&gt;, running the second stage of the installation (the one you usually need to run on the device) under qemu. Pretty smart. This means that the tarball you get is a fully finished root base file system. You can even specify some extra packages that rootstock can install. A SSH server is a good idea, I like less, screen, ne (nice editor, like nano but with ordinary key-bindings, like ctrl-s etc), build-essential so that  we can compile things.&lt;/p&gt;

&lt;p&gt;Note that you specify a user and a password. You should choose a good password.&lt;/p&gt;

&lt;p&gt;Create a rootfs tarball:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ sudo rootstock --fqdn ubuntu --login sgs --password temporary --imagesize 1G --seed openssh-server,less,build-essential,screen,ne
&lt;/pre&gt;

&lt;p&gt;Unpack the tarball and copy the content to your fine new partition on the SD card.
Then set up googles DNS server (the ext3 partition is mounted on /mnt):&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ mv mv armel-rootfs-201008012234.tgz /mnt/
$ cd /mnt
$ tar xvzf armel-rootfs-201008012234.tgz
$ rm armel-rootfs-201008012234.tgz 
$ echo 'nameserver 8.8.8.8' &amp;gt; etc/resolv.conf
&lt;/pre&gt;

&lt;p&gt;It&amp;#8217;s time to put the card back into the phone&amp;#8230;&lt;/p&gt;

&lt;h2&gt;Now on your phone&lt;/h2&gt;

&lt;p&gt;For the rest you need to drop into root:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ su
#
&lt;/pre&gt;

&lt;p&gt;First mount the ext3 partition, I use a dir on the SD card called &amp;#8220;ubuntu&amp;#8221;, you can put it anywhere you want though. Since the SGS has internal storage too the SD card has the device /dev/block/mmcblk1p2&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
# busybox mount /dev/block/mmcblk1p2 /sdcard/sd/ubuntu
&lt;/pre&gt;

&lt;p&gt;chroot by itself is not enough, we need to mount /proc,/dev and /sysfs too.
An the path on android is a bit strange so we need to set that too.&lt;/p&gt;

&lt;p&gt;Tap this on your phone for a glorious chrooted ubuntu:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
# busybox mount -t proc proc /sdcard/sd/ubuntu/proc
# busybox mount --bind /sys /sdcard/sd/ubuntu/sys
# busybox mount --bind  /dev /sdcard/sd/ubuntu/dev
# export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH
# busybox chroot /sdcard/sd/ubuntu 
&lt;/pre&gt;

&lt;h2&gt;Log in via SSH&lt;/h2&gt;

&lt;p&gt;When your chroot&amp;#8217;d you can start the SSH server and log into it that way. This will give you full terminal emulation (as opposed to &amp;#8220;adb shell&amp;#8221;), i.e.bash completion, emacs, vim etc.&lt;/p&gt;

&lt;p&gt;Start server and check what ip nr your phone has&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
# /etc/init.d/ssh start
# ifconfig | grep "inet addr"
&lt;/pre&gt;

&lt;p&gt;Note that since this is Ubuntu the root user doesn&amp;#8217;t have any password so you have to ssh to it with the user name  and password you specified to rootstock. In my example above that&amp;#8217;s &amp;#8220;sgs&amp;#8221; and &amp;#8220;temporary&amp;#8221;. To get root privileges use sudo, remember this is Ubuntu.&lt;/p&gt;

&lt;h2&gt;A script to help&lt;/h2&gt;

&lt;p&gt;If you think tapping all that mounts and path etc on your phone is a bit tiresome to tap you can make a script of it. Shell scripting is not my strong point so it can probably be improved, but it seems to work for me. It mounts the ext3 partition and sets up everything needed. Note that it does &lt;em&gt;not&lt;/em&gt; drop you into a chroot&amp;#8217;d ubuntu, it just starts the ssh server.&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
#!/bin/sh
#we need to setup test [
busybox ln -s /system/xbin/busybox /system/xbin/[

if [ -d /sdcard/sd/ubuntu/etc ] ; then
    echo "ubuntu partition is already mounted"
else
    echo "Mounting ext3 partition to /sdcard/sd/ubuntu"
    busybox mount -o noatime /dev/block/mmcblk1p2 /sdcard/sd/ubuntu

    echo 'Mounting proc,sys and dev'
    busybox mount -t proc proc /sdcard/sd/ubuntu/proc
    busybox mount --bind /sys /sdcard/sd/ubuntu/sys
    busybox mount --bind  /dev /sdcard/sd/ubuntu/dev
fi

echo 'Exporting a proper path'
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH

echo 'Chrooting and starting ssh server'
busybox chroot /sdcard/sd/ubuntu /etc/init.d/ssh start

echo "And your ip is:"
busybox ifconfig | busybox grep "inet addr"
&lt;/pre&gt;

&lt;p&gt;Put it on the sdcard  or the on the internal storage and execute it like this:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ su
# sh /sdcard/sd/ubuntu.sh
&lt;/pre&gt;</description><link>http://burningbroccoli.se/post/949205350</link><guid>http://burningbroccoli.se/post/949205350</guid><pubDate>Sat, 14 Aug 2010 00:12:00 +0200</pubDate><category>android</category><category>samsung galaxy s</category><category>sgs</category><category>ubuntu</category><category>chroot</category></item><item><title>PHPUnit 3.4 in Karmic</title><description>&lt;p&gt;The PHPUnit package in karmic is only version 3.3.* and if you need the Yaml support, as I do, you need 3.4. 
A good thing &lt;a href="http://packages.ubuntu.com/en/lucid/phpunit" target="_blank"&gt;lucid lynx&lt;/a&gt; has an appropriate  package.&lt;/p&gt;

&lt;p&gt;Just download and install with gdebi.&lt;/p&gt;</description><link>http://burningbroccoli.se/post/423982752</link><guid>http://burningbroccoli.se/post/423982752</guid><pubDate>Wed, 03 Mar 2010 12:04:16 +0100</pubDate></item><item><title>Re-inventing the wheel: A logging development SMTP server</title><description>&lt;p&gt;I found myself in a spot of trouble while trying to debug some newsletter sending plugin in &lt;a href="http://plone.org" target="_blank"&gt;Plone&lt;/a&gt; called &lt;a href="http://plone.org/products/dancing/" target="_blank"&gt;Singing &amp;amp; Dancing&lt;/a&gt;. The problem was that I had made a local installation of the application server and the Python version I had to run it on had no support for TLS/SSL. This meant my ordinary outgoing mailserver wouldn&amp;#8217;t work.&lt;/p&gt;

&lt;p&gt;Well anyway that would have been a bad solution to send &amp;#8220;for real&amp;#8221; since I just needed to see that the mails looked good and where addressed  to the right people. So now I probably should have done the obvious and googled  a bit, there seems to be &lt;a href="http://matt.blogs.it/entries/00002655.html" target="_blank"&gt;quite&lt;/a&gt; a &lt;a href="http://quintanasoft.com/dumbster/" target="_blank"&gt;few&lt;/a&gt; simple &lt;a href="http://code.activestate.com/recipes/440690/" target="_blank"&gt;SMTP&lt;/a&gt; servers, but I alas I did not. What I did was to re-invent the wheel a bit.&lt;/p&gt;

&lt;p&gt;Python has some nice SMTP handling modules both for &lt;a href="http://docs.python.org/library/smtplib.html" target="_blank"&gt;sending&lt;/a&gt; and &lt;a href="http://docs.python.org/library/smtpd.html" target="_blank"&gt;receiving&lt;/a&gt;. There is already a debugging SMTP server that just prints any received message. You can start it directly with:&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ python -m smtpd -n -c DebuggingServer localhost:2525
&lt;/pre&gt;

&lt;p&gt;This was nearly what I needed, the only problem was that the mails where &lt;a href="http://en.wikipedia.org/wiki/Base64" target="_blank"&gt;Base64&lt;/a&gt; encoded so it wasn&amp;#8217;t obvious that they where correct.&lt;/p&gt;

&lt;p&gt;Wouldn&amp;#8217;t it be nice if we could view the mails directly in a email application? Well with a little tinkering we can. Again, the standard library in Python to the rescue. This time the &lt;a href="http://docs.python.org/library/mailbox.html" target="_blank"&gt;mailbox&lt;/a&gt; module. The mailbox module can write email messages to &lt;a href="http://en.wikipedia.org/wiki/Mbox" target="_blank"&gt;mbox&lt;/a&gt; files or &lt;a href="http://en.wikipedia.org/wiki/Maildir" target="_blank"&gt;maildirs&lt;/a&gt;, both old and tried and ancient formats for mail box storage. The great thing about a maildir is that several mail readers can parse it, like &lt;a href="http://projects.gnome.org/evolution/" target="_blank"&gt;evolution&lt;/a&gt; (but not &lt;a href="http://www.mozillamessaging.com" target="_blank"&gt;Thunderbird&lt;/a&gt;! AFAIK)&lt;/p&gt;

&lt;p&gt;To read mails in a maildir in evolution you just add a new account (it&amp;#8217;s under &lt;em&gt;settings&lt;/em&gt;) and then select the maildir format. It will then ask you for a folder, the script takes arguments to define it but the default is &lt;code&gt;~/.devbox&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To start the server (I called it &lt;em&gt;devbox&lt;/em&gt;, as in a &amp;#8220;development inbox&amp;#8221;):&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ devbox --port=2525 --maildir=foobar/mymail
&lt;/pre&gt;

&lt;p&gt;Use &lt;code&gt;-h&lt;/code&gt; to get help of the options and remember that if you need to bind against port 25 you need to be root or use sudo. Heres the code, and as you can see one third is GPL preamble, the other third is the option parsing and it&amp;#8217;s only really one small class that does the trivial job of passing on the mail between the SMTPServer and the Maildir. I love Python standard library!&lt;/p&gt;

&lt;pre class="sh_python"&gt;
#!/usr/bin/python
#    Copyright 2010 David Jensen 
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see &lt;&gt;&lt;/&gt;.

import mailbox
import smtpd
import asyncore
from optparse import OptionParser

class DevBox(smtpd.SMTPServer):

    def __init__(self,port,maildir):
        smtpd.SMTPServer.__init__(self,('localhost',port),('localhost',25))
        self.mbox = mailbox.Maildir(maildir)

    def process_message(self, peer, mailfrom, rcpttos, data):
        self.mbox.lock()
        self.mbox.add(data)
        self.mbox.flush()
        self.mbox.unlock()
        print "Added a msg from ",mailfrom

if __name__ == '__main__':
    usage=""" %prog [options]
    
%prog is debugging SMTP server bound to localhost. Useful
for when you need to test outgoing mail but do not want any
mail actually sent. All incoming  messages are saved in a maildir 
for later perusal regardless of any possible address. 
What comes in won't come out."""
    
    parser = OptionParser(usage,version="%prog 0.1")
    parser.add_option("-m", "--maildir",action="store", type="string", 
                      dest="maildir",default='~/.devbox',
                      help='sets the path to the maildir [default: %default]')
    parser.add_option("-p", "--port",action="store", type="int", 
                      dest="port",default=25, 
                      help='sets the port the server listens to [default: %default]')
    (options, args) = parser.parse_args()

    print "Starting server on localhost:%i, with maildir %s" % (options.port,options.maildir)
    dn = DevBox(options.port,options.maildir)
    
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        pass
&lt;/pre&gt;</description><link>http://burningbroccoli.se/post/354573348</link><guid>http://burningbroccoli.se/post/354573348</guid><pubDate>Tue, 26 Jan 2010 18:00:00 +0100</pubDate><category>python</category><category>smtp</category></item><item><title>keyboard shortcuts to focus applications using python-wnck</title><description>&lt;p&gt;In a &lt;a href="http://burningbroccoli.se/post/240221250/python-wnck" target="_blank"&gt;previous post&lt;/a&gt; I fiddled a bit with python-wnck and made a small script that bound &lt;em&gt;&amp;lt;Super&amp;gt;P&lt;/em&gt; key to activating previous focused window, i.e. last app you where looking at. This was kind of useful since I often find myself spending way to much time and effort jumping between applications. Window lists,pagers and good looking compiz effects that does the same thing all have one thing in common, I have to identify a name, image or icon and select it. In short, I have to search for it.&lt;/p&gt;

&lt;p&gt;You may think I have very little patience, pressing &lt;em&gt;&lt;alt&gt;TAB&lt;/alt&gt;&lt;/em&gt; a couple of times to find the window of an app can&amp;#8217;t take that much time, can it? Well, no, not really - but since I&amp;#8217;m programmer I tend to work with multiple applications at the same time (email,browser,eclipse,spotify,terminal(s),nautilus etc) and I switch between them &lt;strong&gt;a lot&lt;/strong&gt; in one day. Actually it&amp;#8217;s not the speed that bothers me, more that I already know which window/application I want and it&amp;#8217;s frustrating to have to search for it every damn time!&lt;/p&gt;

&lt;p&gt;So what&amp;#8217;s my brilliant solution to this? Well my first thought (obviously) was some kind of direct neural interface so that the computer could just infer what I wanted before I even knew wanted it. But since that is a bit too much to engineer on one lunch break I opted for a simpler solution:  creating a couple of shortcuts for my most used apps.&lt;/p&gt;

&lt;p&gt;The script below does half of the job, it tries to find a window matching the supplied application name. If it does gives it focus. If not it will try to start it.&lt;/p&gt;

&lt;p&gt;The script takes one or two arguments, the first is the application name as it is in the &lt;a href="http://burningbroccoli.se/post/241766391/listing-windows-with-python-wnck" target="_blank"&gt;window list&lt;/a&gt;. If that is the same as the executable your&amp;#8217;re all set. Otherwise the second argument is the executables name.&lt;/p&gt;

&lt;p&gt;A couple of examples&lt;/p&gt;

&lt;pre class="sh_sh"&gt;
$ ./activate.py evolution
$ ./activate.py Terminal gnome-terminal
&lt;/pre&gt;

&lt;p&gt;I use &lt;a href="http://wiki.compiz-fusion.org/CCSM" target="_blank"&gt;CompizConfig Settings Manager&lt;/a&gt; and to set global key bindings, so now whenever I tap &lt;em&gt;&amp;lt;Super&amp;gt;T&lt;/em&gt; the gnome-terminal springs to life.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the script, the only requirement is python-wnck.&lt;/p&gt;

&lt;pre class="sh_python"&gt;
#!/usr/bin/python2.6
import wnck
import sys
import time
import subprocess as sub

if len(sys.argv)  [&lt;executable&gt;]"
    sys.exit(1)

name = sys.argv[1]
timestamp = int(time.time())

screen = wnck.screen_get_default();
screen.force_update()
wins = screen.get_windows()
for win in wins:
    app = win.get_application()
    if app is not None:
        if name == app.get_name():
            geo = win.get_geometry()
            screen.move_viewport(max(geo[0],0),max(geo[1],0)) #bugs a bit, unclear why
            win.activate(timestamp)
            sys.exit(0)
            
#if we get this far we didn't find the program, let's start it
if len(sys.argv) &amp;gt;= 3:
    sub.Popen(sys.argv[2],shell=True)
else:
    sub.Popen(sys.argv[1],shell=True)
&lt;/executable&gt;&lt;/pre&gt;</description><link>http://burningbroccoli.se/post/246419714</link><guid>http://burningbroccoli.se/post/246419714</guid><pubDate>Mon, 16 Nov 2009 23:24:00 +0100</pubDate></item><item><title>listing windows with python-wnck</title><description>&lt;p&gt;&lt;em&gt;So as I said in my previous post I&amp;#8217;ve recently found the nice litte  &lt;a href="http://library.gnome.org/devel/libwnck/stable/" target="_blank"&gt;libwnck&lt;/a&gt; and it&amp;#8217;s python bindings.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are lots of fun things you can do with it, try exploring it with &lt;a href="http://ipython.scipy.org/moin/" target="_blank"&gt;ipython&lt;/a&gt; and you&amp;#8217;ll see what I mean.&lt;/p&gt;

&lt;p&gt;Anyways I wanted to share a little snippet of code with you, this will list all windows and print out their name in the form &lt;em&gt;application name:window name&lt;/em&gt;&lt;/p&gt;

&lt;pre class="sh_python"&gt;
#!/usr/bin/python2.6
import wnck

screen = wnck.screen_get_default()
screen.force_update() #updates the window list
wins = screen.get_windows()
for win in wins:
    app = win.get_application()
    win_name  = win.get_name() or ''
    app_name = app and app.get_name() or ''
    print '%s: %s' % (app_name,win_name)

&lt;/pre&gt;</description><link>http://burningbroccoli.se/post/241766391</link><guid>http://burningbroccoli.se/post/241766391</guid><pubDate>Thu, 12 Nov 2009 21:30:00 +0100</pubDate></item><item><title>python-wnck</title><description>&lt;p&gt;I just found out about a nifty litlle library called &lt;a href="http://library.gnome.org/devel/libwnck/stable/" target="_blank"&gt;libwnck&lt;/a&gt; and it&amp;#8217;s python bindings are in the ubuntu repositories under the name &lt;a href="apt:python-wnck" target="_blank"&gt;python-wnck&lt;/a&gt;.  Its all about window management. It&amp;#8217;s meant to be used for applications like window lists and workspace switchers etc. You can maximize windows, change current workspace etc.&lt;/p&gt;

&lt;p&gt;So the first thing I did (naturally) was to write a little script that can change to previously activated window, which is nice to have when jumping frequently between two windows (like eclipse and chromium). To bind a global key it uses a library from &lt;a href="http://projecthamster.wordpress.com/screenshots/" target="_blank"&gt;Project Hamster&lt;/a&gt; which in turn uses a lib from &lt;a href="http://projects.gnome.org/tomboy/" target="_blank"&gt;Tomboy&lt;/a&gt;, don&amp;#8217;t ask me why&amp;#8230; Anyway, this means that you also need to install the package &lt;a href="apt:hamster-applet" target="_blank"&gt;hamster-applet&lt;/a&gt; to try out this script. It also has some other problems, activating a window on a different workspace doesn&amp;#8217;t work. I&amp;#8217;ll fix that later.&lt;/p&gt;

&lt;h2&gt;Installing and running&lt;/h2&gt;

&lt;p&gt;Just copy the script into a text editor, save it as &lt;code&gt;focus_last.py&lt;/code&gt; or and run it with &lt;code&gt;python focus_last.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The keycode for focusing the last window is &lt;code&gt;&amp;lt;Super&amp;gt;P&lt;/code&gt;&lt;/p&gt;

&lt;pre class="sh_python"&gt;
#!/usr/bin/python2.6
#   Copyright David Jensen 2009
#   This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see &lt;&gt;&lt;/&gt;.

import gtk
import gobject
import wnck
import hamster.keybinder as keybinder
import sys

import time
KEY_COMBINATION = '&amp;lt;Super&amp;gt;P'

class FocusShifter(object):
    def __init__(self):
        self.last_window = None       
        try:
            print 'Binding shortcut %s to focus last window' % KEY_COMBINATION
            keybinder.tomboy_keybinder_bind(KEY_COMBINATION, self.focus_last) 
        except KeyError:
            # if the requested keybinding conflicts with an existing one, a KeyError will be thrown
            print 'Key binding conflict, exiting'
            sys.exit(1)
        self.screen = wnck.screen_get_default();
        
    def focus_last(self):
        timestamp = int(time.time())
        win = self.screen.get_previously_active_window()
        #print "Prev win",win
        if win is not None:
            win.activate(timestamp) #not sure what timestamp should be, but this seems to work
            
f = FocusShifter()
gobject.MainLoop().run()
 
&lt;/pre&gt;</description><link>http://burningbroccoli.se/post/240221250</link><guid>http://burningbroccoli.se/post/240221250</guid><pubDate>Wed, 11 Nov 2009 13:20:57 +0100</pubDate></item><item><title>ELIZA</title><description>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/ELIZA" target="_blank"&gt;Eliza&lt;/a&gt; is a neat little program &lt;a href="http://en.wikipedia.org/wiki/Joseph_Weizenbaum" target="_blank"&gt;created in the 60s by Joseph Weizenbaum&lt;/a&gt;. It&amp;#8217;s been around a long time. I heard about it the first time during my university studies and the first version i tried was the &lt;a href="http://www.emacswiki.org/emacs/EmacsDoctor" target="_blank"&gt;&amp;#8216;doctor&amp;#8217; in emacs&lt;/a&gt; (Emacs rules, vim should die!).&lt;/p&gt;

&lt;p&gt;Anyway, a long story short, a friend of mine starting to talk about it one night while we where chucking down some beers and listening to stand up comedy. I don&amp;#8217;t know why but it stuck in my mind so I googled it a bit. My first idea was to see if there where a python implementation (I&amp;#8217;m python biased when I have the luxury to choose), and sure thing there was one, &lt;a href="http://www.jezuk.co.uk/cgi-bin/view/software/eliza" target="_blank"&gt;eliza.py&lt;/a&gt;, with BSD license. It was nice and simple, using regular expressions for most of the work. A bit old though, had to change a import from &amp;#8216;whrandom&amp;#8217; to &amp;#8216;random&amp;#8217;.&lt;/p&gt;

&lt;p&gt;After tinkering around a bit it struck me that the simplest and most portable solution (webwise) would be a javascript implementation. So I made a simple jQuery plugin of it.&lt;/p&gt;

&lt;p&gt;To try or download go to &lt;a href="http://davidlgj.github.com/eliza-jquery/" target="_blank"&gt;&lt;a href="http://davidlgj.github.com/eliza-jquery/" target="_blank"&gt;http://davidlgj.github.com/eliza-jquery/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://burningbroccoli.se/post/240168431</link><guid>http://burningbroccoli.se/post/240168431</guid><pubDate>Wed, 11 Nov 2009 11:47:00 +0100</pubDate></item><item><title>OK so I stayed</title><description>&lt;p&gt;Yep. Finally decided. I&amp;#8217;m staying here.&lt;/p&gt;</description><link>http://burningbroccoli.se/post/240164424</link><guid>http://burningbroccoli.se/post/240164424</guid><pubDate>Wed, 11 Nov 2009 11:40:14 +0100</pubDate></item><item><title>Just a test</title><description>&lt;p&gt;I&amp;#8217;m reviewing &lt;b&gt;tumblr&lt;/b&gt;, just to see how it works. I was lured here by the promise of simple posting + custom html/css and javascript&lt;/p&gt;</description><link>http://burningbroccoli.se/post/125430509</link><guid>http://burningbroccoli.se/post/125430509</guid><pubDate>Wed, 17 Jun 2009 23:40:20 +0200</pubDate></item><item><title>Just testing. This is an image from a postit stuck to the...</title><description>&lt;img src="http://25.media.tumblr.com/bYilWCkzuotvf501ZpJ4kDBjo1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Just testing. This is an image from a postit stuck to the overview map of Seattle Airport (section B I, think..)&lt;/p&gt;</description><link>http://burningbroccoli.se/post/125316600</link><guid>http://burningbroccoli.se/post/125316600</guid><pubDate>Wed, 17 Jun 2009 19:37:49 +0200</pubDate></item></channel></rss>

