☠ /home/haaja

Goodbye Google Reader

So yesterday Google announced that they will retire Google Reader. At first this annoyed me since to me Google Reader was their best service after Google Search of course. Luckily there are plenty of alternatives and for now I chose Thunderbird as I already use it for email.

Good riddance!

From your 55 subscriptions, over the last 30 days you read 9,443 items, 
clicked 480 items, starred 1 items, and emailed 0 items. Since May 21, 
2010 you have read a total of 237,212 items.

Installing ownCloud on a Shared Host

I’ve been using Dropbox and Google Calendar for as long as I can remember and I’ve rarely had any problems with them. As a matter of a fact both products work great, offer free service and have saved my ass on few occasions. Sounds too good? Yeah… The old truth still stands: If you’re not paying for it; You’re the product (and sometimes even if you’re paying). The part of me that is concerned about privacy issues has never liked the situation but I’ve argued that the benefits are greater than lack of privacy. Also lately I’ve been syncing more files to my Dropbox and my free disk quota is running out. Therefore I need to either find a better alternative or start paying for the service. Well yesteday I had some free time on my hands and decided to look for an alternative to Dropbox. Ideal replacement should be easy to use, work well and preferably be open souce. It didn’t take me long to bump into ownCloud.

At first sight ownCloud looked great: nice user inteface, open source, media streaming, suppot for applications and most importantly solid enough to have multiple companies offering services using ownCloud. Let’s take ownCloud into a test as I happen to have some extra web space. I have to say though that ownCloud uses the word cloud pretty vaguely as by default ownCloud is installed on one server and the support for external storage is only an experimental feature.

Installation itself was pretty straightforward. I simply downloaded the latest ownCloud from their install page and extracted it on my server. Next I navigated to /owncloud/ and created the admin user. Everything went smoothly and I thought that the installation was successful as I managed to import my calendar and contacts from google and create files and folders with the web ui. However when I tried to configure desktop sync client to work with my ownCloud installation, things didn’t go as planned. The sync client accepted my credentials during the initial setup but complained that credentials were invalid when ever it tried to sync.

To make WebDAV work I had to edit the .htaccess file in the installation directory.

I changed the existing

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2
[QSA,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
</IfModule>

To

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2
[QSA,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
</IfModule>

Spotting the difference is left as an exercise. :D Nah, just kidding it’s the HTTP_AUTHORIZATION line and the added ,L at the end.

One problem solved but then apache started complaining about permissions.

[Thu Jan 10 23:51:14 2013] [error] [client xx.xxx.xxx.xxx] client denied
by server configuration: <INSTALL_DIR>/owncloud/remote.php

As as solution I added to the .htaccess file following lines.

Order allow,deny
Allow from all

Voilá and the sync client managed to synchronize everything.

Next step is to configure my desktop and mobile calendar, email client and mobile phone for contacts and of course sync client to synchronize everything important. I have to test ownCloud for few months until I’m confident enought to ditch my current solutions but so far everything looks great.

My First Patch to GNOME

I’ve used open source software for many years now but I haven’t really contributed back to any of the open source communities. I have filled some bug reports but other than that I’ve been simply a happy (and sometimes less happy) user. However yesterday I took the first step by doing tiny tiny contribution to GNOME or to be specific to gnome-session. The funny thing is that it was all because of selfish reasons.

I was writing my script called osinfo and found out that gnome-session gave exit value 1 when called with —version argument. This was easily tested doing the following.

[haaja@jarvis ~]$ gnome-session --version
gnome-session 3.6.2
[haaja@jarvis ~]$ echo $?
1

Exit value 1 with non-error cases is problematic because usually exit values other than 0 are interpreted as an error. This was also the case with Python’s subprocess module and specifically its check_output function.

Since I knew that this was trivial to fix I thought that I might just as well fix it. The problem was that I had never before contributed to GNOME so I had no clue how and where to send patches. Luckily after some help from google and I was directed to their bugzilla. Unfortunately GNOME documentation isn’t the easiest for the beginner because they are quite dated and I really didn’t want setup IRC client to join their IRC channels and ask for help. So I spent most of the time browsing their bugzilla and reading git logs to determine conventions used for commit messages and bug reports.

EDIT: I finally did find the documentation Contributing patches.

Finally I created a bug report and attached a patch for the bug. Few minutes later one of the developers reviewed my patch and a while later I received email that my patch was committed to the master branch. Everything went smoothly and surprisingly fast so I might just do this again next time I find something that bothers me in GNOME.

Git Subtree Merge

Last week I took part to an intensive Clojure-course which was an introduction to functional programming using Clojure. The course itself was fairly well organized and interesting but that’s not the topic of this post.

The course was built around solving small programming tasks using clojure. Each topic had their own separate git repository on github which we cloned and added our solutions in. The end result was that participants had many repositories (one for each exercise set) and this was fine during the course. Now that I’ve successfully passed the course I wanted to get rid of all the separate repositories and combine them to a single git repository. I could have simply created a new repository and copied the files into it but this way I would have lost all commit history. I have previously used git submodules but since I won’t be developing these assignments further I would rather not user that method. Few minutes of googling and I found a solution for my problem, git subtree merge. Subtree merge is perfect for my use case since I my repositories were separate but they shared no data with each other. In other words there would not be any merge conflicts.

Here is a quick tutorial of the steps that I did.

First I created a new folder called Clojure and two subdirectories called exercises and material.

$ tree Clojure/
Clojure/
├── exercises
└── material

Then I initialized an empty git repository to the Clojure directory.

$ cd Clojure/ && git init

Next I created a subdirectory which I will use as a prefix to a following merge.

mkdir exercises/old_project

Now it was just a matter of adding the old repository as a remote repository to our newly created main repository.

git remote add -f old_project http://www.example.com/repo/old_project.git

Then do the merge without doing the actual commit.

git merge -s ours --no-commit old_project/master

Next we actually add the old_project repository to our new repository. This happens with git read-tree command which reads the master tree of the old_project repository and stores it under the path given with prefix argument.

git read-tree --prefix=exercises/old_project -u old_project/master

Now we are almost done. Final step is to actually do the commit.

git commit -m "Merged old_project repository to Clojure repository"

In my case I had multiple repositories so I just repeated those steps for every repository I wanted to combine. My final repository structure looks like the one below.

$ tree -d Clojure/
Clojure/
├── exercises
│   ├── blorg
│   │   ├── src
│   │   │   └── blorg
│   │   └── test
│   │       └── blorg
│   ├── i-am-a-horse-in-the-land-of-booleans
│   │   ├── src
│   │   └── test
│   ├── looping-is-recursion
│   │   ├── src
│   │   └── test
│   ├── one-function-to-rule-them-all
│   │   ├── doc
│   │   ├── src
│   │   └── test
│   ├── p-p-p-pokerface
│   │   ├── src
│   │   └── test
│   ├── predicates
│   │   ├── src
│   │   └── test
│   ├── recursion
│   │   ├── src
│   │   └── test
│   ├── structured-data
│   │   ├── src
│   │   └── test
│   ├── sudoku
│   │   ├── src
│   │   │   └── sudoku
│   │   └── test
│   │       └── sudoku
│   └── training-day
│       ├── src
│       ├── target
│       │   ├── classes
│       │   └── stale
│       └── test
└── material
    └── 120-hour-epic-sax-marathon
            ├── bin
                    ├── css
                            └── img

The first level subdirectories below exercise and material directories were originally separate git repositories. Now I have one single repository that contains the data of all the old repositories which I can easily push to github.

Migration to Octopress

Brace yourselves, it’s time for another “I migrated from X to octopress” blog post. Try to bear with me.

Like the title hints I have finally started my migration process from wordpress to octopress. I have nothing against wordpress per se but it’s way too big for my needs. I only need a simple way of creating posts every now and then and for that purpose octopress seems to be quite suitable. Also static html pages are more pop than hipster glasses these days.

Migration was easy enough since I didn’t have too many blog posts and pictures in them. The initial migration was made using excellent tool called exitwp. Exitwp converted my wordpress export xml to several markdown posts without problems. Some people have complained that they’ve had some encoding issues with exitwp but I didn’t have any.

So far I have only customized the default theme little bit and transferred the about page and blog posts. I don’t know yet wheter I will transfer the gallery I had on my old blog or not. I think I might just upload my images to picasa or flickr and just link to it. Also I might enable few more plugins if I find any interesting ones. I can already say that Octopress had the best out-of-the- box experience I’ve had. Default theme was gorgeous and few interesting plugins were built in.

Right now everything seems to work and I am more than happy with octopress. I especially like the fact that I can just use vim to edit blog posts and keep everything under git. Octopress also loads a lot faster than my previous wordpress installation, even though I tried to enable all necessary optimizations.

KDE and Ssh-agent

Hello lazyweb!

GNOME or to be more precise GNOME keyring has nice feature of including ssh-agent that integrates nicely with gnome-keyring. I find this feature very convenient since I don’t have to input my password every time I connect to a server. (I sincerely hope that no one is using ssh-keys without password protection).

Things are quite not as convenient on KDE side of desktop environments even though KDE provides handy tool called KDE wallet. Luckily with few simple scripts we can use the combination of KDE wallet and ssh-agent to provide similar functionality on KDE. So without further ado here is the guide.

  1. Open your favorite text editor and create file ~/.kde/env/ssh-agent.sh. Add following lines into file and save it.

      #!/bin/bash
      eval `ssh-agent`
    
  2. Create file ~/.kde/Autostart/ssh-add.sh and add following lines.

     #!/bin/bash
     export SSH_ASKPASS=/usr/bin/ksshaskpass  
     /usr/bin/ssh-add
    
  3. Create file ~/.kde/shutdown/ssh-agent.sh and add following lines.

     #!/bin/bash 
     eval `ssh-agent -k`
    
  4. As a last step you need to give execute rights for the scripts that we just created.

      chmod +x ~/.kde/env/ssh-agent.sh  
      chmod +x ~/.kde/Autostart/ssh-add.sh  
      chmod +x ~/.kde/shutdown/ssh-agent.sh  
    

That’s it! Now simply log out and log back in and notice how kde-wallet will prompt for password and also your ssh-key password will be asked. In case you want check the “remember this password” option and your ssh-key password will be remembered by kde-wallet. One could argue that this type of functionality should be on default KDE installation but then again it wasn’t too hard to achieve this way either.

Disable Arrow Keys in Vim

I know this information can be found in n+1 other places but I will write it here anyway to be able to access it easily later.

One of the most important things when starting to use Vim as your editor is to drop all old habits! Therefore we will disable the arrow keys so that you are forced to use h, j, k, l to navigate. So without further ado here are the changes one should add to their .vimrc file.

noremap ""  
noremap!  
noremap ""  
noremap!  
noremap ""  
noremap!  
noremap ""  
noremap!  

Happy viming!

Implementing Binary Heap Without an Array

So I had this school assignment to implement a binary heap with a twist of not using an array to store the binary tree. You might think that this is an easy problem to solve and after some thinking it turns out that it isn’t much harder than the generic array implementation. However if this is the first time you’re implementing binary heap this way, you’ll likely find it difficult to insert new nodes in O(lg n) time. With arrays you can always find the last element in constant time. Unfortunately this is not the case with object references unless you have a trick or two in your sleeve. Once you’re able to access last node of the heap and sibling nodes of a particular node in constant time, the solution is similar to any text book implementation. It is also worth noting that at the time of writing google isn’t much of a help solving this problem because next to every example shows the array implementation.

I solved the problem by adding all the node into a binary tree AND a doubly linked list. Then I use the linked list to access last node of the heap and siblings of an individual node. There might be other viable solutions as well but this is by far the easiest I’ve heard of. As I’m lazy and can’t be bothered to draw pictures to further explain the solution. I pushed the source code to a github repository. The original repository was a bit messy and in Finnish so no commit history for you guys, sorry.

256 Colors in Vim and Screen

For some strange reason at least Fedora ships screen and vim with 256 colors disabled. Here’s a quick guide how to enable 256 colors in vim and screen.

  1. Add to you .vimrc file

     set t_Co=256
    
  2. Add following lines to your .screenrc file

     attrcolor b ".I"
     termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
     defbce "on"
    

Also check that your terminal supports or has 256 colors enabled. At least gnome-terminals seems to have this by default. Enjoy combination of vim and screen with 256 colors. :)

Matkan Suunnittelu Edistyy

Pitkästä aikaa on jotain kerrottavaa matkasta. Olen tässä jonkin aikaa jo pohtinut, että mitä paikkoja käyn katsomassa Indonesiassa. Indonesia on valtavan kokoinen ja kunnollisen infran puuttuessa matkustaminen on hidasta. Lisäksi minulla on vain kuukausi aikaa matkustaa, joten joudun lentämään pidemmät etäisyydet. Mielenkiintoisia kohteita ovat muun muassa Togianin saaret Sulawesillä, Gili saaret ja Lombok, Komodon saari sekä Sumatran Lake Toba. Kaikkeen ei missään tapauksessa riitä aika, joten joudun valitsemaan listalta yhden tai kaksi paikkaa.

Olen tässä jokusen päivän katsellut Indonesian sisäisiä lentoja ja niiden hintoja. Lennot ovat varsin inhimillisen hintaisia, mutta ongelmaksi on muodostunut se ettei luottokortillani onnistu lentojen varaaminen. En oikein tiedä missä vika on ja olen lukenut pallontallaajista että muilla on ollut samoja ongelmia. Kaikki toimii varaamisessa hyvin siihen asti kun verkkopankista pitäisi palata takaisin lentoyhtiön sivuille. Tällöin tulee aina ilmoitus että maksaminen epäonnistui. Kuulemma lennot ovat edullisia ostaa suoraan tiskiltäkin, mutta haluan varmistaa että mahdun heti seuraavan päivän lennolle. Lopulta kuitenkin sain Batavia Air:lta liput ostettua. Tämäkin onnistui varmasti pelkästään sen takia että kyseinen lafka käytti luottokorttimaksuihin paypallia. No loppu hyvin kaikki hyvin ja lippu on nyt hankittu.

Mikäli lentoni ovat ajallaan, olen Jakartassa 19.12 klo: 23.50, ja tarkoitus olisi ehtiä aamu seitsemän lennolle Medaniin. Medanissa luultavasti joudun nukkumaan univelkaa pois sillä siinä vaiheessa on takana matkustamista jo reippaasti. Kaikki riippuu siitä miten hyvin saan nukuttua lennolla Lontoosta Singaporeen tai vaihtoehtoisesti Jakartan kentällä. Medanista suuntaan sitten kulkuvälineellä X kohti Parapatia ja lake Tobaa. Lake Toban lisäksi piipahdan mahdollisesti gili saarilla tai jossakin muualla, mutta vain aika näyttää onnistunko siinä ollenkaan. Tämän pidemmälle en matkaa ole suunnitellut, enkä aio suunnitellakkaan.

Välihuomautuksena sain myös passini uusittua. Alunperin tarkoitukseni oli uusia passi mahdollisimman myöhäisessä vaiheessa, mutta sitten lentoja varaillessani tajusin että minun on syötettävä passin numero lentoyhtiölle. No ei auttanut muu kuin käydä Pasilan poliisilaitoksella uusimassa passi. Hintaa lystille tuli 53€ + passikuvien hinta jota en nyt tähän hätään muista. Palvelu asemalla oli poliisimaisen töykeää, mutta passin sai kolmessa päivässä. Lisäksi kävin hankkimassa uuden vedenpitävän pussin, sillä vanha taisi jäädä viime reissulla Don detille Laosiin.