Posts Tagged ‘ubuntu’

“sudo gedit” must die!

Monday, July 26th, 2010

Why is it that so many Ubuntu guides tell you to do sudo gedit /path/to/somefile when there is a sudoedit command? An editor, like Gedit, doesn’t need to run as root, ever.

This is so much better and safer:

SUDO_EDITOR=gedit sudo -e /path/to/somefile

This will …

  1. Copy the file to /tmp/
  2. Invoke gedit as your user
  3. Update the original file if you changed the temporary file

It would of course be really useful if gksudo had this built in already, and could be used in a nice way by nautilus-gksu.

Stuff

Wednesday, May 5th, 2010

Random stuff jag borde blagat om men inte orkat, i till synes omvänd kronologisk ordning.

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?

Liferea vs tiny screen

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

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!

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.