Skip to main content

Posts

Showing posts from November, 2012

Kjært barn har mange navn - or, the story of how I discovered Ruby's each_cons

Reading the Pragmatic Programmer's PragPub from March (I must admit I don't have/take the time to read them regularly enough) I stumbled upon Scala's sliding function on Arrays. This creates a sliding window of consecutive sub arrays of an array. So an  Array(1,2,3,4).sliding(2) would produce an iterator of arrays (1,2), (2,3), and (3,4). Useful! While googling around to see if Ruby has something similar I stumbled across the windowed function in F# that pretty much works the same way, before finding Ruby's each_cons . The first thing I did to test this was to revisit an old (fairly obvious, brute force) seven line Ruby solution (from back in the day when I had just discovered the language) to an Euler problem , and replaced it with the following (admittedly still brute force) one liner (where 'number' is a 1000 character long string containing only numbers): Unlike Scala where you would have the function sliding on string objects, we need to call chars ...

Parenthesis (and dots) (in Scala (as compared to Ruby))

I must say that I quite like what I encounter of the Scala language in Martin Odersky's online " Functional Programming in Scala " course at EPFL (as well as the course itself!). It is almost as expressive as my favourite language these days, Ruby . (Of course it will never really be able to match it on expressiveness, I'd say (the latter being duck typed, and the former being strictly typed (even with a most excellent type inference)).) One detail that I like about both languages is that parenthesis are (most of the times) optional. (By "(most of the time)" I mean that you (obviously) can't really skip them if it leads to problems with operator precedence.) This (can) really lead(s) to more readable code. Scala, however, (seemingly) has some inconsistencies when it comes to when  they are needed. Most notably the println  (and similar?) function(s). ((Quite possibly inspired by scripting languages) you have a quick way to display text at the user w...

Fix upside down Skype video in Ubuntu 12.10 [UPDATED]

When launching Skype in 64-bit Ubuntu 12.10 on my Asus U35J the webcam image was all topsy-turvy. Since I don't live in Australia, or something (tsk-tsk), this was not really cutting it for me.  Some quick googling led me to this forum post:  http://forums.pcpitstop.com/index.php?/topic/198236-why-is-my-skype-video-showing-upside-down/   After making sure that the necessary packages was installed (notably  libv4l-0) I adapted the command from the forum post to: LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l1compat.so skype and voila, the image was OK. Next step is for this to be set to default, which seems to be outlined here (in steps 2 and 3):  http://pc-freak.net/blog/how-to-fix-upside-down-inverted-web-camera-laptop-asus-k51ac-issue-on-ubuntu-linux-and-debian-gnu-linux/  (Actually this post seems to cover most of what is useful from the forum post above...) UPDATE (19/04/2013): Since my laptop was working fine, I decided it was abou...