Pavol Rusnak #cypherpunk #hacker #openhw #privacy #bitcoin #newmediaart

Version sorting in Ruby

Today I needed to implement “human sort” for a list of distributions we support in the Open Build Service. I wanted to sort them alphabetically but at the same time the newest ones at the top. I ended up with the following code:

module Enumerable
  def version_sort
    sort_by { |key,val|
       key.gsub(/_SP/,'.').gsub(/_Factory/,'_100').split(/_/) \
          .map { |v| v =~ /\A\d+(\.\d+)?\z/ ? -(v.to_f) : v.downcase }

@distros = [

@distros.version_sort.each{ |v|
  puts v

which produces this list:


Nifty, right? :-) The idea is simple. I use the sort_by function which pre-computes the values that are later compared. I replace some special values like “Factory” or “_SP”, because I want “Factory” to be the newest (100 is higher than any other openSUSE version) and “11_SP1” to behave exactly like “11.1”. Then I split the key using the “” delimiter and turn any string in form “digit” or “digit.digit” to float number. I change the sign, because I want versions to be sorted in the reverse direction. Good thing is that Ruby operator <=> works on arrays also, so I’m done with key modifications and the sort does the rest …

PS: I used |key,val| in sort_by block because I want to use this function also to sort hashes by their key. This way it works both for arrays and hashes with any further modifications.

GNOME-Shell Extension: YaST (item in) Status Menu

This is just a short follow-up to my older blogpost Adding YaST menuitem to GNOME 3 status menu. Few minutes ago Andy asked me if I could create a proper gnome-shell extension so I went ahead and did it. :-)

I’ve set a git repo on Gitorious and also built the package in my home:prusnak project. If there will be interest from our GNOME Team, I will create a submit request to some GNOME devel project and Factory as well.

If you don’t know this yet, you have to install the gnome-shell-extension-yast-status-menu and then either logout and login or press Alt+F2 and type “r” (which will restart gnome-shell).

Enjoy! :-)


Bash PS1 tricks

Many of you know already about this feature, but some of you don’t so I wanted to share it with you. I just changed mine PS1 configuration in ~/.bashrc to look like this:

export PS1='\[\033[1;37m\][\[\033[1;32m\]\u\[\033[0m\]@\h\[\033[0m\] $? \[\033[1;34m\]\w\[\033[0;35m\]$(__git_ps1 " %s")\[\033[1;37m\]]\[\033[0m\] '

Take a look at the following picture to see how it works:


or check the video on youtube.

The number between user@host and the current working directory is the exit status of the most recently executed command (or pipeline). This is great because you don’t have to type echo $? everytime you want to find it out. The __git_ps1 magic will print git branch name if you are inside of the git repository. Furthermore it will add special characters indicating the state of the repo: % - untracked files present, + - new files added, * - some tracked files changed, $ - there is something in the stash (see git stash --help). Pretty cool, right?

openSUSE Spacebus

Yesterday we were replacing old chairs in our Prague SUSE office with the brand new ones. We got a wicked idea to stack the older ones into the Boosters’ Office and have a virtual bus ride for a few minutes. Our colleague Michal Kubecek and his camera were ready as usual so he quickly took a photo of us enjoying the ride:


Later I had some time to practice my 1337 GIMP skillz and created a motivational poster for your viewing pleasure. After Geeko Bus and Geeko Tram I give you without further ado the “openSUSE Spacebus!”:


Credits: bus photo CC BY-NC by yewenyi, space photo CC-BY by Sweetie187, spacebus photo CC BY-NC by me

Adding YaST menuitem to GNOME 3 status menu

This blogpost is now obsolete.

Please go to GNOME-Shell Extension: YaST (item in) Status Menu.

I read a blogpost from Nelson Marques about adding YaST modules icon to GNOME Shell. I kind of liked the idea of YaST integration into GNOME Shell, but I had to share Julian Aloofi’s worries in comments. He came up with a simple idea to just add the YaST menuitem to status menu in the top-right corner. This was very easy to implement because most of the GNOME Shell features are written in Javascript. I created the following simple hack and ended up with this:


If you want to add the YaST menuitem as well, just follow these simple steps (as root):

cd /
patch -p1 < gnome3-statusmenu-yast.patch
rm gnome3-statusmenu-yast.patch

Now you have to restart GNOME Shell (press Alt+F2 and enter “r” command) and you can enjoy the new menu item. :-) Remember, the changes will be lost next time you reinstall the gnome-shell package.

I already contacted Frederic and Vincent about the patch and they are still looking for the best way how to integrate YaST with the rest of the system, so stay tuned. :-)

PS: Andy found an interesting bug. For him, the item was added but clicking on it did nothing. Solution was found by Frederic - just install the missing gnome-menus-branding-openSUSE package.