February 24, 2014
filed in the late afternoon by dr_who in: from the grid,hacking
average time to read 0:50 minutes

On Friday Apple released an iOS bug fix for an issue with their SSL implementation. Adam Langley analyzed the patch and found out that the same problem is also present in the Mac OSX implementation. For so far unknown reasons (though the rumors range from merge error to NSA induced bug) a goto fail; line got duplicated (highlighted below):

(code excerpt taken from Apple’s open-sourced code)

The effect is that the sslRawVerify code never gets called — allowing an easy MITM attack on iPhone, iPads, Macs. Unfortunately, Apple did something rather stupid and only released the iOS patch and not concurrently the Mac OSX patch. As a consequence all Maverick Macs are currently potential victims…

Anyhow, had Apple enforced cautious coding guidelines and mandated that if-then-else blocks always have to use squiggly braces, the code in question would not have been an issue:

By encapsulating the then-block, the second goto fail would have been dead code and nothing would have happened (the compiler might even have flagged this).

So: always use squiggly braces for your if-then-else statements!

m4s0n501
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 16, 2014
filed in the early evening by dr_who in: hacking,python
average time to read 0:52 minutes

today we were trying to do a multipart/form-data POST to one of our webservices using the usually rather usable python requests. the spec of the webservice required that multiple files were to be POSTed as multiparts with the name files and individual filename attributes — a task that python request according to its doc did not really seem to support:

since the files parameter is a dict, it’s not really possible to add the files keyword twice. several searches and attempts (tried listing tuples as value of the key, didn’t really work) later we resorted to tracing into the requests.post() call to see what was going on down in the engine room of requests. lo and behold, we did come across the following inspiring piece of code in requests’s _encode_files method:

the inspiring bit is the for (k, v) in files: part — this is iterating over a dict (as illustrated by the doc), but that should also work with a list of tuples of (name, file object)!

sure enough: this piece of code:

yields the desired result:

Voila!

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 15, 2012
filed terribly early in the morning by dr_who in: hacking,linux,void
average time to read 0:26 minutes

while tweaking the spam filters on our mail server i finally took the step of adding a cron job to learn from the inbox and junk folders of each user. as we are using spamassassin as part of our spam defense this basically involves a couple of invocations of sa-learn to

  • learn the “ham” from each users inbox folder
  • learn the “spam” from each users junk folder

below is the shell script that gets invoked by cron once a day:

the while read line; do ... done bits are there so that i can nicely indent the output of sa-learn.

works rather nicely.

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.
July 1, 2012
filed in the early afternoon by dr_who in: hacking
average time to read 2:14 minutes

the other day i tried to come up with a minimalistic Ajax setup — minimalistic in the sense of minimal coding overhead. my ingredients of choice were jquery and JavaScript on the client side and python on the server side. the goal was to use both GET and POST REST calls for obtaining the dynamic data and utilize JSON as the data format.

the python server code makes use of python’s BaseHTTPServer.HTTPServer and BaseHTTPServer.BaseHTTPRequestHandler classes:

(more…)

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 19, 2012
filed mid-morning by dr_who in: hacking
average time to read 0:31 minutes

the other day i was coding a scala apply(array: Array[String}) method to instantiate an object from a CSV file. i ended up with something like this:

there were about a 100 parameters to use. i wasn’t really too excited about having to change the rewired(0) to use the proper index by hand. so, here’s what i did:

  • in emacs mark the region
  • then invoke shell-command-on-region and
  • use perl -pi -e 's{rewired(0)}{sprintf("rewired(%d)", $. - 1)}e;' as command to invoke

emacs will then show you the result of the command in a temporary buffer, you can either copy and paste from there, or just repeat the shell-command-on-region and prefix it with ctrl-u — emacs with then replace the region with the output of the command directly.

voila!

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.
July 22, 2011
filed in the early afternoon by dr_who in: hacking
average time to read 0:43 minutes

it turns out that the sbt/web-plugin configuration i described in my last post is not quite cutting it. what we observed is that while changes to the contents of the webapp subtree were indeed effective immediately1 sbt commands like prepare-webapp and jetty-reload would sometimes work and sometimes just ignore us.

so, back to digging around in the web-plugin sources and this is what we are now using:

this sbt configuration tells jetty to run out of the src/main/webapp directory — any changes you do in there will become effective immediately and prepare-webapp and jetty-reload are working as expected. the drawback is that your generated classes and lib files get copied to src/main/webapp/WEB-INF :-( i know, sucks, but still better than having to restart your webapp everytime you change a {html,css,js} file. if you are using git you might want to add

to your top-level .gitignore file.


  1. on browser reload, that is. 

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.
July 4, 2011
filed in the early afternoon by dr_who in: hacking
average time to read 1:12 minutes

the solution described below turns out to have its flaws and is not really recommended — have a look at the recently posted update for a better solution!

simple build tool 0.7.5 comprised the jetty and webapp functionality — version 0.10.0 (sbt10) no longer does so, instead you have to pull in the sbt webplugin. one feature of sbt7.5′s webapp support that we used heavily was the ability to run jetty out of the source tree instead of the exploded temporary WAR file:

> Another possibility is to directly run the web application out of the the source web application path: > > override def jettyWebappPath = webappPath > override def scanDirectories = mainCompilePath :: testCompilePath :: Nil > > — sbt7.5, continuous redeployment

(we actually used to set scanDirectories to Nil)

achieving the same setup with sbt10 is not as simple or even obvious, the solution reported in the simple build tool newgroups does not really provide the same feature, as it still requires to have a ~ prepare-webapp running in sbt. here’s what seems to work:

<pre language=”scala”> // run jetty from source tree jettyConfiguration <<= (sourceDirectory in Runtime, jettyConfiguration) map { (sourceDir, jettyConf) => { val conf = jettyConf.asInstanceOf[DefaultJettyConfiguration] new DefaultJettyConfiguration { def classpath = conf.classpath def jettyClasspath = conf.jettyClasspath def war = sourceDir / “webapp” def contextPath = conf.contextPath def classpathName = conf.classpathName def parentLoader = conf.parentLoader def scanDirectories = conf.scanDirectories def scanInterval = conf.scanInterval def port = conf.port def log = conf.log def jettyEnv = conf.jettyEnv def webDefaultXml = conf.webDefaultXml } } }
  // set jetty scan dirs to empty list jettyScanDirs := Nil </pre>

changes in src/main/webapp are immediately effective for the running jetty instance. voila!

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 28, 2011
filed in the early morning by dr_who in: hacking
average time to read 1:14 minutes

i’m an ardent emacs user. for our current project we chose the scala language as our programming language along with lift as the web application framework. initially we used maven but have switched over to the simple build tool — sbt in short — about half a year ago, as we found that to be faster than maven and also offering more features (such as test-only, test-quick, etc). to get scala support in emacs i’ve been using ensime which cooperated really well with sbt.

the sbt project recently made version 0.10.0 available — aka sbt10. switching from sbt7.5 to sbt10 is either very easy or a bit of a struggle. it’s easy if you are using a plain vanilla setup. it’s a struggle if you’ve created your own tasks — to paraphrase star trek: “it’s tasks, but not as we know it, jim”.

among the changes brought by sbt10 is that manged JARs are no longer copied into the lib_managed tree (instead the version in $HOME/.ivy2/cache is used, avoiding redundant copies) — that unfortunately confuses the heck out of ensime. florian hars, suffering from the same problem, wrote an sbt10 ensime plugin that fixes the issue for the time being (until ensime has proper sbt10 support).

to install the sbt ensime plugin, follow the instructions in its README, then in restart sbt and invoke the ensime task. after a compile of your project, it will generate a new .ensime project file (save an eventually existing old one if you care about it). then it’s just a restart of emacs and the invocation of ensime.

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.
April 13, 2011
filed terribly early in the morning by dr_who in: hacking
average time to read 0:53 minutes

thunderbird is a terrific mail application (“mail user agent” is the posh name, i believe).

pretty much the only thing i don’t like about it though is its way of formatting the date and time and not providing a way of letting me configure the date format via preferences. it got bad enough that i recently spent a bit of time to figure out how get thunderbird to display date and time in yyyy-MM-dd HH:MM format — that is, 2011-04-13 20:34 instead of 04/13/2011 08:34pm or something similarly silly.

the solution was hiding in a forum post on the ubuntu forum: by switching the locale (well, at least parts of it) to en_DK.utf8 thunderbird would use the yyyy-MM-dd HH:MM format (aka ISO date–time format).

here’s how i did that on ubuntu:

[sourcecode language="bash"] # first: create a diversion of the normal /usr/bin/thunderbird dpkg-divert –divert /usr/bin/thunderbird.ubuntu –rename –local –add /usr/bin/thunderbird # next: create our locale setting wrapper cat <<HERE >/usr/bin/thunderbird #!/bin/bash export LC_TIME=en_DK.utf8 export LC_PAPER=en_DK.utf8 export LC_MEASUREMENT=en_DK.utf8 exec /usr/bin/thunderbird.ubuntu "$@" HERE chmod a+x /usr/bin/thunderbird [/sourcecode]

that should do the trick.

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.
March 9, 2011
filed around lunchtime by dr_who in: hacking,linux
average time to read 2:37 minutes

i’ve long been using an external 22″ monitor with my ubuntu linux powered X200 thinkpad. while ubuntu maverick (10.10) has some issues with attaching and detaching the second monitor and subsequent suspend–resume cycles (the second suspend after a detach would not resume, d’oh), ubuntu lucid (10.04.02) works just fine (as befitting a long-term-support release).

for quite a while i’ve had the old 20″ monitor which i had been using previously sitting on my desktop along with an USB DisplayLink adapter — the idea being to hook the old monitor up as well as a third monitor1. the displaylink driver provided by ubuntu lucid seemed to work properly — the monitor’s screen would turn green on connecting it and a framebuffer device (/dev/fb1) and so i tried various recipes floating around on ubuntu forums and elsewhere — all promising to achieve a grand unified desktop comprising all three monitors — and they either didn’t work or if they achieved the grand unified desktop it was unusable.

so, after another prolonged period during which the monitor and the displaylink adapter gathered even more dust, i tried a different approach: give up on the grand unified desktop goal and instead just try to make use of the monitor. the idea this time was to start up a VNC server, then use a VNC client to directly render the server into the framebuffer device (/dev/fb1) provided by linux’s displaylink driver. the vncserver bit is actually quite easy:

[sourcecode language="bash"] vncserver -name hidden -geometry 1600×1200 -depth 16 :42 [/sourcecode]

which starts a VNC server for the :42 display.

the VNC client bit turned out to be a bit more difficult. ubuntu lucid does have directvnc client which is “a vnc client for the linux framebuffer device”2. that client does seem to require keyboard and mouse access and in some configurations did not work at all or locked up my keyboard (not the mouse, though, funnily enough) or crashed the running X session, so no points on that one. further research luckily turned up vnc2dl by none other than quentin stafford-fraser one of the original VNC developers (and also the inventor of the webcam it seems). vnc2dl seemed a bit more promising and — after slightly modifying3 dldevice.c — did do the job:

[sourcecode language="bash"] sudo vnc2dl :42 [/sourcecode]

next up was fusing display :42 to my main display :0 on a keyboard and mouse level so that i could just move the mouse pointer over to the left and end up on display :42 — here x2x (in the equally named ubuntu package) came into play:

[sourcecode language="bash"] x2x -west -to :42 >/dev/null 2>&1 & [/sourcecode]

and, hey, presto!, both displays are linked mouse and keyboard wise.

only thing still bothering me was that cut and paste was not working. to fix that required adding

[sourcecode language="bash"] vncconfig -nowin & [/sourcecode]

to my .vnc/xstartup file.

to have firefox run on display :42 required creation of a new firefox profile — i added that to .vnc/xstartup as well.4


  1. yep, even more screen real estate; can’t have enough of that: the ur-IDE emacs in one screen, instant messaging app pidgin on the other (for communicating with the team), the third screen would be really useful to host a firefox window with the API docs and so forth. 

  2. see man directvnc for more information about that one. 

  3. vnc2dl in the version on quentin’s github is hard-wired to 1280×1040/24bpp which my old monitor doesn’t quite grok, changing the wiring to 1600×1200/16bpp made it more grokkable for my setup. 

  4. to get the new profile synchronized with the default profile i used firefox’s recently added Firefox Sync add-on. 

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.
next page »