Rösträkning med Bash

January 18th, 2010

Piratpartiets primärval är avslutat. 1300 röster registrerades av partiets ca 48 tusen medlemmar, dvs ca 2.7%.

Grattis till Norrbotten som hade överlägset högst valdeltagande

Här är ett stycke Bash-magi som ger dig en votes.txt med antal röster och på vem, sorterad fallande efter antal röster. Paketen curl, grep, sed och coreutils behövs om de inte är installerade, iaf i Ubuntu och förmodligen de flesta Debian-baserade distributionerna.

Notera att detta endast visar hur många röster som kandidaterna fått.

#!/bin/bash

curl -s "http://data.piratpartiet.se/Data/DisplayInternalPollVotes.aspx?PollId=2" |
    sed -r 's/\s$|^\s*//g' | # tar bort blanktecken
    grep -E '^[A-Z0-9]{12}\b' | # endast röster
    sed -r 's/^[A-Z0-9]{12}\s*//' | # ta bort röst-id
    sed -r 's/\s+/\n/g' | # dela upp i en kandidat per rad
    grep -E '^[0-9]' | # tar bort tomma rader
    sort | uniq -c | sort -nr > votes.txt # räkna och sortera

# Detta hämtar och byter ut medlems-nr mot namn.
curl -s "http://www.piratpartiet.se/primarvalskandidater" |
    grep -Eo '<span[^>]*SpanCandidateName[^>]*>[^<]*' | cut -d\> -f2 |
    sed -r 's/^(.*)\s+\(#([0-9]+)\)$/sed -i "s,\\b\2\\$,\1," votes.txt;/' | sh

De faktiska ska som jag förstått det viktas efter hur högt man placerat kandidater, eventuell kvotering samt hur fördelningen mellan distrikt ser ut. Så, 16:00 idag presenteras de färdiga listorna. Frågan är; vad gör vi nu?

Liferea vs tiny screen

December 14th, 2009

I use Liferea for RSS-feeds. I also have a craptop with a tiny screen (1024×576px).

Liferea - Normal view

Liferea - Normal view

I think there is room for optimizing this, more spatial perhaps?

Liferea - wide view

Liferea - wide view

This could use some miller-columnification.

Optimally, I would like to have this:

  • Single pane
  • Oldest unread post first
  • Headlines which expand when clicked

Damn you Ctrl+W

November 4th, 2009

Don’t know how many times I accidentally pressed Ctrl+W when I wanted to delete a word in some non-terminal app, instead closing it and losing all the text I’ve written. Now I found out you can do this:

gconftool --set /desktop/gnome/interface/gtk_key_theme \
  --type string Emacs

Then Ctrl+W does what it should!

Trac + Evolution?

October 26th, 2009

Imagine having your assigned tasks from Trac in Evolutions ToDo-list and beeing able to . Like this but with Trac as backend.

Idea for Application menu

September 14th, 2009

Navigating menus with a touchpad isn’t my idea of awesome. But imagine something like Global menu combined with Gnome Do or dmenu.

  1. Press magic keybinding, like Super + Menu
  2. You get some selection thing with all menu items
  3. You type in what you want to do, filtering as you type
  4. ???
  5. PROFIT!

Some IRCin’

<zash_> a do-like application-menu-thing would be handy
<kholerabbi> Which is a pleasure
<kholerabbi> what do you mean?
<zash_> kholerabbi: something that lets you navigate app-menus by keyboard
<zash_> since not everything has proper keybindings
<kholerabbi> zash_: that's actually kind of interesting...
<zash_> and navigating gigantic menu trees with touchpad is a pain
<kholerabbi> you can already use the keyboard (arrow kets etc.)
<zash_> kholerabbi: yes, but arrows and alt+underlined char only does so
        much
<kholerabbi> agreed
<zash_> label-matching ala gnome-do would be faster
<kholerabbi> so you'd press a shortcut (super+menu) then type 'about' or
             'new'...
<zash_> precisly
<kholerabbi> You should mock it up. If it's really a good idea it will
             catch on. Consider large menus like the gimp and inkscape in
             your designs
<kholerabbi> ok
<kholerabbi> I need sleep, but think on it and maybe talk to the global
             menu people
 * zash_ needs moar coffee!

Some bash testing

grep MenuItem some_window.glade -A 3 | \
grep -E '<property[^>]+name="label"' | \
grep -Eo '>[^<>]+' | sed 's/^>//g' | \
sed s/_// | dmenu -b -i

Om Skype

August 23rd, 2009

Piratpartiets mål är att förändra lagstiftningen på en global skala för att gynna framväxten av informationssamhället, präglat av mångfald och öppenhet.

Nice!

Principprogram version 3.3

Den offentliga sektorn ska arkivera och göra dokument tillgängliga i öppna format. Det ska gå att kommunicera med myndigheter utan att vara bunden till en viss leverantör av programvara. Användningen av öppen källkod i den offentliga sektorn, inklusive skolor, ska stimuleras.

Öppna format och öppen källkod ska uppmuntras.

Men, varför;

Webbstrategi- och utvecklingsgruppen som syftar till att förena alla som vill vara med och bidra med utveckling och strategier runt all möjlig mjukvara som rör sig inom PP. Vill du hjälpa till så är det enklast att lägga till antingen Daniel .. eller Mikael .. på skype så bjuder vi in er i chatgruppen.

Meh.

Skype uses a proprietary Internet telephony (VoIP) network, called the Skype protocol. The protocol has not been made publicly available by Skype and official applications using the protocol are closed-source.

Skype has taken extreme measures to obfuscate their traffic and functioning of their program.

This makes me a saaad panda.

Men, vad kan man göra åt det?

Ung Pirat @ Nolia

August 6th, 2009

Lite bilder från Stora Nolia.

Kids vs. Machine

Man vs. Mac

Datorkastning, meet G3 Macintosh.

MMN tejpar

MMN-o tejpar ihop en trashad burk.

Lighttpd and WP Super Cache

August 1st, 2009

Why would you need lua scripting to serve cached static files when you instead can

Like this:

    $HTTP["host"] == "blag.zash.se" {
            server.error-handler-404 = "/index.php"
            dir-listing.activate = "disable"
    }

The stuff i have in the supercache/blag.zash.se/ directory is: 2009, category, page, tag. Oh, and of course index.html, which is configured to take precedence over index.php. If you have other virtual directories in your root you will need to create symlinks for those too. And of course for each year, if you have that kind of setup.

Also, with mod_compress, there’s no need for WP Super Cache’s own (apparently buggy) compression. And you get compression of scripts and style sheets.

Destrutting xfce4-panel

July 21st, 2009

I didn’t like that when xfce4-panel is in a fixed position and not expanded to the full width of the screen, it sets _NET_WM_STRUT and _NET_WM_STRUT_PARTIAL which reserves space at the screen border.

Waste of space on my tiny screen

Waste of space on my tiny screen

The unused space on my tiny screen above the maximized window annoys me, so i downloaded the source whith apt-get source xfce4-panel and added a setting to disable setting the _NET_WM_STRUT properties. Here’s a tarball of my patches.

Yay, less wasted space.

Yay, less wasted space.

The setting can be enabled by editing ~/.config/xfce/panel/panels.xml and add (or change if it already exists) <property name="disable_struts" value="1"/> in the <properties> element.

A better long term solution would probably to have the window manager ignore struts for maximized windows when a panel does not cover the entire border.

Grattis PP!

June 8th, 2009

Pirat(er) till EU-parlamentet! Yeah!