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.
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.
January 12, 2010
filed around lunchtime by dr_who in: hacking
average time to read 0:54 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.

p5rn7vb
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.
September 1, 2009
filed mid-afternoon by dr_who in: from the grid,hacking,linux
average time to read 1:50 minutes

a colleague of mine in japan contacted us asking whether our in-world collaboration tools could be extended to support japanese characters — he had tried our internal, public sametime 3d servers and had noticed that while in-world chat and instant messaging worked just fine, our flipcharts, brain storming boards, calendar, and voting tools did just display rather boring little rectangles :-(

not good. even worse when it means lost leads. so i set out to investigate. since OpenSim is being used in japan, it was a fair assumption that we might have a font problem here. this was confirmed by a twitter from adamfrisby:

@DrScofield so it should load fine.Only issue you need to be aware of is fonts – you need to use a font with the correct charset availible.

so, first port of call: how are we specifying the font to use for text rendering? digging through the OpenSim source i ended up in the VectorRenderModule:

gulp: we’ve got it hard coded :-(

so, next question: can we change it dynamically? looking through the code, it seems like we might:

except, hmph, there is no osSetFontName() OSSL function :-(

a couple of SMOPs later, we had osSetFontName() and could also configure the default font name in OpenSim.ini, good. now to figure out which linux font would do the trick.

i tried:1

  • Arial — no good: doesn’t have japanese script support
  • DejaVu Sans/Serif — again, no good, no japanese script support
  • Kochi Mincho — works!

— the configuration for that one is:

[VectorRender]
    font_name = "Kochi Mincho"

my next quest was to see whether i could find a font that would support the whole range: european scripts as well as japanese and also chinese.

…unfortunately, while windows users have Arial Unicode MS there is no such complete beast available to linux users — yes, there are fonts such as bitstream cybit, but their license conditions either don’t allow commercial use or only for a single user. so, if you are running under linux you need to localize your OpenSim installation via OpenSim.ini.

but! at least we figured out how to get japanese character sets supported in OpenSim on linux and can now configure one of our sametime 3d servers to support japanese OpenSim users properly! :-)


  1. lest you get the wrong impression: i know no japanese, instead i’m using google translate to produce suchs gems as “OpenSimは岩!”2 

  2. and hoping that the good folks at google don’t do a “Έχω τρεις όρχεις” on me… 

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.
August 25, 2009
filed in the late evening by dr_who in: hacking
average time to read 1:41 minutes

for almost 10 days i’ve been the proud owner of a new mobile phone, the htc hero, an android and, thus, linux based mobile phone! over the past year or so i had become increasingly fed up with my apple ipod touch — yes, i had jail-broken it, yes, i had amarok synchronizing via ssh with it, but at what “speed!” ridiculous!1

when my trusted nokia n95 started acting up and started crying for power more and more often the writing on the wall was quite legible: “get a new phone” — so i did :-D

after a bit of research — the palm pre looked sexy but is not available on the continent for some time to come and also lacks the standard API set of the android platform — i settled on the android based htc hero.

copying music over, sync-ing those podcasts i love to listen to — it’s all just a matter of plugging in the USB data cable to the htc hero and my thinkpad, telling the hero to offer the SD card as a USB drive to linux and we are in business: gone are the hour long transfer times for those ARD radio tatort radioplays or the swiss SF TV dok vidcasts — it all happens in a flash now, sweet :-)

the only thing i was missing: vidcasts :-( turns out the hero can play those, but you need to – install the video player application via the android market, and – “hack” amarok’s config file so that amarok would be cool with sending .m4v vidcasts to the hero

for the latter you need to locate the line that reads

supportedFiletypes=mp3

in your .kde/share/config/amarokrc file and change it to read:

supportedFiletypes=mp3, m4v

voila! amarok will now transfer those vidcasts to the hero and the video player application will play them :-)


  1. don’t get me wrong: i like the user interface of the ipods and iphones. what i don’t get, though, is the early-1990s mindset of apple: a locked platform??? why on earth would you try to exclude customers from your platform? oh, never mind… 

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.
June 18, 2009
filed in the early evening by dr_who in: from the grid,hacking
average time to read 0:16 minutes

for stress testing i needed to create 100 avatar accounts quickly. instead of going via opensim’s console i started ipython and entered the following python script:



		


a couple of minutes later i had successfully created 100 avatar accounts, ”Bot0 Dude” to ”Bot99′, all wearing the same outfit as ”Bot Dude”, an avatar i had prepared earlier.

voila! avatar machine :-)

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 »