sha1sum rewritten in python using openssl
I like how I can use the sha1sum tool on my Linux boxes to create a file with checksums of a collection of files and then use the tool again to verify the files against the checksums.
I've been missing that functionality on my Mac, so I wrote a small wrapper to the openssl command that provide the same basic functionality using Python. Python is really handy when it comes to writing small scripts like that does some string handling and calls other programs and since the basic checksumming functionality already is available in the openssl package it simple, short and neat.
As usual, feel free to use this any way you want.
#!/usr/bin/python import subprocess import sys def checksum_file(filename): sp = subprocess.Popen(["/usr/bin/openssl", "sha1", filename], stdout=subprocess.PIPE) retval = sp.communicate()[0] return retval[retval.find("= ") + 2:-1] def verify(checksumfile): f = open(checksumfile, "r") for line in f: line = line[:-1] (sha1, fn) = line.split(" ") calc = checksum_file(fn) if calc != sha1: print "%s: FAILED" % fn sys.exit(1) else: print "%s: OK" % fn def usage(): print "Usage: sha1sum [-c CHECKSUM_FILE] [FILE]..." sys.exit(1) if __name__ == '__main__': if len(sys.argv) == 1: usage() if sys.argv[1] == '-c': if len(sys.argv) != 3: usage() verify(sys.argv[2]) else: for f in sys.argv[1:]: print "%s %s" % (checksum_file(f), f)Filed under Programming, System administration, Uncategorized | Comment (0)
Mina argument för Piratpartiet i Europaparlamentet
The election to the european parliament is coming up and this post is the first in what hopefully will be a series written in Swedish making the case for voting for the pirate party. For an english version of the basic argument, please see this post.
Snart är det europaparlamentsval. I detta inlägg har jag för avsikt att gå igenom några för- och nackdelar som spelat in när jag gjort mitt val att gå med i piratpartiet och min plan att rösta på dem den 7 juni.
Piratpartiet är ett politiskt parti som arbetar för en reformerad upphovsrätt och att motverka utvecklingen mot ett övervakningssamhälle. Partiet tar inte ställning i frågor som är utanför partiets uttalade områden, och har för avsikt att genom samarbete med andra politiska partier och konstellationer främja den egna politiken.
Den främsta invändningen mot att rösta på Piratpartiet för mig är att jag med en piratröst väljer representation som, om vi kommer så långt som till parlamentet, väljer att vara tyst i politiska frågor där jag personligen har starka åsikter. Jag skulle vilja avveckla jordbrukssubventionerna och stoppa Europaprlamentets flyttcirkus mellan Bryssel och Strasbourg. Än värre, med lite otur kan Piratpartiets uttalade strategi, att gå med i och rösta med den parlamentsgrupp som ger bäst gehör för partiets frågor, innebära att min representant röstar på ett sätt som är emot min övertygelse i vissa frågor.
Jag tror dock att denna nackdel för det första i praktiken inte är så stor som den verkar och för det andra mer än väl uppvägs av det fördelar jag ser med att rösta pirat:
Piratpartiet kan sannolikt driva frågorna om rättssäkerhet och personlig integritet mer effektivt än andra partier med liknande åsikter i dessa frågor. För en EU-parlamentariker finns det nämligen alltid för många ärenden och viktiga frågor, så även om jag skulle lägga min röst på en kandidat från exempelvis miljöpartiet som delar mina ståndpunkter om detta så är sannolikheten stor att denne kommer att ägna mandatperioden åt saker som jag inte alls tycker är så viktiga. Dessutom är frågor om till exempel mjukvarupatent och reglering av internet så svåra att det krävs spetskompetens för att alls kunna arbeta effektivt med detta. Det är helt enkelt otroligt lätt för den parlamentariker som inte är mycket påläst i en fråga att bli bortfintad och därmed ineffektiv, även om grundåsikterna är de rätta. Här har Piratpartiets toppkandidat Christian Engström järnkoll.
En röst på Piratpartiet är alltså den mest effektiva röst som går att lägga mot övervakningssamhället och för en ny syn på upphovsrätt i Europaparlamentet. Dessutom är en plats i Europaparlamentet en chans för Piratpartiet att visa vad man går för när det gäller öppenhet i det politiska arbetet, effektivitet att få fram sina frågor och en möjlighet till medieutrymme som ger bättre chanser att nå det stora målet, en plats i Sveriges riksdag.
Filed under Politics, Uncategorized | Comment (1)The standalone gas pump
Imagine that someone invented a standalone gas pump. One that didn't need to be connected to tanks of gasoline at a gas station or even the power grid, but could be used to fill up the tank of your car all by itself. The pump created gasoline from the carbon dioxide in the air around it and didn't produce any waste. Since the pump doesn't require any raw materials and was cheap to produce you could use it practically for free.
Does it sound like a brilliant machine, and a solution to many of our world's problems? I think so, but on the other hand I'm pessimistic about how such a machine would be received by our society.
Why? Because when it comes to information such a machine has been invented, and some part of society seems to be at war with it. That machine is the idea of pee r to peer file sharing on the internet. Digital information can be copied and distributed to millions of users practically for free. I can have access to enormous amounts of high quality music and other media all for just the cost of my computer and my internet connection. The act of accessing that content doesn't stop others from getting it as well. The orignal creator of the content gets to keep it as well and do what she wishes with it.
Yet some multinational media corporations, not unlike the oil companies that make money off gasoline sales, claim that their revenue streams are hurt by this new invention and that they need compensation. Today the Pirate Bay trial began here in Sweden, where the prosecutor together with some lawyers representing US based media companies will try to put four guys in jail for running a website that lets internet users share and download digital content.
If you are making up your mind about if they should be convicted or not, think of them as the entrepreneurs responsible for trying to take the standalone gasoline pump from the inventor out to the world market. Sure, their actions probably hurt the companies that has made obscene amounts of money off selling small plastic discs containing music and movies in the last decade. Just like the standalone gas pump would definitely decrease the revenue of large oil companies and put many, many people working in the oil industry in unemployment.
But when you look at the bigger picture, a world where anyone and everyone can have access to a large part of the media that is produced, that is something really valuable for the whole society, and as a whole that is more valuable than the dramatic downside of media companies not being able to make as much money as they used to.
Would it be reasonable to call using the standalone gas pump stealing? One could argue that you would be stealing the money that Exxon would otherwise get from filling up your tank. If you would want to make a more emotional argument you could argue that , and that a small fraction the money you stole from Exxon would go to Saudi Arabia and that a small fraction of that would go to poor defenseless children crying in an orphanage.
The core of my argument is that no one should be guaranteed that their current business model should be protected from the effects of new technology the way that the media companies is trying to do now. Manufacturers of mechanical calculators were put out of business when the electronic calculators came along. It was painful for the companies and their employees, but for society as a whole we're better off with cheap, smart electronic calculators than with a healthy industry creating expensive, dumb mechanical calculators. This is true when it comes to file sharing on the internet and it would be true if the day would come when someone invents the standalone gas pump. Lets recognise this and change our laws accordingly.
Filed under Uncategorized | Comments (5)Disruptive technology and the future of media
A few months back I got an invite to Spotify, a streaming music service available in Sweden and some other markets, that I have used increasingly since. The basic service is free for invited users and once every ten songs or so they play one or two 30 second commercials. For a fee of 99SEK/month (about $12) you get the service free from commericals and they have a thousands and thousands of albums to choose from.
I must say that this service is brilliant in several ways. When I first started to use it I was happy to discover that the audio quality was totally acceptable and that large parts of my favourite music was available. Now, a bit later, I find myself changing my music listening behaviour due to the nature of the service. You can click on an artist name to see other music by that artist, and you can click on an album name to see what other songs are on that album. This means that you can surf from artist to artist on compilation albums and listen to find new music that you like. This is something that prior to Spotify you could only do using peer to peer file sharing and that was quite a bit less convenient than this solution, putting all legal issues aside for a moment.
So, this way I can search for the title of a film I saw a while back that I liked, Lars and the Real Girl, click on Nat King Cole, find out that an artist named Bebel Gilberto has remixed him. A bit down in the list of albums from that artist I find a collection album named 20 ways to float through walls which sounds kind of cool. One of the artists, Snooze, catches my attention. It turns out I like several songs from the album Goingmobile. All this in a matter of seconds, guided by interesting group names, song names and album covers. Doing the same thing using any other technology that I know of would have taken hours.
One of the most encouraging things about this is that it shows that once the media industry moves past just trying to stop unstoppable file sharing and allow creative people to build something better then they can win their customers back.
I have feeling that the attitude change needed before Spotify could spring into existence would not have happened without the pressure from thepiratebay.org and others.
Filed under Uncategorized | Comment (0)Cause and effect?
I've been doing some reading lately and a topic that has come up more than once is that of false causalities. It seems to be human nature to construct causalities that fit our worldview when in fact the only thing that can be objectively demonstrated is co-variation. We can see this when it comes to non-heterosexuality and the relative occurrence of mental health problems. Some people seems to have their interpretation of the fact that some surveys find depression to be more common among non-heterosexuals than in the general population as a direct cause and effect relation. You're depressed because being gay makes you so! Well, I'm not sure about that, in fact I'm sort of convinced that is not the case. But how do you illustrate that interpreting co-variance as cause and effect is often problematic? With colorful diagrams of course!
Alexander sent me a link to this wonderful piece of graphics, from climate sceptic:
In the comments I found the only relevant question to ask: should we struggle to produce more oil, so the quality of the music will increase, or should we attempt to draft better composers and musicians into rock 'n' roll, so we can have more oil? I'm so confused! At least it made me smile.
Filed under Uncategorized | Comments (2)Falling through the sky
The reason that I haven't written here in a while is that I have been busy having my 30th birthday, with associated celebrations. It has been great fun. Thanks to my amazingly thoughtful fiance Alexander I got a gift certificate for a tandem skydive that I had the great pleasure to redeem today. What a rush! Thanks to a whole bunch of friends I got a photograph joining me in the jump as well. Skydiving makes even a geek like me feel like a rock star. Amazing. I got a whole album of pictures.
I predict McCain
I've been following the US presidential election closely for more than half a year now, and when I got the message that Obama chooses Joe Biden as his vice president I changed my mind about who I think is going to win this election. My adjusted prediction is that John McCain is going to win.
I think that he can snatch a close victory in november because now Obama has basically invalidated his own best arguments. The Obama campaign likes to paint the picture of McCain as problematically old and part of the washington establishment, but now they have proven that being old and part of the establishment is not a problem when choosing a vice president candidate.
Also, I don't think that you should underestimate Obama's consistent opposition against the war in Iraq as giving him the edge that he needed to defeat Hillary in the primaries. Now that he has chosen a running mate that voted yes to the war, that argument is weakened as well.
Part of me thinks that this is kind of sad. I really liked the idea of an american president that was a brilliant public speaker. I also think that Obama is the smarter guy and being intelligent is one of the most important assets a president can have. On the other hand, with McCain we get a president that is pro free trade, which is a really good thing, especially for those of us living in Europe.
Filed under Uncategorized | Comment (0)Programming for fun and profit
I work as a programmer. Most days it is great, because I get to spend my days writing software and even get payed to do it. However, when writing commercial software unfortunately the most elegant solution to a particular problem is rarely the one that is reasonable to spend time on. Almost all the time, "good enough" is the goal.
As an example, a new functionality that we have just added to voxbiblia.com, the website i spend most of my days working on is the ability to create albums out of the audio Bibles available from our site. An album is a collection of Bible verses read by one of our voices. From a more technical perspective a collection is a group of MP3 audio files. We want those MP3 files to be easy to download and once downloaded we want them to have metadata that makes them show up in your MP3 player. Do achieve this we want to be able to generate metadata information on the fly and we also want to put a whole lot of MP3 files with metadata into a zipfile so that i can be available as one download. We have code to to all this (The ID3 metadata generator will be released as Free Software some day, I promise) and it works as expected but one aspect of the zipfile generation code is not elegant as I would want it to be.
The current solution needs to read each MP3 file into memory to be able to calculate it's CRC-32 checksum before it can write it to the zip datastream served to the user. Since our server is quite powerful it is not a problem to read a few MP3 files into memory at the same time, but the thought that it must be a more elegant and efficient way of doing it was spinning around in my head. Since there is absolutely no justification for finding this solution, the one we had was good enough, I had to put this problem on the shelf for some time.
However, vacation came and when I thought about what to do that would be really fun and recreational I thought about this problem and I decided to try to solve it. So I did, and it was great fun. I will blog about the specifics of this little project in a short while, but for now I'm just so glad that I solved the problem.

