Posts for Sunday, August 16, 2009

Adding Common Lisp to Apache Thrift

Well, with cl-pack sitting in a (hopefully) finished state, I'm turning my attention back to what got me started on it in the first place: attempting to write Lisp support for Apache Thrift. Thrift is the RPC framework Facebook uses internally and they open sourced it a bit ago, and it made its way into the Apache incubator where it resides now getting all kinds of attention. Several languages have been added to it, and its been generally cleaned up. After watching a video on Facebook architecture I got interested in Thrift. When I found out there was no Lisp support I figured I'd take a stab at it. Apparently others have tried but disappeared, so as to weather I'll finish, we can only wait and see but it seems like a good challenge and something I'd very much like to see done.

The digression onto cl-pack was a wonderful little trip. I learned a bit more about Lisp and lots more about packaging software for Common Lisp. It was a good little project to cut my teeth on and hopefully better prepare me to see this through.

So wish me luck, I'll probably need it for this larger undertaking. Approach #1 is reading the Ruby code and then writing similar CLOS Lisp code. It seems like a decent approach off the top of my head.

Moved to Linode

My web host for a good long while was Futurehosting. My OS was Debian 4.0 (Etch). Strike one: as of now there's still no option to upgrade to a newer version of Debian. Debian lags so much to begin with, it's really painful ify ou want to use anything released in the past two years.

I had an unmanaged VPS. I ran a bunch of funky non-standard stuff on there and it ran mostly OK. I had to upgrade to get more RAM just so SBCL would run on it, which sucked but I don't know that another host would've been any better.

The good thing about Futurehosting was that they responded very fast to tickets. The bad thing was the fact that I had ample opportunity to know this. The server would go down randomly once every month or two. I'd open a ticket saying "Hi my server is down", then things would be working again in a half hour, but why did this happen so often? I don't know. An awful lot of "failed switches". I wonder how often this happened without my knowing about it, given how often it happened in the middle of my using the server for something.

With all the hardware they were burning through I would've expected upgrades or price reductions over time, given that I was a steady customer for so long and that disk space and memory keeps becoming cheaper and cheaper in the world. But the prices always stayed the same, which was another strike.

Being hosted there was annoying but never annoying enough to switch. And migrating all of my sites and data to another server seemed like a huge pain. Momentum: the worst enemy of progress.

I moved to a new host on a whim recently: Linode. It was far less painful than I expected. Thanks to Linux and plaintext config files, it was mostly a SCP-it-all-over and tweak process. It took me one evening and a bit of time the next morning. Linode offers a lot of OSes which is also nice.

I pay less for Linode than I did at FH (and I get fewer resources at Linode, but I don't need much). Thus far I'm astonished how much faster things are running on the server. Even goofing off at a terminal, the shell is more responsive. My email loads instantly in kmail instead of lagging for a second. I never knew what I was missing. Linode's DNS control panel is also pretty braindead simple to use.

Futurehosting gets a C+ from me. It worked and my website existed, but it didn't knock my socks off. Hopefully Linode is better.

Install Lisp ASDF packages as a user with CLC

CLC or Common Lisp Controller is a system that other Lisp systems user to keep track of ASDF systems (a mouthful I know). By default, system packages are installed to /usr/share/common-lisp/ but what happens if you don't have root access but still want to leverage the ease of use CLC installed ASDF packages provide?

clc-register-user-package to the rescue! Create ~/.clc/source and put your ASDF package there, then simply run

$ clc-register-user-package ~/.clc/source/package/package.asd

and volia, you can (require :package) from any of your Lisp systems there after.

It's pretty awesome. :)

Posts for Saturday, August 15, 2009

Comcast blocks port 25

Testing a remote SMTP server is kind of hard when Comcast is secretly blocking all inbound and outbound traffic on port 25. I only figured it out when telnet wouldn't even work. I could've saved myself an hour of frustration if I'd known this. Thanks, Comcrap.

Windows Powershell: Can you handle the power?

MS Powershell is Microsoft's ripoff of Bash. I don't think this is a bad thing necessarily. Bash is a good tool and it's open source. If Windows bundled a sensible, full-fledged Bash and got rid of CMD.EXE I would dance for joy.

So Powershell lets you refer to your home directory as ~ and a bunch of commands have *nix aliases like ls and cat. This is nice for those who have *nix commands firmly internalized. You have to use .\foo.bat to run things in the current directory instead of just foo.bat, which I thought was cool.

But Powershell is not without its problems. For one thing I see this a lot:

The redirection operator '<' is not supported yet.

How hard is it to implement input redirection, really? For another thing, tab completion continues to be broken. When you hit Tab it still doesn't put a slash at the end of the text it inserts. You have to type a manual \ every time you hit Tab, to continue tabbing your way through directories. Thus doubling the number of keystrokes you're forced to type. This continues to drive me crazy. There's a small amount of evidence that someday it'll be fixed, but I'm not holding my breath.

You also usually can't bundle flags together. e.g. rm -rf would have to be rm -r -f in Powershell. This is just annoying enough to bother me, but I can look past it.

Sadly, Powershell also runs slower than a geriatric sea turtle. I don't understand what it's doing that takes 10-20 seconds to startup. Or why tab completion often lags for 5+ seconds itself.

My happiest surprise was when I tried to uninstall Powershell (so I could try version 2) and got this:

/random/powershell.png

This dialog listed every program installed on my computer (in random order) including every Windows Update I'd ever installed. The worst part is that I couldn't even dismiss this dialog as an error. For all I know, uninstalling Powershell could cause every program on my computer to stop working. I've seen stranger things happen in Windows.

A person walking past my office when I saw this would have heard the crazed, maniacal, tortured laughter that only the experience of being forced to use Windows can elicit.

Lightweight compositing in X

It might seem as if one needs a whole desktop environment in order to enjoy the luxury of compositing and its so called real transparency, but in fact this is not the case.

All one needs is to have X compiled with composite support (USE="xcomposite" in Gentoo) and two small X applications (both are in the official Portage tree):

  • xcompmgr — a lightweight compositing manager
  • transset-df — an application with which one can select the desired transparency levels (this is a patched/improved version of the original X.org's transset)

Although xcompmgr does not have all the nifty effects as KDE or GNOME or Compiz do, it does pack real transparent windows (as well as panels etc.), basic shadows and a few more tricks.

The man pages of these two are short and quite self-explenatory, so I find it obsolete to describe the usage here.
<!--break-->

cl-pack 0.2

cl-pack 0.2 is out and can be gotten at the regular place. I've packed a lot of new features into it. More data types supported, and a lot of new syntax and formating rules including grouping and '/' templates. Additionally some bugs were fixed including signed number support.

cl-pack covers most of Perl's pack's features ignoring as far as I'm concerned only weird esoteric stuff. Granted thats up to interpretation but I am very happy with what cl-pack supports and so I am pushing out 0.2 and calling it "feature complete" unless I hear from anyone soon needing anything or with bugs. If not I'll rerelease it in a bit as 1.0. It's a pretty solid piece of work IMHO.

Posts for Friday, August 14, 2009

Submit your Exherbo repositories

In Exherbo we employ a distributed development model where users can easily create their own repositories containing packages not otherwise available. Most users want to share their repository so other people can benefit from their work and quite often contribute updates and fixes in return.

But how do you find all these repositories? To solve that problem we've created the unavailable and unavailable-unofficial repositories. These two repositories index all the repositories Exherbo knows about (and is deemed of sufficient quality of course) and this makes it possible for paludis to know which repositories packages like powerpc-utils or bzflag are in.

All this is for nothing if you don't submit your repository for inclusion in unavailable* however so I'd like to remind people to submit their repositories. All you need to do is ask for it to be added in the #exherbo channel on freenode.

And you have a lot to gain by submitting your repository - here's just a short list of what you get in return:
- A reasonable thorough review of you repository with comments on things that needs improvement and explanations as needed
- The review usually teaches a lot of things about Exherbo and the exheres package format
- You get higher quality packages
- Other users can contribute to your packages in the future - you should expect updates, bugfixes and improved packaging from your fellow users
- Inclusion on Summer

So keep on creating new repositories and packages but make sure you submit them to unavailable-unofficial - there's lots of people that wants to help with your packages.

Backup around firewalls with ssh and rsync to encrypted destinations

I decided I really needed to work on a server backup system, so here are my notes on the system I have now.

First things first, the files I want to backup are owned by all different users, so the only user who can run the backup process is root. Therefore I can't just run rsync from my local machine and grab the files from the server, the backup process has to be run on the server and backup to the backup machine. Now in my case this was a bit of a trick because the backup machine was behind a firewall, so the server had no direct line of communication to it. So I wrote a script to turn on a reverse ssh port forward.

recv-serv-backup.sh

 
#!/bin/sh
 
ssh -R 8000:127.0.0.1:22 -N user@kvasir.mindstab.net
 

When run on the backup machine behind a firewall, it connects to the server (kvasir) and listens on port 8000. When ssh on kvasir connects to port 8000 it redirects that traffic to local port 22, the ssh port of the backup machine. This is how the firewall is gotten around. Reverse port mapping is a cool trick to master.

Next as root on kvasir I generated a public ssh key and put it on the backup machine so root could automatically log on repeatedly to the back up machine (think lots of rsync calls) once the key was loaded once. Then I hooked up the key to keychain. That is all better outlined at:
Gentoo Linux Documentation: OpenSSH key management, Part 1 and
Gentoo Linux Documentation: OpenSSH key management, Part 2.

The all I needed to do was poke the rsync syntax to use the nonstandard ssh port for backup. The best method I found was

rsync -e "ssh -p 8000" -av

rsync for those of you who don't know is a great little backup tools. It's like a smart (in that it only copies files that have been modified since the last backup) network aware (since it can use ssh) copy tool. Simple but really useful.

So with that I wrote a backup script on the server

server-backup.sh

 
#!/bin/sh
 
backup () {
        echo "$1..."
        DST=`echo "$1" | awk '{split($0,a,"/");  result = "/"; for (i=2 ; i < length(a)  ; i++)   result = result "/" a[i];  print result;  };'`
        rsync -e "ssh -p 8000" -acv $1 dan@127.0.0.1:~/kvasir$DST ;
 
}
 
backup "/svn"
backup "/git"
...
 

There is one caveat, rsync won't create subdirectories on the other side specified in the path so you need to create the basic directory structure.

 rsync -e "ssh -p 8000" -av /git user@127.0.0.1:~/kvasir/git

is fine because it will create /git just fine, but

 rsync -e "ssh -p 8000" -av /home/user user@127.0.0.1:~/kvasir/home/user

will fail if ~/kvasir/home doesn't exist. So you'll need to create the basic directory structure or enhance the backup function to strip out extra directories in the target path.

Finally, I didn't want anyone and everyone to potentially be able to gain access to private data on the backup machine, so the target directory needed to be encrypted. There are a lot of options, but I opted for the easy encFS route and just installed "cryptkeeper" and had it setup the directory.

Now all I have to do is mount the encrypted backup directory, run the script to turn on the reverse ssh tunnel, and run the backup script, and I have an encrypted backup solution for my server that gets around firewalls.

Not bad.

References

    Posts for Thursday, August 13, 2009

    avatar

    Open Source Days 2009: Talk Suggestions

    Peter Toft has made an announcement on his weblog about Open Source Days 2009. Open Source Days is the largest Danish open source conference that targets both developers and end-users. This year the conference will take place the 24’th of October. It is only going to be a “small” community conference and then there will be a larger conference in the beginning of 2010. I am already very excited about this conference and I am looking forward to meet a lot of Danish open source people.

    Peter Toft also suggested that people should let the coordination team know which talks they would like to hear about. Here are my suggestions:

    • Julia Lawall from DIKU about Coccinelle. Julia did perhaps the most interesting talk at Open Source Days 2008 about her research on semantic patches and how they are used. I would like to hear what has happened since then, especially regarding the focus on bug hunting using Coccinelle.

    • Bryan Østergaard about open source project management. Bryan is the leader of the Exherbo project and used to work on Gentoo before finally starting his own project. Bryan has written an interesting blogpost about how to manage an open source project the right way and getting more contributors and more useful contributions. It would be interesting to hear more about this as a talk at the conference.

    • Jesper Louis Andersen and I are working on a Git tutorial spread out over three workshops and we are planning to present them during the winter at SSLUG’s location in Frederiksberg. We could do a one hour talk at Open Source Days, and I am sure a lot of people would find it interesting to hear.

    • A lightning talk about communities on IRC. This is not super important, but if someone found it interesting I would be more than willing to do it.

    Looking forward to see you at the conference. Remember to follow the Zebrapig!

    Subtitler in Qt

    A certain company needed a way to easily get text-based subtitle files in a batch fashion. The DVDs were available for ripping such subtitles, but the necessary OCR work proved too time-consuming and cumbersome, even with solutions like SubRip. So, I figured that 1000s of individuals on the Internet already gladly spend their days OCRing DVD subtitles into text formats, and sure enough databases like Subscene exist. So, I built a program to wrap Subscene’s web interface, and what better way to do this is there than QtWebKit?

    Subtitler's Subscene Interface

    I capture the downloads by using QtWebKit’s unsupportedContent signal and parse the downloads by using QNetworkAccessManager’s finished signal. I then run the zip archive through QtIOCompressor’s code for unzipping zips, then extract and parse the subtitles.

    A significant issue is that a lot of the subtitles on Subscene are from torrents that have videos which are cut off at the beginning. The solution is to shift each subtitle in the file by a constant time interval if neccessary, so I built an interface to easily see and shift timing:

    Subtitler's Preview Interface

    As you can see, it’s possible to shift all the subtitles. Phonon made this page a breeze. One significant challenge was writing a search algorithm that would find the correct Subtitle based on a time falling in a certain range. It needed to be super speedy and designed for sequential searches. I came up with the following, which could use a bit of improvement:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    QString SubtitleParser::subtitleAtTime(quint64 time)
    {
    	QLinkedList<Subtitle>::const_iterator i;
    	bool forward = true;
    	for (i = m_searchPosition; i != m_subtitles.constEnd(); ) {
    		if (i->isContainedIn(time)) {
    			m_searchPosition = i;
    			return i->text();
    		}
    		if (i->isAfter(time)) {
    			if (i == m_subtitles.constBegin())
    				break;
    			--i;
    			forward = false;
    		} else {
    			if (!forward)
    				break;
    			++i;
    		}
    	}
    	return QString(' ');
    }

    Another challenge was dealing with QWizard and QWizardPage, particularly issues with fields and custom buttons. The field/property system is just too cumbersome to work with; there ought to be a better way of establishing centralized data with straight up pointers. The buttons on QWizard all want to be global, so adding a custom button to a single page proved a bit hackish. It’s a cool API, but just a little bit limiting. If anyone has some suggestions, let me know.

    As always, the code is available on my gitweb, and I encourage you to try it out, read the code, and send me suggestions in the comments below.

    Though this was designed to work on Linux, Qt, being delightfully cross-platform, also makes it possible to run the Subtitler on OSX. Check out the OSX screencast:

    Direct YouTube Link

    Better Fox, Cat, and Weasel – part 2


    Header

    Continuing from Better Fox, Cat, and Weasel. Recently I had to create a new mozilla configurtion folder because I decided to share icecat’s configurations with firefox’s (don’t ever do this ;) ) and realized that I missed a couple things.

    about:config

    Mouse scrolling

    The number of lines to scroll and use smooth scrolling:

    mousewheel.withnokey.sysnumlines false
    mousewheel.withnokey.numlines 8
    general.smoothScroll true

    Spell check in one line text boxes too:

    layout.spellcheckDefault 2

    Disable blinking text (rarely seen, but very annoying):

    browser.blink_allowed false

    Searching from the address bar and to not use “I’m Feeling Lucky”

    keyword.URL

    Change from http://www.google.com/search?ie=UTF-8&sourceid=na vclient&oe=UTF-8&gfns=1&q= to http://www.google.com/search?q=

    Others

    Font Size

    I find it best to use the css font tags to set my font size. I’ve talked about this before but this seems a better place for it. Check out Daniel Greene’s CSS Font Properties and look for font-size medium and set your default font, and font-size.

    Always show go button

    Show Go!

    Navigation

    F3 will search forward; shift-F3 will search backward.

    Middle-clicking a tab will close the tab.

    Testing new Mozilla releases

    You can enable “earlier version” add-ons by adding to your about:config:

    extensions.checkCompatibility bolean false

    To add an earlier add-on: find the add-on page, view the source, search for the .xpi or .jar file and add https://addons.mozilla.org/ to the front of it.

    avatar

    minor uniformity patch for smplayer

    One of the things that good Linux applications should have is uniformity. Just like Mac OS X does. All applications should use the same keybindings to perform the same tasks. For example, on _every_ OS X application, in order to quit it you have to press “CMD+Q”, it’s that simple and everybody follows it. Everybody. On Linux though there are some applications that simply don’t care about uniformity. One of these applications is smplayer.

    While it is almost standard for Linux applications to quit using Ctrl+Q, smplayer simply doesn’t have this option. It has the option of closing the current video with Ctrl+X but it doesn’t have the simple option of quitting using a keyboard shortcut.

    So, the next (oneliner actually) patch does simply what I described above. It makes smplayer quit using “Ctrl+Q”.

    The screenshot that shows what the patch does:
    smplayer

    smplayer-0.6.8-quit.patch:
    --- smplayer-0.6.8/src/baseguiplus.cpp 2009-08-13 16:07:04.000000000 +0300
    +++ smplayer-0.6.8/src/baseguiplus.cpp 2009-08-13 16:08:22.000000000 +0300
    @@ -67,8 +67,7 @@
    tray->setToolTip( "SMPlayer" );
    connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
    this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
    -
    - quitAct = new MyAction(this, "quit");
    + quitAct = new MyAction(QKeySequence("Ctrl+Q"), this, "quit");
    connect( quitAct, SIGNAL(triggered()), this, SLOT(quit()) );
    openMenu->addAction(quitAct);

    And a patched ebuild for smplayer-0.6.8 to use this minor patch (only one line is added to the ebuild):
    smplayer-0.6.8-r1.ebuild

    P.S. Keybindings in smplayer can be set through Preferences, and someone could actually put Ctrl+Q as the quit shortcut but I think that this should be the default setting like most other applications have it. Uniformity matters.

    avatar

    Windows Mobile 6.5 Review

    You know that nervous feeling you get just before you install Linux for the first time? Especially if you’re installing something like Gentoo – all that weird scrolling of funny commands scream “no more warranty for you“? It’s quite the same when you flash your first ROM – the equivalent of installing an OS on your phone.

    I own a Windows Mobile phone. I would be lying to say that my general dislike of Windows extends to the Mobile version – it is a very capable operating system, and more importantly, very flexible. I would probably go so far to say that it’s better than all of the alternatives in that market (which is definitely more than 2). I would also like to spend an article discussing what I believe are the best/vital application for it, but I’ll save that for later.

    If you buy any Windows Mobile powered phone nowadays, it’ll probably come preloaded with Windows Mobile 6. However two newer version do exist (for beta-testing): 6.1 and 6.5 – the latter being the latest, and apparently a huge improvement over 6.1. When 6.1 came out, I instantly looked for a way to upgrade, new features are always attractive. I found a lovely community by the name of XDA-Developers – basically a bunch of smartphone geeks. However most of them said that especially for my phone model, it would lag and probably be as stable as Vista.

    6.5 has been out for a while, and that has allowed plenty of ROMs to mature and undergo vigorous testing by others. ROMs are basically the equivalent of Linux Distributions - they come with their own style, preloaded applications, system modifications, and so on. I picked a ROM that I thought looked good (mainly because it sticks to the defaults – I don’t like all the unwanted bulk) and flashed it (on a Windows computer – there is a way to flash it on Linux but I didn’t want to risk “bricking” the phone.)

    Right, that was a long introduction, let’s get to the review!

    wmreview1

    The today, or home screen, has a brand-spanking new interface named Titanium. The home screen is one of the vital areas of the phone – allowing you quick access to pretty much anything you need. It now looks downright dashing and is themeable. It provides access to S(M)MSes, phone records, favourite contacts, weather, email, and has plugins to extend its functionality. It’s a definitely improvement and all this time when WM has been playing catch-up on Apple’s “home” screen, this is where its overtaken Apple.

    It makes full use of both vertical scrolling (to choose between plugins) and horizontal scrolling (for more information within plugins). Shown in the example above are two plugins, the “clock”, which is where it is left at for most of the time, and the media plugin, which allows you to control your music playing (even choose other songs, pause, play) right from the home screen. Other examples (not pictured) are the calendar, which allows you to flick through your upcoming appointments within the next two days, and the pictures which allows you to browse your pictures. Etc. Wonderful stuff.

    Even on my HTC Hermes, probably not known now for its processing power, it runs quite smoothly and only lags when I am running several programs on the side. This is acceptable I guess.

    wmreview2

    The lock screen has also been improved. It follows the same “sliding” action as the iPhone but the slider begins at the middle – nifty if you prefer to hold it with your left hand or your right. A definite plus is that it shows useful information on the lock screen. Shown here it is displaying an upcoming appointment, but it also shows SMSes, missed calls, etc.

    wmreview3

    The start menu has been replaced to a rather beehive-ish layout. Microsoft claims it improves usability - other than being bigger and more touch-friendly than the previous menu, I don’t personally see any difference to the classical grid layout – if anything, its more confusing. At least its aesthetic and overlays upon your background image (note I am using one of the defaults). It’s not very configurable at the moment and you’ll have to scroll a bit if you have a lot of applications, but this could be liable to change in the future.

    Please also note that in the screenshot above the ROM I used modified it so that it shows 4 columns instead of the default 3. This is an improvement but keep in mind that other releases might not feature the same 4 column layout.

    wmreview4

    The next up is what I believe is the biggest improvement: every single menu or scrollable frame has been given thicker padding and a kinetic scroller. The scrollbars themselves have been made slightly bigger, but more importantly you can see that it’s well spaced, finger-friendly, and of course, you can flick through it easily. Shown in the picture is the “browse files” and a menu of the browse files. It does look a tad bit fat in the picture, but all-in-all I don’t see how I did without it in the past.

    wmreview5

    Finally I am going to highlight some of the in-house application upgrades. First is the messages application, which deals with SMSes, Emails, etc. Messages are now shown in a conversation view – true, this is an old feature with other smartphones, but a godsend for Windows Mobile users. Internet Explorer has also been revamped – and new design almost completely ripped off Opera Mobile. Buttons hide themselves automatically to give maximum screen estate when surfing, and a mini-page map shows when you scroll around the webpage – with of course kinetic scrolling. Tabs are also a huge plus. However my personal experience hasn’t been that great as it does seem to lag quite a bit – so I will be sticking to Opera Mobile for the moment.

    I should also mention that around here and there several small usability tweaks have been made and though screenshots cannot capture these effectively they really add to the “polish” Windows seems to be doing on their beta in preparation for the upcoming Windows Mobile 7.

    Finally, this is also version 6.5 – Windows seems to be hard at work and making lots of improvements – and already other reviews on later versions show an interesting new improvement on the softkeys at the bottom. I’m looking forward to where this is going, and definitely think Windows Mobile 7 will turn out to be a success – at least if their competitors don’t make them play catch up again.

    Related posts:

    1. Windows 7 Review
    2. Windows 7 “feature”: let’s include XP!
    3. Blender 3D: Architecture, Buildings and Scenery – Review

    Posts for Wednesday, August 12, 2009

    Scala tail recursion and decompiler adventures

    I’ve been into Scala lately. More about it will follow later, but there’s something I found out which I really like.

    Last couple of days I wrote some very basic Scala snippets, containing constructs which would be non-trivial or ‘unusual’ to write in Java, compile it to a class file, and then use a Java decompiler to figure out how the Scala compiler maps those constructs to JVM bytecodes.

    There’s one thing which took my attention: looks like (basic) tail-recursive functions are optimized into while-loops! This only happens if the last call of a function is a call to itself (the most basic form of tail recursion), but it’s an interesting feature anyway… No more need to put socket accept handling in an infinite while loop :-)

    A little demo. First, here’s a Scala object which implements a very basic ‘reduce’ function:

    object Reducer {
      def reduce[T, V](fun: (V, T) => V, values: List[T], initial: V): V = {
        if(values isEmpty)
          return initial
        val next = fun(initial, values head)
        return reduce(fun, values tail, next)
      }
    
      def main(args: Array[String]): Unit = {
        val values = List(1, 2, 3, 4)
        val sum = reduce[Int, Int]((x, y) => x + y, values, 0)
        println("Result: " + sum)
      }
    }
    

    We can compile and run this, and it’ll output the expected result ‘10′:

    MacBook:reduce nicolas $ scalac Reducer.scala
    MacBook:reduce nicolas $ scala Reducer
    Result: 10

    Now we can open the generated class files in JD. There are a couple of them (it’s interesting to take a look at all of them and figure out what they represent exactly), but in this case we need ‘Reducer$.class’, which contains the implementations of our public functions, including ‘reduce’.

    Here’s the Java version of the ‘reduce’ function:

    public <T, V> V reduce(Function2<V, T, V> fun, List<T> values, V initial)
    {
      while (true)
      {
        if (values.isEmpty())
          return initial;
        Object next = fun.apply(initial, values.head());
        initial = next;
        values = values.tail();
      }
    }
    

    ‘Function2′ is a built-in Scala type which represents a function taking 2 parameters. As you can see, this code does exactly the same as our Scala version and is most likely the way we’d write the code manually as well (the only thing I don’t get is why ‘next’ is an Object and not a ‘V’, I might figure that out later), but without forcing us to write the imperative code, whilst still producing bytecodes which will most likely show the best performance on the JVM (which currently has no tail recursion optimization support (although that might change one day)).

    I like it :-)

    [update]
    For reference, here’s a slightly more Scala-ish implementation of reduce, showing the same time performance characteristics during some basic profiling. I was not able to get JD nor jad to generate any usable decompiled code though:

    def reduce[T, V](fun: (V, T) => V, values: List[T], initial: V): V = {
        values match {
            case List() => initial;
            case head :: tail => reduce(fun, tail, fun(initial, head))
        }
    }
    

    It uses Scala’s “List” pattern matching functionality.

    Compiling Pure-FTPD with MySQL Support in RHEL5 x86_64

    I really had a hard time getting pure-ftpd 1.0.22 to compile properly witih mysql support on a RHEL5 x86_64 server.  It turns out that the mysql libraries path in the configure script is incorrect.  I’m not sure if this is just a problem with my particular configuration or with the way pure-ftpd tries to figure out where the mysql libraries are.  In any case, I modified the configure script to use mysql_config with appropriate options to set the mysql include paths and lib paths as appropriate.  Assuming mysql_config is in your path, I wouldn’t expect this to ever fail.

    If anyone else has this problem, just apply the following patch to the configure script:

    --- configure.old       2009-08-12 13:11:07.000000000 -0500
    +++ configure   2009-08-12 13:22:23.000000000 -0500
    @@ -25114,9 +25114,9 @@
    LDFLAGS="$LDFLAGS -L${withval}/lib -L${withval}/lib/mysql -L${withval}/mysql/lib"
    CPPFLAGS="$CPPFLAGS -I${withval}/include -I${withval}/include/mysql -I${withval}/mysql/include"
    else
    -      LD_RUN_PATH="/usr/local/mysql/lib:/usr/local/mysql/lib/mysql:/usr/lib/mysql:/usr/mysql/lib:/usr/mysql/lib/mysql:/usr/local/lib/mysql:${LD_RUN_PATH:+:}${LD_RUN_PATH}"
    -      LDFLAGS="$LDFLAGS -L/usr/local/mysql/lib -L/usr/lib/mysql -L/usr/mysql/lib -L/usr/local/lib/mysql -L/usr/local/mysql/lib/mysql -L/usr/mysql/lib/mysql"
    -      CPPFLAGS="$CPPFLAGS -I/usr/local/mysql/include -I/usr/include/mysql -I/usr/mysql/include -I/usr/local/include/mysql -I/usr/local/mysql/include/mysql -I/usr/mysql/include/mysql"
    +      LD_RUN_PATH="`mysql_config --libs | awk '{print $1}' | cut -c3-`:${LD_RUN_PATH}"
    +      LDFLAGS="$LDFLAGS `mysql_config --libs | awk '{print $1}'`"
    +      CPPFLAGS="$CPPFLAGS `mysql_config --include`"
    fi
     
    { $as_echo "$as_me:$LINENO: checking for floor in -lm" &gt;&amp;5

    Backup Your Xing Contacts Using Bash

    So, you have bloody Xing account and you want to backup your contacts? But you don't want to upgrade to become a premium member (which I would recommend if you're a regular Xing user and want to backup your contacts on a regular basis) because you plan on leaving the platform anyway? If that's the case the following might be of interest to you ;-).

    Yesterday I decided that I want to leave Xing for the better. I just didn't get any use out of the platform. In the 3 years I was a member I didn't participate in any groups, nor did I actively manage my network. I accepted contacts when they approached me, but that's about it. Most of my contacts are either work colleagues or people I know in person and I think I really don't need to be a Xing member to just, well, manage that data. On the other hand I have a linkedin account as well. I might need to put some work into that though. In any case, I consider my linkedin account more valuable in terms of networking than my Xing account and most of my important contacts are on linkedin too anyway.

    So I needed a way get all my contacts of the platform, just to be sure my local address book isn't out of sync (I'm not really into contact management so it is probably way out of sync). Xing however, provides a function to export all vCards in one go to premium members only.

    Sorry guys, but I don't want to go premium just before leaving Xing.

    IMPORTANT: Xing's TOS don't allow to use scripts to interact with the Xing website. I would have used an API, as stated in the TOS, but I couldn't find any references if this API does even exist :-/. If I'm wrong please point me into the right direction, but, I share tante's opinion on the matter. So, use this script on your own risk! I am not responsible for any implications the usage of this script has regarding your relations with Xing.

    Okay, back to the story: I wrote a little bash script which utilises wget and sed to fetch the vCards of my Xing contacts.

    To run the script just download it from below, put it in your ~/bin directory and make it executable. The script will download the vCards of your contacts into the current directory when you execute it. It accepts one parameter, namely the number of pages it needs to check to get all your contacts. To find out about that number, just go to your Xing contacts page and switch to vCard view. The last number of the pagination links below the vCards is the number you need. And last not least you also have to set your username and password inside the script to make it work.

    The script will sleep 2 seconds after each fetched vcard, this is to prevent the script from hammering the Xing servers, so if you have lots of contacts you might go and do something else while it's running. The error handling of the script is pretty basic, it won't let you know if a download fails, but you can check if everything worked correctly by just counting the number of vCard files against your number of contacts when the script has finished.

    That's it! Have fun leaving Xing!

    %> ~/bin/xingscrape.sh 7
    Authenticating ...
    Fetching vcards ...
    Peter Lustig ...
    ...
    ...
    Done!
    %> ls -l | wc -l
    77
    

    And here's the script:

    xingscrape.sh
    #!/bin/bash
     
    user='XINGUSERNAME'
    pass='XINGPASSWORD'
     
    # script start
    if [[ $# -lt 1 ]]; then
        echo "Error: missing offset"
        echo
        echo "Usage: $0 [offset]"
        exit 1
    fi
    count=$1
    url='https://www.xing.com/app/contact?notags_filter=0;card_mode=1;search_filter=;tags_filter=;offset='
    useragent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5"
     
    # authenticate and save cookie
    echo "Authenticating ..."
    wget --cookies=on \
         --keep-session-cookies \
         --save-cookies=cookie.txt \
         --post-data="login_user_name=${user}&login_password=${pass}&remember-login=1&op=login" \
         --user-agent=${useragent} \
         --quiet \
         -O - \
         https://www.xing.com/app/user \
         > /dev/null
     
    # dumb check if auth worked
    if [ $(wc -l cookie.txt | cut -c 1) -lt 6 ]; then
        echo -n "Boo, auth failed :-/!"
        exit 1
    fi
     
    # lets do all the work
    echo "Fetching vcards ..."
    for i in $(seq 0 $count); do
        # fetch vcard urls
        vcards=$(wget --referer="https://www.xing.com/app/user?op=home" \
             --cookies=on \
             --load-cookies=cookie.txt \
             --keep-session-cookies \
             --save-cookies=cookie.txt \
             --user-agent=${useragent} \
             --quiet \
             -O - \
             "https://www.xing.com/app/contact?notags_filter=0;card_mode=1;search_filter=;tags_filter=;offset=$(($i*12))" \
             | sed -n 's/.*href="\([^"]*vcard[^"]*\)".*/\1/p')
     
        # fetch each vcard
        for vcard in $vcards; do
            fname=$(echo $vcard | cut -d \= -f3)
            response=$(wget --referer="https://www.xing.com/app/user?op=home" \
                 --cookies=on \
                 --load-cookies=cookie.txt \
                 --keep-session-cookies \
                 --save-cookies=cookie.txt \
                 --user-agent=${useragent} \
                 -O $fname \
                 https://www.xing.com${vcard} 2>&1)
     
            # check HTTP response if we got the vcard
            echo $response | egrep -i "200 OK" > /dev/null
            if [ $? == 0 ]; then
                # give vcard file a proper name
                contact=$(head -n4 $fname | tail -n1 | cut -d \: -f2 | tr -d [:cntrl:] | iconv -f ISO-8859-1 -t UTF-8)
                mv $fname "$contact"
                echo "$contact ..."
            else
                rm $fname
            fi
     
            # don't hammer their servers
            sleep 2
        done
    done
     
    # delet cookie etc
    rm cookie.txt
    echo "Done!"

    Of course there's room for improvements. If you have an idea how to make this script better just let me know in the comments ;-).

    Read or add comments to this article · Save to del.icio.us
    avatar

    Dell Inspiron 9100 infra red port

    My old Dell laptop has a built-in infra red port on the front. In the 4 or more years that I've had it, I've had no need for the port.

    Now that it is becoming my (MythTV) media centre, the infra red port becomes useful! Here are the steps I used to get it working. I had some small hassle with the built-in serial port driver taking over.

    1. First, make sure it's enabled in the BIOS, and take note of the serial port it's attached to.

      There are no other serial ports on this laptop, so anything that looks like a serial port is likely to be the infra red port.

    2. I used lirc to receive and configure the port.

      In Gentoo enable the lirc global USE flag (global means put it in make.conf because many programs can make use of it). Also add this line to make.conf:
      LIRC_DEVICES="sir"

      In other distros, you have to somehow build the sir driver.

      Also add the lirc USE flags hardware-carrier and transmitter. You can do this in /etc/make.conf, or better use /etc/portage/package.use, or better still, make package.use a directory, and add the file /etc/portage/package.use/lirc-20090806 with the contents:
      app-misc/lirc hardware-carrier transmitter

      (You can of course make any-named file in /etc/portage/package.use)

    3. (re)compile! This includes lirc, MythTV, mplayer and anything else that might be able to take advantage of your new lirc USE flag.

      In Gentoo, you could use the command:
      emerge --update --newuse --deep world
      to find and rebuild all packages that have changed USE flags.

    4. Now you need to load the lirc module. For com1, run this command:
      modprobe lirc_sir io=0x2f8 irq=3 threshold=5

      options lirc-sir io=0x2f8 irq=3 threshold=5
      Also add this line to remove any conflicts:
      install lirc_sir setserial /dev/ttyS0 uart none; modprobe --ignore-install lirc_sir

      Make sure you run update-modules; then unload and reload the lirc_sir module after any changes to lirc.conf

    5. Test your configuration with mode2. Run mode2 as root and then press buttons on a remote. You should see some output like
      pulse 591
      space 96900
      pulse 9042
      space 2277
      pulse 591
      space 96900
      pulse 9042
      space 2273
      pulse 594
      space 96901
      pulse 9042
      space 2274
      pulse 593


      If not, make sure you've unloaded any serial related module. Check dmesg after loading the lirc module to make sure your hardware is recognised:
      $ dmesg | grep lirc_sir
      lirc_sir: I/O port 0x03e8, IRQ 4.
      lirc_sir: Installed.


    6. You're almost there! Now you can download remote codes from the LIRC website, or make your own with irrecord. I made my own, since my remote wasn't there.

      Copy the remote code file to /etc/lircd.conf

      Leave the /etc/conf.d/lircd blank or all commented out if you have the same hardware

      Start lircd: /etc/init.d/lircd
    And that should be that!

    Many thanks to:

    Posts for Monday, August 10, 2009

    It's alive!

    Elbereth - my old laptop is alive! :D

    It turned out that what made it look completely dead was some faulty RAM. Without those 256 MiB (the 1 GiB left is enough for my needs anyway), it boots up and works just fine :] Thanks Maq for fixing my precious lappy! :D

    So what did I learn from this disaster:

    • don't panic, it can probably be fixed if you keep your cool and check everything
    • faulty RAM shows the same symptoms as clinical death ...especially since it seems that on laptops you don't get those tell-tale beeps when RAM is foo
    • it's still nicer to have your old lappy working then buying a new one
    • reliable backups are essential
    • PortableApps are a nice solution when needs be ...but, boy!, am I happy to have my KDE an Awesome back! XD
    • Amarok is not only amazing, but most probably the best tool out there to listen to free music and disover new artists and tracks
    • now I understand (again) why people use FaceBook and Flash games ...man, Windows is such a boring OS ...I actually caught myself searching for flash games! O_o
    • what people say about the ThinkPad's keyboards is true! They are fantastic!! — the bounce, the sound, the layout — it all makes sense, when you get used to it! If my dad didn't let me occasionall borrow his old ThinkPad, I'd never believe just how much of a difference there is!
    • 14.1" is enough (erm, I'm talking about the screen diagonal, BTW)
    • when Elbereth finally gives up and dies — hopefully not for at least a year! — ThinkPad T400 will be in my narrowest selection for a successor (probably called Fangorn)

    hook out >> lalalalala, lappy working, eix-sync; emerge -DNu world, studying obligation law while stuff compiles...

    P.S. Maq (a.k.a. MaQmigh, Dexter) is a hardware wiz, a co-worker at Cyberpipe, friend and an all-round great guy
    <!--break-->

    New Shoes

    After reading splitbrains latest article about his new shoes and a closer look at this:

    3807114243_0d8a61368b.jpg

    3807116783_0dbcd73e20.jpg

    (I wore those shoes through 2 summers and 2 winters.)

    I decided that it might be at the time to get myself some new shoes as well (allthough I was comfortable with the fact that everyone could see my socks when I was walking around the rain issue was a tad bit suboptimal at times ;-)).

    My only problem is that I'm a big fan of Vans since I was a teenager. My first really comfy shoes where a pair of Sk8-His. There's just no alternative (standard Adidas Samba shoes do it too though). So I googled arround if Vans shoes are produced under fair ecologial conditions but found no references. So I hope I'm on the safe side and my new pair lasts at least another 2 years (if you know about something which speaks against Vans please let me know in the comments).

    3807919120_9e1683dc0d.jpg

    BTW, nope, that the color of my new shoes somehow matches the link color I use on my blog or the Arch Linux Logo color was not intentional ;-).

    Read or add comments to this article · Save to del.icio.us
    avatar

    Arch Linux 2009.08 & Froscon 2009

    So, the Arch Linux 2009.08 release is now behind us, nicely on schedule.
    I hope people will like AIF because it was a lot of work and we didn't receive much feedback. I personally like it to apply my fancy backup restoration approach.
    But I'm sure if more people would look at the code we would find quite some design and implementation things that could be improved. (With uzbl I was amazed how much difference it can make if many people all have ideas and opinions about every little detail)

    Later this week I'm off to the Counting Cows festival in France, and the week after that (august 22-23) I'm going to FrOSCon in Germany where I will meet some of my Arch Linux colleagues in real life, which I'm really looking forward to.

    If anyone wants a ride to froscon let me know. But note I'll try to maximize my time there (leave saturday early and come back late on sunday. I even took a day off on monday so I might stay a day longer if I find more intersted people to hang out there)

    Desktop Yank


    Every now and then I get the urge to put up my desktop, so here it is. Not much different (like the kcheckgmail and ktorrent thing). Haven’t got to updating to 4.3 yet because I’m going to have to do a full reinstall soon (don’t really need RTM anyhow). I got a computer that didn’t come with install disks for Vista so I gotta find a way to restore vista from the restore disks created by the emachines restore program (phew). I also got a partition at the beginning of the drive called PQSERVICE that I have no idea what it does. To my dismay I have previously tried to use the restore vista disks and got a big fail. Don’t think the program is able to wipe the disk with Linux partitions. Drat. Anyways, before I veer too far, here’s my desktop:

    Clean

    Dirty

    Ok, I lied. Just updated:

    Not too bad. KDE 4.3 doesn’t start up as fast but that might be because I’m still using the same ~/.kde4 folder. Doesn’t really have to tools I need yet (web browser, sound-recorder, network manager…) but a few good bugs got rid, so it’s a good update.

    Posts for Sunday, August 9, 2009

    avatar

    Jabber

    It is still vacation and I decided that I needed something today on this not to sunny day. So after cycling trough the city and discovering that some places in Amsterdam could really use some attention in OSM (will do that later this week), I decided to setup my own jabber(XMPP) server.

    After browsing trough the portage tree landed on jabberd2. It is writen in C (no java or whatever on my server!) and easy to setup. This basically means that I could register and login using kopete in no time!

    Now the things I like about open protocols (and software of course) is that most of the times you can do way cooler things with it. Take the MSN (of Live) protocol for example: sending messages in plain text over the net! I prefer secure connections, all the time actually, and that is possible with jabber. It is even specified in the RFC. And not just my connection to my server, also the server2server connections are secure. I mean that is just awesome! Since I see no point in securing only one part of the route.

    Now of course some of the people I chat with can still not use SSL which would mean kind of a security risk, and we do not want that. But since you can use a client of your liking I can also use OTR encryption while using jabber.

    Now I already told you that jabber is open. Which means anyone with enough time (and some skills) can write a library for this protocol. Which in turn makes it easy to use for status messages of your bash scripts or for elog messages from portage! Now I have not checked on any of this but I could imaging jabber plugins for torrent/usenet deamons (informing you of your finished download) or even bootup messages from computers that you maintain informing you of several useful things!

    Long story short. I like Jabber!

    Edit: I am now using ejabberd (or recomandation of a fried) and the webinterface rocks!

    Posts for Saturday, August 8, 2009

    sms is a garbage protocol

    • no error on transmission failure
    • no failure on invalid recipient
    • no assurance of delivery to temporarily disconnected recipient

    All of which amounts to the result that when you do send a text you have no idea if the number is correct, if the message went through, and in the event the person’s phone is turned off if he’ll ever see it.

    Now, I really don’t care if the flaws are in the protocol, the phones or the services we pay for; what I do know is that it all makes for an appalling technology whose reliability imitates Microsoft’s infamous msn messenger where messages constantly go missing without notice. I hear all the time about messages I never saw and apparently when my phone is off for a few days there is zero chance of getting messages sent in that interval.

    Compare it to email, which doesn’t have any of these flaws, and it seems incredible that we are actually paying to use this.

    And that’s to say nothing of the horrendous user interface for typing messages on a phone to begin with.

    This entry belongs in a comprehensive tome I have been writing in my head for a decade, detailing just how much cell phones suck. But the field is so vast that it overwhelms my ability to articulate it.

    Planet Larry is not officially affiliated with Gentoo Linux. Original artwork and logos copyright Gentoo Foundation. Yadda, yadda, yadda.