March 3, 2011
filed mid-morning by dr_who in: hacking
average time to read 1:00 minutes

i’m a big fan of IRC and we use it in our distributed team to stay in touch and also coordinate testing and upgrades. as i’m also a big fan of the ur-IDE emacs i’m using emacs’s rcirc mode for my IRC needs. typically i have a small buffer window at the bottom of my emacs frame dedicated to IRC. quite nice…

…until you start sbt or do some git work in egg as then those modes try to acquire some screen real-estate and without scruples either “recycle” my IRC buffer for their content :-( or split it into two :-(

this being emacs there had to be a way to get that IRC buffer window protected. and there is :-) digging into the emacs info docs and looking at the underlying emacs lisp files this is what i came up with:

 [sourcecode language="text"]
 (defun rcirc-toggle-current-window-dedication ()
   (interactive)
   (let* ((window (selected-window))
          (dedicated (window-dedicated-p window)))
     (set-window-dedicated-p window (not dedicated))
     (setq window-size-fixed (not window-size-fixed))
     (message "Window %sdedicated to %s"
              (if dedicated "no longer " "")
              (buffer-name))))

 (global-set-key (kbd "<Scroll_Lock>") 'rcirc-toggle-current-window-dedication)
 [/sourcecode]

this will toggle the window-dedicated-p and window-size-fixed bits of the window in which you press the scroll-lock key — and, hey, presto! — no more pirating of the IRC buffer window.

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
February 18, 2011
filed mid-afternoon by dr_who in: hacking
average time to read 4:34 minutes

we have been using scala and the lift framework for our project for over a year now. as we are starting on a new subcomponent of it, i thought i’d take a crack at using lift’s new CSS selector transforms.

CSS transforms provide an alternative to the traditional lift templating mechanism:

[sourcecode language="xml"] <lift:FooBar> <foobar:dosomething /> <lift:FooBar> [/sourcecode]

which requires the following scala code:

[sourcecode language="scala"] class FooBar { def render(in: NodeSeq): NodeSeq = bind("foobar", in, "dosomething" -> <span>dog</span>) } [/sourcecode]

and would result in

[sourcecode language="xml"] <span>dog</span> [/sourcecode]

with the new CSS transforms we get rid of the tags and instead use plain HTML:

[sourcecode language="xml"] <div class="lift:Foobar"> <span id="animal">XXX</span> </div> [/sourcecode]

and then change the binding to:

[sourcecode language="scala"] class FooBar { def render = "#animal *" "dog" } [/sourcecode]

and end up, again, with

[sourcecode language="xml"] <span id="animal">dog</span> [/sourcecode]

— just with much less code! and once you start looking into expanding lists, it really becomes obvious that CSS transforms are a huge step forward. add to that that you can now design your web apps using normal HTML design tools (which in my case is emacs, nxhtml mode, and moz-repl) and life has just become a lot easier and more productive…

…except for one thing :-) you see, we are using comets and lift’s rather cool partialUpdate(SetHtml("dog", Text(wuff! wuff!))) construct to dynamically update the “dog” span. for that we were — in the pre-CSS transform age — using calls to chooseTemplate to fetch XML snippets and re-render them. how to do this with CSS transforms?

let’s assume our HTML snippet is a bit more complex and includes an image:

[sourcecode language="xml"] <div class="lift:Foobar"> <div><span id="animal"><img src="XXX" /></span></div> </div> [/sourcecode]

the CSS selector transforms page lists the following construct:

[sourcecode language="scala"] "animal ^^" #> "ignore" [/sourcecode]

this will select the element with the id “animal”. so far, so good. what’s not so good is that the intuitively next idea

[sourcecode language="scala"] "animal ^^" #> "ignore" & "img [src]" #> "dog.png" [/sourcecode]

doesn’t work (CSS transforms are actually functions, so we can invoke them on NodeSeq in sbt’s console):

scala> val in = <div><span id="animal"><img src="XXX" /></span></div>
in: scala.xml.Elem = <div><span id="animal"><img src="XXX"></img></span></div>

scala> ("#animal ^^" #> "ignore")(in)
res0: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="XXX"></img></span>)

scala> ("#animal ^^" #> "ignore" & "img [src]" #> "dog.png")(in) 
res1: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="XXX"></img></span>)

what does work is the following code:

[sourcecode language="scala"] val template = ("#animal ^^" #> "ignore")(in) ("img [src]" #> "dog.png")(template) [/sourcecode]

if we try this in console we get:

scala> val template = ("#animal ^^" #> "ignore")(in)
template: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="XXX"></img></span>)

scala> ("img [src]" #> "dog.png")(template)
res2: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="dog.png"></img></span>)

which is what we expect. just a bit cumbersome to write and the contraction

[sourcecode language="scala"] ("img [src]" #> "dog.png")(("#animal ^^" #> "ignore")(in)) [/sourcecode]

while producing the same result, is a bit hard to understand.

ideally, we could write it as:

[sourcecode language="scala"] "#animal ^^" #> "ignore" ~> "img [src]" #> "dog.png" [/sourcecode]

as in: first select the template, then apply the following transform. well, we are in scala land, where (almost) everything is possible! so, why not create that operator? how hard can it be?

“not very” is the answer. first step is to figure out what it is that we want: CssBindFunc can be viewed as (NodeSeq) => NodeSeq functions. so, we really want to concatenate one (NodeSeq) => NodeSeq with another one. writing this as a function that translates into:

[sourcecode language="scala"] def andThenInto(first: (NodeSeq) => NodeSeq, second: (NodeSeq) => NodeSeq): (NodeSeq) => NodeSeq = (ns: NodeSeq) => second(first(ns)) [/sourcecode]

throwing that into the sbt console yields:

scala> def andThenInto(first: (NodeSeq) => NodeSeq, second: (NodeSeq) => NodeSeq): (NodeSeq) => NodeSeq =
    (ns: NodeSeq) => second(first(ns))
andThenInto: (first: (scala.xml.NodeSeq) => scala.xml.NodeSeq,second: (scala.xml.NodeSeq) => scala.xml.NodeSeq)(scala.xml.NodeSeq) => scala.xml.NodeSeq

scala> andThenInto("#animal ^^" #> "ignore", "img [src]" #> "dog.png")
res4: (scala.xml.NodeSeq) => scala.xml.NodeSeq = <function1>

scala> res4(in)
res4(in)
res5: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="dog.png"></img></span>)

scala> 

which is exactly what we are after — well, almost. andThenInto is a bit long, we wanted to use ~>. so, let’s try that:

def ~>(first: (NodeSeq) => NodeSeq, second: (NodeSeq) => NodeSeq): (NodeSeq) => NodeSeq =
    (ns: NodeSeq) => second(first(ns))
$tilde$greater: (first: (scala.xml.NodeSeq) => scala.xml.NodeSeq,second: (scala.xml.NodeSeq) => scala.xml.NodeSeq)(scala.xml.NodeSeq) => scala.xml.NodeSeq

doesn’t look too bad. let’s give it a spin:

~>("#animal ^^" #> "ignore", "img [src]" #> "dog.png")
res6: (scala.xml.NodeSeq) => scala.xml.NodeSeq = <function1>

scala> res6(in)
res6(in)
res7: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="dog.png"></img></span>)

looking good. next, let’s pimp CssBindFunc with that:

[sourcecode language="scala"] implicit def pimpCssBindFuncWithAndThenInto(first: (NodeSeq) => NodeSeq) = new { def ~>(second: (NodeSeq) => NodeSeq): (NodeSeq) => NodeSeq = (ns: NodeSeq) => second(first(ns)) } [/sourcecode]

and give it a go:

scala> "#animal ^^" #> "ignore" ~> "img [src]" #> "dog.png"
<console>:14: error: type mismatch;
 found   : java.lang.String("img [src]")
 required: (scala.xml.NodeSeq) => scala.xml.NodeSeq
       "#animal ^^" #> "ignore" ~> "img [src]" #> "dog.png"

ooops. what happened? the compiler seems to be doing the grouping in a different way then we expected. “operator precedence” was jumping up and down in my mind in the back row desparate to get called on: looking up that topic in the “scala bible” turned up the explanation: the ~ character is in the highest precedence category together with #. to avoid having to use parenthesis we changed our “andThenInto” operator to &~>:

[sourcecode language="scala"] implicit def pimpCssBindFuncWithAndThenInto(first: (NodeSeq) => NodeSeq) = new { def &~>(second: (NodeSeq) => NodeSeq): (NodeSeq) => NodeSeq = (ns: NodeSeq) => second(first(ns)) } [/sourcecode]

which then yields the desired result:

"#animal ^^" #> "ignore" &~> "img [src]" #> "dog.png"
res10: (scala.xml.NodeSeq) => scala.xml.NodeSeq = <function1>

scala> res10(in)
res10(in)
res11: scala.xml.NodeSeq = NodeSeq(<span id="animal"><img src="dog.png"></img></span>)

scala> 

:-)

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
December 30, 2010
filed around lunchtime by dr_who in: linux
average time to read 1:00 minutes

i recently got my first real desktop system — as in: not a thinkpad. it’s an 8 core, 8GB, 1 terabyte system with an nvidia graphics chipset allowing two large displays to be powered: really sweet. installing ubuntu maverick 10.10 from the alternate install CD1 was simple and straight forward. installing the latest nvidia drivers from the x-updates ppa and running nvidia-xconfig provides the correct configuration for the 1920×1200 display (second display on order :-) and, except for suspend–resume, everything works fine.

the issue with suspend–resume is that the machine goes through the motions of suspending but then just comes back :-( d’oh. googling around for “maverick suspend problem” i stumble over a post in the ubuntu forums citing the maverick release notes

When the XHCI module is loaded for USB 3.0 operation the system cannot suspend. Manually unloading XHCI will allow suspend to complete normally. To avoid future suspend problems, the workaround is to add SUSPEND_MODULES=”xhci-hcd” to /etc/pm/config.d/unload_module then the system can suspend normally.

— hmph. following those instructions, suspend–resume are working. :-)


  1. …to be able to use disk level encryption! the home directory encryption offered by the normal ubuntu install CD suffers from path length issues and also stability issues. disk level encryption has so far worked quite well and we use it on all our machines now. 

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
January 15, 2010
filed mid-afternoon by dr_who in: hacking
average time to read 0:37 minutes

one thing i quite like about scala is that ability to run it in “interpreted” mode via the scala command. that allows me — similiar to python or ipython — to experiment and quickly try things out or even test my classes and objects.

what was a bit of a pain was getting the proper classpath constructed so that not only target/classes was picked up but also all the required dependencies. poking a bit around in maven’s plugin documentation i came across the dependency plugin and in particular the dependency:build-classpath mojo, armed with that information i came up with the following rather useful shell script:

save under a convenient name, stir, and enjoy: call this script instead of calling scala directly.

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
January 13, 2010
filed mid-afternoon by dr_who in: hacking
average time to read 0:25 minutes

note to self: maven differentiates between installing and deploying a package (which might have been built via a mvn package):

  • install — just installs the JAR file and the POM file, if the -DcreateChecksum=true flag is provided it will create the SHA1 for the JAR only
  • deploy — install JAR and POM and all necessary meta data along with SHA1s

to install a package to a shared repository a deploy is to be preferred over an install as with an install we’ll get missing checksum errors later in life.

so, this works like this (using the lift-ldap package as an example):

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
filed around lunchtime by dr_who in: from the grid
average time to read 0:45 minutes

for over a year we’ve been meeting more or less once a month or two over lunch to discuss and chat about all things OpenSim — very creatively volker gässler and i called them OpenSim Zurich Lunches back then when. for the past year we’ve been having lunch at the cafeteria of the IBM Research — Zurich lab, this month’s OpenSim Zurich Lunch will be the first time we meet closer to the downtown zurich area:

so, if you are around, have time to spare, and are interested to meet up with fellow OpenSim-ers, let volker know by dropping him an email — fe11 at gmx.ch — so that we can reserve enough seats at king’s kurry.

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
January 12, 2010
filed around lunchtime by dr_who in: hacking
average time to read 0:53 minutes

in one of our projects we are using maven to build our web application. part of our build process involves maven resource filtering, in particular, we need to insert path names into resources controlling the build process. since our team uses both linux and windows, we need to be able to generate file: URLs that work irrespective of the underlying platform.

using a construct like

file://${project.build.directory}/path/to/stuff

didn’t really work: on linux the resulting file: URL was usable, on windows it was not: there was a / missing plus all occurences had been escaped.

after trying a couple of variations, i came across the available variables section of the maven documentation which listed project.baseUri — which seemed just the ticket!

alas, it turns out that maven’s resource plugin currently does not know about ${project.baseUri} — doh. yet, not all hope is lost: by adding the following property definition to the project’s pom.xml file did the trick:

instead of ${project.baseUri} we use ${projectBaseUri} in the resource file, which gets translated to the desired file: URL. bingo.

zv7qrnb
all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
January 5, 2010
filed mid-morning by dr_who in: from the grid,linux
average time to read 0:45 minutes

the latest rezzme now contains the necessary code to build debian/ubuntu dpkgs — making it as easy to install rezzme packages on the latest debian/ubuntu systems as it already is for windows and mac OSX machines as the dpkg format allows me to explicitly specify the prerequisites (such as PyQt4).

while working on the dpkg support i also found out that debian/ubuntu has the very useful /etc/firefox-3.0, /etc/firefox-3.5, and /etc/thunderbird directories that allow me to provide package specific javascript to, for example, add a protocol handler for the rezzme: URI scheme. that along with gnome’s gconf tool gives us the same seamless rezzme user experience as on windows or mac OSX — unfortunately, it seems that nothing comparable exists for redhat/fedora based systems.1

also the windows build code has been cleaned up and the no longer required dependency on setuptools removed.


  1. at least i couldn’t find anything comparable; if you know how to do this — independent of minor version upgrades of firefox and thunderbird — i’d appreciate it very much to learn about that. 

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
December 9, 2009
filed in the early evening by dr_who in: hacking,linux
average time to read 0:57 minutes

i just switched over from thunderbird 2 to the new sparkly thunderbird 3 — and i like it very much. particularly the tabbed user interface is quite nice but also lightning 1.0 seems to cope much better with those lotus notes generated calender invites :-)

what did bother me was that i couldn’t find an easy to use function for keyconfig to bind the page left and page right keys (aka F19 and F20) of my X200 keyboard to “previous tab” and “next tab”. after some digging i stumbled across the mozilla thunderbird 3 tabmail page which then allowed me to figure out how to create the code for keyconfig:

[sourcecode language="javascript"] // next tab var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']. getService(Components.interfaces.nsIWindowMediator); var winId = windowManager.getMostRecentWindow("mail:3pane"); var tabmail = winId.document.getElementById(‘tabmail’) tabmail.switchToTab((tabmail.tabContainer.selectedIndex + 1) % tabmail.tabInfo.length) [/sourcecode] and [sourcecode language="javascript"] // previous tab var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']. getService(Components.interfaces.nsIWindowMediator); var winId = windowManager.getMostRecentWindow("mail:3pane"); var tabmail = winId.document.getElementById(‘tabmail’) tabmail.switchToTab((tabmail.tabContainer.selectedIndex + tabmail.tabInfo.length – 1) % tabmail.tabInfo.length) [/sourcecode]

copy & paste the code snippets and use keyconfig’s “add key” feature to bind the code to whatever key you’d like to use.

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
November 23, 2009
filed mid-afternoon by dr_who in: hacking,linux
average time to read 1:41 minutes

i recently switched all my systems from running kubuntu hardy heron 08.04.02 to xubuntu karmic koala 09.101 — a rather pleasant switch over. the only thing that was bothering me was the really crappy fonts in firefox and emacs. in firefox, no matter what i configured in firefox itself or in the appearance settings dialog of xubuntu (tried both gnome-control-center and XFCE’s appearance dialog) the fonts would still be blurry and below a certain size unreadable almost. in emacs i was suffering from the blurriness plus humongous menu fonts (i am getting older, i know, but so far i don’t need that large a print, really).

after a lot of research i finally managed to track it down to the following:

  1. firefox doesn’t seem to be really interested in what the user’s desktop settings say, the only guy it will listen to is fontconfig configured via /etc/fonts/conf.d!
  2. to get rid of the blurry fonts i needed to drop the 10-hinting-{full,medium,slight}.conf from fontconfig’s /etc/fonts.conf.d directory

that fixed the blurry fonts in firefox and emacs.

to get emacs menu’s back to a more sensible size i had to edit $HOME/.emacs.d/gtkrc — changing the default face via M-x customize-face only affected the buffer and modeline fonts but not the menu itself. i’m using the DejaVu Sans fonts, so my gktrc file looks like this:

style "user-font"
{
    font_name="DejaVu Sans 8"
}
widget_class "*" style "user-font"
gtk-font-name="DejaVu Sans 8"

style "default"
{
    font_name="DejaVu Sans 8"
    bg[NORMAL] = { 1.0, 1.0, 1.0 }
}

that one fixed emacs.


  1. yes, i did try kubuntu 09.10 in the hopes that the KDE 4 gang had gotten their act together and had produced by now something as usuable (as opposed to blinky, flashy, sparkly) as KDE 3.5 — alas, that hope was in vain: a lot of the features that i’d valued in KDE 3.5 were still missing, usability was still not on par with KDE 3.5′s usability — but, hey, it’s blinky, flashy, sparkly, surely that counts for something? no, not really. i’m less interested in being an onlooker in the continuing GUI-blinky, flashy, sparkly pissing contest with windows/mac osx, and rather interested in a desktop that i can adapt to my needs without having to go on an archaeological expedition into the innards of KDE 4. sorry about that.

    and, also, yes, i know about the KDE 3.5 repo for karmic — tried that, in fact, it mostly works, but with producing “cannot contact session manager” (no matter which session manager i tried) that was no longer usable either. really sorry. 

all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.
« previous pagenext page »