Archives 2005 - 2019    Search

Märkliga krigsrubriker i SvD om valsystemet

published Sep 01, 2010 11:57   by admin ( last modified Sep 01, 2010 11:57 )

Man bör väl egentligen mer uppmärksamma tidningar när de gör bra saker, men ibland är det så enkelt att peka ut något som blev fel. Det finns kritik i Danmark mot det svenska valsystemet. Det kan man skriva om. Ett valbevakningsorgan skickar inte observatörer till det svenska valet för att det inte har någon kritik att framföra. Det kan man också skriva om. Men om man sätter ihop dessa diametralt motsatta nyheter i en krigsrubrik så kan det bli konstigt:

Det verkar nämligen på rubriken som om danskarna och OSCE tycker samma sak: Danskarna kritiserar, och OSCE är så uppgivna över sakernas dåliga tillstånd att de inte en ids komma.

Det svenska valsystemet har blivit föremål för en internationell debatt. Det är framför allt i danska tidningar som den svenska valsäkerheten blivit en het fråga



Läs mer: Valobservatörer nobbar det svenska riksdagsvalet | SvD


A buildout run from its own bootstrapped python

published Sep 01, 2010 06:32   by admin ( last modified Sep 01, 2010 06:32 )

Just a quick note so I can find it again:

Because the recipe plone.recipe.zope2instance relies on zc.recipe.egg, it also supports the python option. However, the recipe plone.recipe.zope2install did not support that nice option. I added the option and made a new 3.3 release.



Building custom Python in the same buildout as Zope2 — BubbleNet - Plone and Zope services in Belgium


Europeiskt försvar oroande svagt

published Aug 28, 2010 07:12   by admin ( last modified Aug 28, 2010 07:12 )

Alltsedan andra världskriget har den demokratiska delen av Europa förlitat sig på Pax Americana - att USA har varit tillräckligt starkt för att garantera vår säkerhet.

Men USA står mycket möjligt inför stora ekonomiska problem som kan göra att de inte kommer att kunna - eller vilja - garantera Europas säkerhet med samma emfas som idag.

Inom politiken kan man vara oense om vad staten skall göra, men ett gott försvar räknas alltid till kärnverksamheten. Europa behöver ta ett större ansvar för att kunna försvara vår frihet och välstånd.

The beginnings of a sound policy today, he argues, might be for America to withdraw from a costly war in Afghanistan and pull forces out of Europe. Such a move would shock Europeans who hope that the impact of their own defence cuts will be softened by American help in times of need.


Läs mer: The cost of weapons: Defence spending in a time of austerity | The Economist


Catch errors before they become Import Errors

published Aug 20, 2010 04:27   by admin ( last modified Aug 20, 2010 04:27 )

A python script to count bpm (beats per minute) on Linux

published Aug 18, 2010 11:53   by admin ( last modified Aug 18, 2010 11:53 )

As I have written before, soundstretch can do bpm analysis on soundfiles on Linux. However:

  • it needs wav rather than mp3 files.
  • For my music it sometimes report half the correct bpm

 

I have written a script that wraps soundstretch and lame into a command that takes an mp3 file as input and outputs the bpm.

Internally, it converts the mp3 into temporary wav file with lame, runs soundstretch on the file, gets the bpm guess from soundstretch and fits that into a window of bpms.

I do not usually write command line scripts, so there may be problems in the below code, and there are certainly some hard coded assumptions. Use at your own risk. I intend to package this up and release it in some way, but until then, here is is in its present state:

#!/usr/bin/python
DOC = ''' This program detects bpm for mp3 files. It relies on lame and soundstretch being
installed on your system.


Usage:

%s <filename>

-or pipe filenames to it.

Example:

find . -name "*.mp3"| %s\n''' % (__file__, __file__)

import os
import pipes
import select
import shutil
import subprocess
import sys
import tempfile

## Define the window for sane bpm values. This may depend on genre of music. ##
BPM_WINDOW_MAX = 240
# Do not change this one
BPM_WINDOW_MIN = BPM_WINDOW_MAX/2
###############################################################################

def _get_bpm_from_soundstretch(output):
"""Gets bpm value from soundstretch output"""

output = output.split("\n")
for line in output:
if 'Detected BPM rate ' in line:
bpm = line[18:]
return float(bpm)
return None # Could not parse output

def fit_bpm_in_window(bpm_suggestion):
"""Double or halve a bpm suggestion until it fits inside the bpm window"""

if bpm_suggestion is not None:
while bpm_suggestion < (BPM_WINDOW_MIN):
bpm_suggestion = bpm_suggestion * 2
while bpm_suggestion > (BPM_WINDOW_MAX):
bpm_suggestion = bpm_suggestion / 2
return bpm_suggestion

def analyze_mp3(mp3filespec):
"""Uses lame and soundstretch to analyze an mp3 file for its bpm rate"""

# Make a temporary working directory for storing the wav file
# that soundstretch should analyze
workingdir = tempfile.mkdtemp()
wavfilespec = workingdir + "/tempwavfile.wav"

# Use lame to make a wav representation of the mp3 file to be analyzed
wav_command = 'lame --decode %s %s' % (mp3filespec, wavfilespec)
subprocess.call([wav_command], shell=True, stderr=open(os.devnull, 'w'))

# Call soundstretch to analyze the wav file
bpm_command = 'soundstretch %s -bpm' % wavfilespec
p = subprocess.Popen([bpm_command], shell=True,stdout=subprocess.PIPE)
output = p.communicate()[0]

# Delete temporary working directory and its contents
shutil.rmtree(workingdir)

bpm_suggestion = _get_bpm_from_soundstretch(output)

return fit_bpm_in_window(bpm_suggestion)

def process_input(mp3filespec):
bpm_suggestion = analyze_mp3(pipes.quote(mp3filespec))
if bpm_suggestion is None:
print "Unable to detect bpm for file %s" % mp3filespec
else:
print "BPM rate for %s is estimated to be %s" % (mp3filespec, bpm_suggestion)

if __name__ == "__main__":
argv = sys.argv[1:]
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): # input is piped to program
mp3filespecs = sys.stdin.readlines()
for mp3filespec in mp3filespecs:
process_input(mp3filespec.rstrip('\n'))
elif len(argv) < 1: # No pipe and no input file, print help text and exit
print DOC
sys.exit()
else: # Input file present
mp3filespec = os.path.abspath(argv[0])
process_input(mp3filespec)

It needs soundstretch and lame to be installed.


Hur ofta borde man kolla hur börserna gått?

published Aug 18, 2010 09:44   by admin ( last modified Aug 18, 2010 09:44 )

Varför skriver man om världbörsernas upp- eller nedgång som en nyhet snart varje dag på framsidan på de stora nyhetssajterna? Vore det inte bättre att ha en månatlig sammanfattning?

Eftersom börserna svänger varje dag, varje minut och varje sekund, så står det ju fritt att välja tidsintervall man vill rapportera. Att göra det till en daglig nyhet tillskriver dagsläget ett nyhetsvärde som det inte har. Om trenden är en fyraprocentig nedgång över en månad så är en tvåprocentig uppgång någonstans i mitten inte så intressant. Jag antar att man ändå rapporterar en snabb tvåprocentig uppgång för att vara först, eller i all fall inte sist, med nyheten.

Att rapportera det dagliga läget måste dock vara väldigt billigt att göra: Det är bara att läsa av förändringar under dagen, och lägga till ett känsloladdat ord: "Turbulens", "Uppgång", "Nedgång", "Oro". Det är inget fel att använda känsloladdade ord i sig för att beskriva en börs, känslor är i en funktion det vi använder för att koordinera en flock, men det blir lite mycket känslor upp och ner om man rapportera om det varje dag.

Nicholas Nassim Taleb rekommenderar i sin bok "The Black Swan" att man inte kollar börsen för ofta, just för att slippa den känslomässiga turbulensen kring rörelser som i det större perspektivet kan betraktas som slumpmässiga.

De ledande börserna i Asien steg under onsdagens handel i linje med börserna i New York. Undantaget var de kinesiska börserna.



Läs mer: Mest upp på Asiens börser - DN.se


Editing services on Ubuntu 10.4

published Aug 18, 2010 06:08   by admin ( last modified Aug 18, 2010 06:08 )

 

Summary: Install rcconf from the usual repositories and use the space bar to toggle services on or off.

 

On CentOS 5 there is a GUI for turning on and off services. on Ubuntu 10.4 I could not find anything similar installed. So I decided to go the the Ubuntu synaptic package installer and have a look around. I found bum and rcconf that both claim to have GUIs for editing runlevels, which seems close enough to what I needed.

Bum

Bum did not work. Bummer. It exited with the message: "cannot open display 1.0". I am testing through VNC to a daemonized tightVNC server, and maybe bum cannot handle that. Unrelated to this I had the same error message with an X utility called xcutsel, so maybe it is tightVNC doing something wrong, I do not know.

rccconf

rcconf worked, but it took me a while to figure out what key on the keyboard toggles a service on and off. It is the spacebar.

Screenshot of rcconf. No mouse support, use pgUp and pgDown to scroll (or arrows), space bar to toggle and tab to switch to next UI element (i.e. the OK button, and then the Cancel button).


How to put an independent VNC server on Ubuntu 10.4

published Aug 15, 2010 06:59   by admin ( last modified Aug 15, 2010 06:59 )

...and fix the drag and drop problem. The following guide worked for putting an independent VNC server running on Ubuntu 10.4. With independent I mean that is separate from the desktop session running on the computer that is connected to the physical monitor. Instead the below guide will give you an "always on" desktop session independent of what you see on the monitor. One advantage compared to desktop sharing is that you can adjust the screen resolution to fit comfortably in a window on the controlling computer. Another advantage is that you can run the vnc session as another user than who is currently using the computer, or as the same user but with a different desktop.

 

This guide intends to show you how to build a headless server with tightvnc, such that you can remotely access the server’s gui using any vnc client. I’m still working on it, so if you have any comments or questions, please feel free to let me know.

  Ubuntu TightVNC Server - Dave Lachapelle

 

I followed the instructions to a "T" and it worked. Lachapelle recommends you remove the geometry option for Ubuntu 10.4, but it worked fine on my 10.4 computer.

After install i ran the script as "/etc/init.d/vncserver start" once. Xtightvncserver then prompted me to define passwords for accessing the new desktop, one password for full control, and one for viewing only.

You could extend the script to start several independent vnc sessions, to make the server work as a multiple desktop provider. That is how I use my CentOS 5 server (which is soon is going to be Ubuntified).

 

Update 2010-08-16, 2010-08-20, 2011-01-28

Currently drag and drop is broken in Gnome on Ubuntu 10.4 when you use tightvnc. Everything else seems to work though, and in most cases you can get around drag and drop by e.g. instead do a cut and paste. However for e.g. reordering playlists in Rhythmbox there is no workaround. Actually I spend a bit of time trying to figure out why the heck drag and drop did not work, when everything else worked. A bug in Gnome itself was not the first thing that sprang to mind. According to some sources on the Internet this bug affects all remote desktop sessions, but I have noticed that x11vnc works, although that is strictly for sharing an existing screen session.

See here for bug report and workaround for the drag and drop issue:

https://bugs.launchpad.net/ubuntu/+source/gtk+2.0/+bug/587856

Basically, you need to slightly downgrade a couple of Gnome packages. I did this and drag and drop started working again. There is now what seems to be identification of the offending code upstream in the Gnome bug tracker, but it is not clear when a fix will find its way into Ubuntu.

The downgrade at the link above seems to be volatile. When you do other installs on your system, and possibly just straight updates, the downgraded Gnome packages will be replaced. I have currently done like this to fixate ("pin") the downgrade:

nano -w /etc/apt/preferences.d/pinGnomeForRemoteAccess

and in that file I put:

Package: libgtk2.0-0
Pin: version 2.20.0-0ubuntu4
Pin-Priority: 1001

Package: libgtk2.0-bin
Pin: version 2.20.0-0ubuntu4
Pin-Priority: 1001

Package: libgail18
Pin: version 2.20.0-0ubuntu4
Pin-Priority: 1001

Package: libgail-common
Pin: version 2.20.0-0ubuntu4
Pin-Priority: 1001

Package: gtk2-engines-pixbuf
Pin: version 2.20.0-0ubuntu4
Pin-Priority: 1001

2010-10-03: The pinning works! It's been in place now for several weeks, and drag and drop is still working.

2010-08-26: Added version keyword to pin file

 


Link - How to make Rhythmbox et al treat a storage as a player

published Aug 14, 2010 12:27   by admin ( last modified Aug 14, 2010 12:27 )

(See also Firefly DAAP server, first impressions.)

Rhythmbox will not initially identify the device. To get rhythmbox to see the device, you simply place a text file into the root directory of the player named '.is_audio_player' (/media/Sansa View/.is_audio_player).

You can also tell rhythmbox where to store files it transfers to the device:

audio_folders=MUSIC/
folder_depth=2



Taken from: Sandisk Sansa View on Ubuntu Linux


Getting the code for Facebook's "Like" button

published Aug 12, 2010 02:13   by admin ( last modified Aug 12, 2010 02:13 )

Here is a link going directly to a page on Facebook with boiler plate code for making a Facebook "Like" button.

This evening I tried filling out a form on Facebook that should give me the code for a Facebook button to put on a page. Trying with different browsers I could not get it to output any code, the submit did not seem to work. Analyzing the submit button, it submits to a url that if you just access it directly (i.e. a GET without parameters) you get some boiler plate code where you easily can replace relevant parts. I guess the form submit button will start to work again, but if not accessing the taget url directly works somewhat.


"Classicists have continued their efforts to suppress Wittgenstein's arguments up to the present day, e.g. on Wikipedia."

published Aug 02, 2010 02:36   by admin ( last modified Aug 02, 2010 02:36 )

Det här är lite utanför mitt område, men om jag förstår andemeningen så är det att logik bör betraktas som en slags ingenjörskonst, och att den måste användas på ett liknande sätt som ingenjörskunskap, dvs inom rimliga ramar, och att man får acceptera motsägelser. Författaren föreslår något som han kallar "Consequently Direct Logic", som ska göra logikområdet mer relevant för t ex programvaruutveckling.

Classicists have continued their efforts to suppress Wittgenstein's arguments up to the present day, e.g. on Wikipedia.



Läs mer: Incompleteness Theorems - a knol by Carl Hewitt (see http://carlhewitt.info)


The Guardian om Sverige, Göran Lindberg och våra deckarförfattare

published Aug 01, 2010 11:02   by admin ( last modified Aug 01, 2010 11:02 )

Deckarförfattarna Henning Mankell, Stieg Larsson och andra har visat en bild av Sverige som är annorlunda än den idealiserade bild som ofta finns i t ex Storbritannien. Efter domen mot förre länspolischefen Göran Lindberg så undrar The Guardian's Andrew Anthony om det kanske ligger något i denna nya bild:

Anthony skriver en lång och intressant artikel som redovisar synpunkter från olika svenska opinionsledare. Han avslutar med en undran om det kan vara så att svenskarna är överpragmatiska, att vi identifierar problem som ska lösas med utbildning, utan att ta in den större bilden av vad det är man försöker lösa.

Läs mer: Göran Lindberg and Sweden's dark side | feature | World news | The Observer


When clicking in folder_contents leads to downloads (Plone)

published Aug 01, 2010 02:58   by admin ( last modified Aug 01, 2010 02:58 )

Summary: Add the portal_type on a line in the property "typesUseViewActionInListings" in the site_properties property sheet in portal_properties, and you will get the view instead

 

Having created my own MP3 content type in Plone, based on the File content type, I noticed the strange behavior that clicking on any MP3 in a folder contents listing would lead to a download of the MP3. Awkward.

Trying out the standard File content type, this does not happen; you get to the view of the content item instead.

So what's the difference? With File, there is "/view" appended to the url of each content item in the folder contents listing, with the MP3 file there is not. Time to look through the view configurations in XML for the two content types. There were differences, specifically File tacks on "/view" to the specification of "View". Changing this in MP3 made no difference.

Ok, time to take on the diving suit and chase down the code for the folder_contents view. Thankfully it was reasonably easy to find, in

./plone/app/content/browser/foldercontents.py

The view decides to tack on "/view" if the content type of the item to list is in this list:

use_view_action = site_properties.getProperty('typesUseViewActionInListings', ())

So, I added "MP3" on a line in the property "typesUseViewActionInListings" in the site_properties property sheet in portal_properties. And it worked. Not so obvious.


Checking what would be updated before making an svn up

published Jul 30, 2010 11:59   by admin ( last modified Jul 30, 2010 11:59 )

If you have a working copy in subversion that is older than the latest checkin, you may want to check the differences you would get if you made an svn up, without actually doing an svn up.

svn diff --revision HEAD

...will give you that.


--revision N The client compares TARGET@N against working copy.


Läs mer: svn diff


Link - On software project development estimates

published Jul 30, 2010 06:05   by admin ( last modified Jul 30, 2010 06:05 )

 

How many estimates were accurate?



Läs mer: 10 Reasons Why Software Project Estimates Fail


Video editors on Linux

published Jul 28, 2010 06:23   by admin ( last modified Jul 28, 2010 06:23 )

Here is a list of Video editors available on Linux. I have tried them all, save Lombard. Will try to summarize more experiences at a later time.   

My use case was extracting individual three second long moves from salsa dance performances. I tried three Linux based video editors for this: AviDemux LiVES, Cinelerra and Pitivi. The best by far for this particular application were AviDemux and  LiVES.

Updated 2012-02-23 with AviDemux.

  • AviDemux, with preprocessing in ffmpeg is the best for my uses. Clean interface and fast. You must preprocess with e.g. ffmpeg for scrubbing to work if you have keyframes in your video. Read more here on how to do that.
  • Cinelerra (Cinelerra for Grandma)
  • LiVES The second best one I have found for extracting short video clips from a video.
  • Kdenlive Has a lot of filters you can apply to video. Unsure of how cutting works.
  • Pitivi
  • Lombard Very recent contribution, supports only basic editing at this point in time, according to web site.

 

 


CLI ID3 editors - tagging a tree with find and xargs

published Jul 27, 2010 11:39   by admin ( last modified Jul 27, 2010 11:39 )

 

Summary: id3tool, id3v2 and eyeD3  worked fine with find and xargs, see below for the specific syntax for each.
I could not get id3ren to work. All taken from Ubuntu's repository for 9.10 Karmic Koala.

 

I needed to tag a whole directory tree of MP3 files with the genre tag "Salsa". This blog post is about whether the above mentioned command line tagging tools worked as expected with find and xargs to batch add a tag. Results were checked with the EasyTag editor.

Now, a standard way in the shell on unixish systems to dig up files and pipe them to a command is something like this:

find -name "*.mp3" -print0 |xargs -0 tag-command --flags
  • "find" finds all items and prints them out for you,
  • the "-name "*.mp3" limits it to items ending in mp3,
  • the "-print0" prints them in such a way that the next command in the chain does not get confused by any weird characters in the file names, achieved by putting a NULL character in between them. MP3 files often have weird file names. Do note that the -print0 command needs to come after the parameters to find!

"xargs" then executes tag-command for each item that find finds. The "-0" flag is to unpack the NULL delimited items xargs gets from find.

 

Here are the results:

find -name "*.mp3" -print0|xargs -0 id3tool -G Salsa

(no output generated on command line) id3tool worked like a charm.

find -name "*.mp3" -print0|xargs -0 id3ren -genre Salsa
*** No ID3 tag found in ./music - music.mp3

===> Entering new tag info for ./music - music.mp3:

id3ren just hanged there for at least ten minutes, at which point it was terminated by me. I copied the mp3 file it stopped on to another directory and ran id3tool on it as above, and it worked fine. Finally I also ran it on files that had already been tagged; it still reported "No ID3 tag found", and hanged.

find -name "*.mp3" -print0|xargs -0 id3v2 -g 143

(no output generated on command line) id3v2 worked like a charm.

 

eyeD3 also worked like a charm:

find -name "*.mp3" -print0|xargs -0 eyeD3 -G Salsa

a file.mp3 [ 7.85 MB ]
-------------------------------------------------------------------------------
Time: 04:51 MPEG1, Layer III [ ~225 kb/s @ 44100 Hz - Joint stereo ]
-------------------------------------------------------------------------------
No ID3 v1.x/v2.x tag found!
Setting track genre: Salsa
Writing tag...
ID3 v2.4:
title: artist:
album: year: None
track: genre: Salsa (id 143)

...and eyeD3 just chugged on like that, adding tags.

One difference between eyeD3 and the other working editors was that they stopped when being fed a faulty file path, while eyeD3 continued with the next path.

Update 2010-09-22

This blog posting has been completely rewritten after "jax" commented that the find command used had been wrong. I had treated "-print0" as just another flag to the find command. It is not, in fact when find encounters a "-print" or "-print0" command it prints right then and there, and any flags coming thereafter are ignored (unless another -print or print0 command follows them). This meant that my impression was that none of the editors worked, when in fact all but one did work.

I first tested like this:

find -print0 -name "*.mp3"|xargs -0 tag-command --flags

But that is wrong!

This is the way it should be:

find -name "*.mp3" -print0 |xargs -0 tag-command --flags

Thanks to jax for pointing this out.


Link - Wrapping mplayer in python

published Jul 27, 2010 01:47   by admin ( last modified Jul 27, 2010 01:47 )

Update 2011-jan-09: I have now got around to it, but have had problems using the below code examples on Linux. They seem to be targeted to Windows. I have instead started using the python-mplayer library with gtk. It works fine, with the exception that I could not get sound through my USB headset when using PulseAudio. Solution was to switch to a sound card.

 

Sometimes I'd just like to make a video player/editor with the functions I need and nothing else: Slow motion, select a short piece and save it. If I ever get around to that, this may be a good starting point:

This article will just focus on creating a really simple Media Player that you can play movies with.



Läs mer: wxPython: Creating a Simple Media Player « The Mouse Vs. The Python


Yes please mama

published Jul 25, 2010 06:43   by admin ( last modified Jul 25, 2010 06:43 )

I asked a friend a question yesterday, about how to remember rhythms. This afaik is for samba: "Yes please mama, I want cake, mama". I guess there are many rhythms in samba, though,

One of our patterns with a phrase to help you remember it: "Yes please mama, I want cake, mama!" When you play it, "mama" is played with open notes, all the rest are closed. See, easy!



Samba Ottawa Home Page


Mp3cat - gets only the data part of the mp3

published Jul 23, 2010 03:15   by admin ( last modified Jul 23, 2010 03:15 )

One's mp3 files have a tendency to get duplicated over different computers, hard disks and portable players. Some of the tags may also get edited on some copies but not others. Since tags are stored in the file there is no easy way to detect which mp3s are identical music-wise by just hashing the file with md5, sha-1 or other hashing algorithm. Instead you need to run the hashing on only the data part.

I have not found any modules for python that does this. I have found one python module which will report the byte offset of where the data starts, but I guess that only works if the meta data are in the start of the file. The only command line tool I have found that can extract the data part is mp3cat:

This is the mp3cat home page. Download the latest release tarball mp3cat-0.4.tar.gz or (better) check out the current version from my subversion repository: http://svn.tomclegg.net/repos/trunk/mp3cat


My intial evaluation is favorable, i.e. an md5 hash of two files with different meta data but same music data gets the same hash value. Found mp3cat via this blog post:

The author wants the same thing I am searching for–the ability to generate a checksum of the audio stream and store it in the file header as a tag. Furthermore, he mentions his use of mp3cat! I pulled down a copy of mp3cat and compiled it on my archive box. Then the fun began


 Tim's Mind Organized » Checksum mp3 audio frames (the data and not the headers)

 There has at least existed one java program that does the data extraction and hashing in one fell swoop. It is mentioned in this discussion, but the download link does not seem to work.

 

Update 2010-07-25

I now looked into the CPAN archive, and as usual there is a Perl module, Audio::Digest::MP3 that does exactly what you want :-)

 

Audio::Digest::MP3 - Get a message digest for the audio stream out of an MP3 file (skipping ID3 tags
Audio::Digest::MP3 - search.cpan.org

Untested by me so far.