Posts Tagged ‘linux’

“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.

PAE

Wednesday, June 16th, 2010

PAE på en burk med 192M RAM är nog rätt ovärt.

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?

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.