Archive for the ‘Programming’ Category

My first prosody module!

Saturday, July 24th, 2010

I have recently written two XMPP related things. The first is a prosody module called mod_post_msg which accepts messages in a HTTP POST, using HTTP authentication. It was inspired by this ejabberd module by skeltoac, but it takes full stanzas, whereas mine just takes a plain text message body.

The second is a sendxmpp like Bash script based on cURL which works with the module. It is supposed to work like sendxmpp, but doesn’t support all of it’s options. You can get sendxmpp-curl here.

This allows you to post simple XMPP messages from CLI (like sendxmpp), with less round trips than a full XMPP session would require (At least I hope so).

Rösträkning med Bash

Monday, 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?

Damn you Ctrl+W

Wednesday, 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?

Monday, 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

Monday, 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

Lighttpd and WP Super Cache

Saturday, 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

Tuesday, 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.

Påminn folk om att rösta

Friday, June 5th, 2009

Här är lite bash-magi för dem som har sin adressbok i Evolution.

CAcert.org

Monday, May 11th, 2009

Byggde ett mek som testar ssl, mest för att jag kör med CAcert vars root-cert inte är med i webbläsare och annat ännu.

Folk verkar tro att saker är trasiga när Firefox ssl-varningar dycker upp.

CAcert är annars awesome!