Sawfish and Emacs/org-mode

Hi there, Today I'm going to write a small example on connecting the Sawfish window manager to the Emacs text editor.

Why might you want to do this? Well mostly I just wanted to further my usage of Emacs, and thought the idea of being able to clock in and out of tasks in org-mode whenever I change workspace or window would be pretty cool. Of course both Sawfish and Emacs make extensive use of the Lisp programming language) so it is a natural fit :)

To start off, you'll want to be using the Sawfish window manager, and you'll want to have emacs.jl somewhere in your lisp path. From there you can put something like the following in your ~/.sawfish/rc:

;; Require emacs.jl for emacs functions
(require 'emacs)

;; Define a hook to be run on workspace change, utilizes the emacs-eval function defined in emacs.jl
(define (my-enter-workspace-hook)
  (emacs-eval (format nil "(org-clock-in-on-workspace-change %S)" (nth current-workspace workspace-names))))

;; Add our hook!
(add-hook 'enter-workspace-hook my-enter-workspace-hook)

You will need to reload Sawfish for these changes to take effect (or you can eval them from Emacs).

Read more...

Scheme-to-PHP

/images/chicken.png

I'm writing this post to inform of my latest GitHub repo, Scheme-to-PHP, which contains the beginnings of a very very naive Scheme to PHP5 translator. It will do so by implementing r4rs (or maybe r5rs) forms and macros in Scheme, that return the equivalent strings of PHP code, hopefully forming a working PHP script. There will be a way of calling native PHP functions and classes, and Scheme functions such as map will be mapped (no pun intended) to the equivalent PHP function (eg. array_map).

This is being written using Chicken Scheme, which I'm currently spending most of my time hacking about with and is totally awesome :)

Comment on this post.

XMMSinatra

Last night I released the first version of XMMSinatra, a tiny and minimal XMMS2 web client written in Sinatra (Ruby). You can find the code and a screenshot at the Github repository.

/images/xmmsinatra_thumb.png

Comment on this post.

Hackfest Weekend

Back from a really fun hacking weekend in Wellington, where I met some new people (and fellow hackers) and got to work on a project integrating TBB further into the HipHop-PHP compiler (and exposing it to PHP), which can be found at Github. We made some pretty good progress and came up with a few pretty graphs.

As mentioned in the last post, I have decided to purchase a Linode VPS for a couple of months to try it out, and so far I am super impressed with the overall service. I will be using it mainly as a LNMP (Linux, Nginx, MySQL, PHP) host and so far it is doing the job well. I will also be spending the coming months looking further into RoR, Perl, a couple of NoSQL servers (CouchDB, Redis), and maybe a message passing framework or two. This will also give me a chance to play around with some monitoring systems, and some deployment systems, such as Capistrano.

As a side-note, anyone have any ideas of what to do with a bunch of Clickatell SMS credits? I have an account with plenty of credits but it's sitting pretty stagnant at the moment.

Also really looking forward to visiting Christchurch in the coming weeks. Haven't been there in forever.

Comment on this post.

ProtoIRC

So I made a tiny and very hackable IRC bot/client base in PHP for rapid prototyping. Of course I threw it on GitHub. It makes heavy use of PHP >= 5.3 closure support as well as regular expressions for defining just about everything. Basic knowledge of the IRC protocol is recommended. You can find more information in the README file in the previous link.

Here is an example of what a minimal bot looks like:

<?php
require('protoirc.php');

$irc = new ProtoIRC('nick@hostname:6667', function ($irc) {
        // This code will run on connect
        $irc->send('JOIN #channel');
});

$irc->in('/^:(.*)!~.* PRIVMSG (.*) :!echo (.*)/', function ($irc, $nick, $channel, $args) {
        // Arguments are self documenting
        $irc->send($channel, "Echoing '{$args}' for you {$nick}", 'green');
});

// Also available is the ability to catch stdin, irc in, and irc out. Set up timers, and call functions asynchronously (fork/join).

$irc->go();
Comment on this post.

HashTWM Patch

This morning I woke up to find a patch waiting for me on GitHub that extends HashTWM's primitive tag support with what appears to be a more full featured, dwm-like tag support. Thanks to http://github.com/gtellalov for this patch :)

This is the beauty of open source :D

Comment on this post.

LibOrgParser Update

Today I brought my LibOrgParser repository up to date with my local copy, for the first time in a while since I've been rather slack with my local repository.. but hopefully I got everything. The new version brings reading and writing functionality, as well as a new API, and the OrgQL utility, which lets you run simple SQL like queries on an org-mode file, thanks to the SQLite library. Queries that look like this,

SELECT ALL FROM /home/zanea/todo.org WHERE heading CONTAINS todo

Oh and I found this image I made a while ago, kinda neat I think :)

Add OrgQL to that, and that's pretty much my todo list flow :)

Edit: Oh and while we're at it, here's a one liner bash function for opening links in a file:

function nav() { grep -ohE "[[:alpha:]]*://[[:alnum:][:punct:]]*" $@ | while read; do xdg-open "$REPLY"; done; }

# use like this
nav todo.org someotherfile.txt
Comment on this post.

Misc Win32 Utilities

Just created a new git repository on GitHub for my Miscellaneous Win32 utilities. Right now it just has my ExplorerGestures code, but I will be adding some more utilities as I find them on my hard drive.

Edit: Added some more utilities. Probably still more to come..

Comment on this post.

PrepFS

Been a while since I posted anything here, and it's always good to have some fresh content, so I thought I'd post my latest creation PrepFS (Pre-process FS), a small utility FUSE filesystem, that enables preprocessing of files.

My main motivation behind creating this, is enabling modified .Xdefaults dependent on running window manager, or machine it is being viewed from. An Example of usage would be something like this:

~/.xinitrc

wm=`echo -e "openbox\nxmonad" | dmenu`
prepfs ~/.dotfiles/prepfs -b ~/.dotfiles/real -pp "gpp -D$wm -x \"%s\""
exec $wm

~/.dotfiles/real/.Xdefaults

#ifdef openbox
    blah*blah: blah
#else
    this*stuff: here
#endif

Then make sure ~/.Xdefaults is symlinked to ~/.dotfiles/prepfs/.Xdefaults

More information (including source) can be found here http://bbs.archlinux.org/viewtopic.php?pid=576680

Comment on this post.

MPD Class for PHP

I've just been going through a couple of folders and I found a very basic PHP class I wrote to control the Music Player Daemon. Assuming the text protocol hasn't changed much it should still work fine :)

<?php
/*
 * Base MPDControl Class
 * Provide functions for connecting and retrieving raw data from MPD
 */
class MPDControl {
    var $hostname, $port, $timeout, $socket, $errno, $errstr;
    function MPDControl($hostname = 'localhost', $port = '6600', $timeout = 3) {
        $this->hostname = $hostname;
        $this->port = $port;
        $this->timeout = $timeout;
    }

    function connect() {
        $this->socket = @fsockopen($this->hostname, $this->port, $this->errno, $this->errstr, $this->timeout);
        if (!$this->socket) {
            return false;
        } else {
            $this->getData();
            return true;
        }
    }

    function disconnect() {
        $this->sendRaw('close');
        fclose($this->socket);
    }

    function getData() {
        $lines = Array();
        $line = '';
        while ((substr($line, 0, 2) != 'OK') && (substr($line, 0, 3) != 'ACK')) {
            $line = fgets($this->socket, 256);
            $lines[] = $line;
        }
        unset($lines[count($lines)-1]);
        return $lines;
    }

    function sendRaw($string) {
        fwrite($this->socket, $string."\n");
    }
}
Read more...