Wednesday 24 December 2008

Philosophy of change

Recently I involuntary got involved in a religious debate (yes, again). My observation of how my counterpart argued became apparent pretty quickly. Change, is bad. Now, we should further define change in this particular context. Change, as in changes made to laid down principles or things considered to be facts.

If you become a part of a doctrine, a book that rigidly defines good and bad, your habits and your afterlife. You get the feeling of certainness, at least when it comes to these things. Certainness feels good, doesn't it? You can stop worrying about these specific issues, because they have been taken care of. This observation upon religion is not new, but what are the consequences?

Any change made to these principles or any element that might cause your principles to change is now causing you to feel less certain. Can god exist if we have evolved from microbes? Can my morale be justified if we are not created? Asking those questions hurt, I know, I have been there. You are faced with what seems to be two options, to abandon your principles and become a "devil", someone with no morale or certainty or to shut your eyes, perhaps even work against these "forces". For these "forces" must truly be "evil" if they tempt you to doubt? Even though they make no such claims.

But I see it in another light. I see change as good. My opponent brings up things such as Einstein proving that the ether is not a necessity. That it is indeed possible that science is wrong and that it _will_ change. I agree, I wholeheartedly agree that science will change and I think that most likely science is wrong. Wrong of course means not in perfect harmony with the physical world. Theories will change in accordance to future observations.

But my opponent and I don't agree upon change. I think that change is good, I don't think that the claims of science are rigid and forever true. Instead, they will change, but most likely for the better. You proved me wrong, thank you, thank you for allowing me to discard what was faulty and move on. To me, change is good, change is the very essence of living. I strive to pass something on, not what I learnt from those before me, but what I learnt, verified and tried to take further. This goes both regarding morale and knowledge. For how else can my children be wiser than me? I am the rope, humanity is the rope dancer.

Sunday 21 December 2008

Sorting all the mail

I am subscribed to numerous mailing lists, ranging from FreeBSD to Python. As a result, I get a couple of hundreds of mail every day. Most of my mail boxes, such as the one I got from my school can't withstand such a bombardment for very long. Within matter of days the inbox will be full.

My old solution was to use Thunderbird on my workstation to filter out all the mails into a directory structure on my disk. That way the mails were pulled from the server and stored at a place where storage space was plenty. It worked, but it was a bit ugly. As soon as the machine was turned off or my connection went down I would have my inbox filled until a got home and started the workstation again. Now, not being at home and not having a workstation things needed to change. But how?

GMail is kind of neat, and free. You get a couple of gigabytes of storage and Google gets to index your mail and give you relevant ads. The only thing that really bothers me is that GMail sometimes uses a different terminology which clashes with ordinary email terminology. You use "labels", which really are folders on the IMAP server (took me a couple of seconds to understand what it meant to "tag" an email and to "archive it"). Sure, GMail is to date _the_ best and most intuitive way to display mails, but it is a bit confusing at times. Would I make a similar user-interface definitely, there's a lot of thought put into it.

Anyway, on to the point. I unsubscribed my old email, signed up for a GMail account and subscribed my new email to about 75 lists. Then used the GMail UI to "label" all my incoming mails from the mailing lists, mails from Python/Dev are now labeled as python/dev and are thus stored in the //INBOX/python/dev directory. It's tedious, I got there. I then added my GMail account to my mail client of choice (Thunderbird) and I could read them just like in the old days, but being accessible from any computer and not having to worry about filling my inbox.

Now, everything could have been just fine. But Thunderbird was not playing along. As a default Thunderbird won't check other boxes than the inbox. This is most likely due to the fact that it takes quite some time to check all the directories. But I just won't find it comfortable to click every single folder every time I want to check for mail. You can force Thunderbird to check every single one of them, but doing so requires you to edit the properties for all your directories (no, you can't change more than one at the time). This, is tedious, _very_ tedious.

To make matters worse, for my ordinary inbox I sort mails by date. This is really good for simple conversations but for a mailing list like FreeBSD/Current, it just becomes a huge mess. For these cases you want to sort by threads, as in, a conversation becomes a tree, the first mail is the root, all mails are leaves and an edge is established to the mail which the mail replied to. This also requires you to change the properties on a per-directory basis. I have three operating systems and a workstation at work. I don't want to reboot to check my mail, so setting it up would force me to make about 200 clicks per client. This is not acceptable, so I turned to Google.

I found the following. There is a configuration editor and there is a way to achieve this without grinding your teeth for all too long.

Check all IMAP folders for new mail
http://www.mozilla.org/support/thunderbird/tips#beh_downloadstartup

Sort order for mail/news not configurable by default
https://bugzilla.mozilla.org/show_bug.cgi?id=86845#c74

Just remember that you need to delete the old directories information files in order to rebuild them with the new defaults (in my case, threaded sorting). Why not use a one-liner? Remember to shut down Thunderbird before applying it and then start Thunderbirds afterwards and you are all done.

find ${PATH_TO_GMAIL_INBOX} -name '*.msf' | xargs rm

I hope you enjoy the "easier way to do it" (tm) as much as I did.

SSSB and automation

Recently I began reading up a bit on this whole web thing (yes, I lost my interest in coding HTML and web pages back in grade school). Things have changed and I better learn a bit since it will be beneficial for my work on my thesis. I wanted to try out authentication and HTML forms. Here's the story.

SSSB is a company that rents out flats to students in Stockholm. Back in the good old days (see 2005) you registered and for every day you got a day in line. These days could be traded in for a flat when you needed one, the more days, the better the flat. But, those things changed, the rules of the game are basically the same but you need to log in now and then to show that you are active enough. This of course, is tedious, most other non-student flat renting companies in Stockholm either don't bother or charge a fee. Already back in 2005 this annoyed me a bit but now being in the US and all it's a gun to my head. If I forget I will not have anywhere to live when I get back, or worse, I may loose three years of days. This seemed like an excellent task for a small hack.

The script I created has been tested a bit, but as always, use it at your own risk and take into consideration any moral implications. I will most likely not deploy it, but at least it might prove useful to someone.


#!/usr/bin/env python

'''
Author: Pontus Stenetorp
Version: $Id: sssb.py,v 1.2 2008/12/21 08:07:04 ninjin Exp $

Simple script to keep logging on the SSSB website to keep your days in line
for a flat in Stockholm. Meant to be executed by cron now and then.

This does not violate the agreement on sssb.se but the morality of automating
this is somewhat questionable. *sigh* I remember the good old days before this
log in every 'n' days silliness.
'''

import os
import random
import sys
import time
import urllib
import urllib2

### Constants
## User settings
USERNAME = '1234567890'
PASSWORD = '1234'

# The maximum amount of days to wait between logins, this value should be
# lower than the actual required amount of days (90)
WAIT_MAX = 90/2

# The minimum amount of days to wait between logins, this is to not log in
# all too often
WAIT_MIN = 14

# Faking is _not_ nice, but it is sometimes the only option
FAKE_USERAGENT = True

# If you want to fake, you may choose from the list below and give the index
# here. If set to negative the script will choose one at random and note it
# in the data file for future logins.
FAKE_USERAGENT_INDEX = -1

## Web page specifics
SSSB_URL = 'http://www.sssb.se/index.php?page=login'
VALUES = {'m6input_username': USERNAME, 'm6input_password': PASSWORD,
'mact': 'FrontEndUsers,m6,do_login,1', 'm6returnid': '794',
'page': '794'}

## Script internals
DATA_FILE_PATH = os.path.expanduser('~/.sssb_data')

# Look for this to confirm a successful login
LOGGED_IN_MATCH = 'Du %sr inloggad som:' % ''.join(['&', 'auml;'])

SECONDS_PER_DAY = 60 * 60 * 24

# If you are honest you will show that you are actually running a script
REAL_USERAGENT = 'SSSB login Python script 1.0'

# Thank you http://www.zytrax.com/tech/web/browser_ids.htm for the user-agents
# A mix of user agents to choose from, ranging from MSIE to Opera on several
# operating systems.
FAKE_USERAGENTS = [
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; SLCC1; ' +
'.NET CLR 2.0.50727; .NET CLR 3.0.04506; Media Center PC 5.0; .NET ' +
'CLR 1.1.4322)',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SU 3.1; SLCC1; ' +
'.NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 1.1.4322; Tablet ' +
'PC 2.0; .NET CLR 3.5.21022)',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8pre) ' +
'Gecko/20071019 Firefox/2.0.0.8 Navigator/9.0.0.1',
'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) ' +
'Gecko/20050519 Netscape/8.0.1',
'Opera/9.60 (X11; Linux i686; U; en) Presto/2.1.1, Opera/9.02 ' +
'(Windows NT 5.0; U; en)',
'Mozilla/5.0 (Windows NT 5.1; U; en) Opera 8.00',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 ' +
'(KHTML, like Gecko) Version/3.1.2 Safari/525.21']
###

def main(argv=None):

def read_data_file():
data_file = open(DATA_FILE_PATH, 'r')
last_login, next_login, user_agent = [line.strip() for line
in data_file]
data_file.close()
return int(last_login), int(next_login), user_agent

def write_data_file(last_login, next_login, user_agent):
if os.path.isfile(DATA_FILE_PATH):
os.remove(DATA_FILE_PATH)
data_file = open(DATA_FILE_PATH, 'w')
data_file.write(str(last_login) + '\n')
data_file.write(str(next_login) + '\n')
data_file.write(user_agent + '\n')
data_file.close()
return

if not os.path.isfile(DATA_FILE_PATH):
if not FAKE_USERAGENT:
user_agent = REAL_USERAGENT
elif FAKE_USERAGENT_INDEX < user_agent =" random.choice(FAKE_USERAGENTS)" user_agent =" FAKE_USERAGENTS[FAKE_USERAGENT_INDEX]" next_login =" 0," user_agent =" read_data_file()" current_time =" int(time.time())">= next_login:
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
data = urllib.urlencode(VALUES)
request = urllib2.Request(SSSB_URL, data)
request.add_header('User-agent', user_agent)
response = opener.open(request)

logged_in_line = [line for line in response if
LOGGED_IN_MATCH in line]

if not logged_in_line:
print 'FATAL: Log-in failed'
return -1

next_login = random.randint(
current_time + WAIT_MIN * SECONDS_PER_DAY,
current_time + WAIT_MAX * SECONDS_PER_DAY)
last_login = current_time
write_data_file(last_login, next_login, user_agent)
return 0

if __name__ == '__main__':

sys.exit(main(argv=sys.argv))



At line #53 you may notice a strange ''.join(), Blogger finds it a good idea to translate my escaped Swedish characters. This is a remedy, so enjoy the special Blogger version which is slightly uglier than my own version.

EDIT:
Blogger is really _terrible_ at displaying code, one almost weeps when you take a look at it. All the 80 width formatting killed by static width. *sigh* Paste it into an editor and take it away from this awful place.

Saturday 21 June 2008

P990i USB issues

Recently I got a new cell phone, my old one being 9 years old it was quite a change. I wanted one that played music, had WiFi (since I spend most of my time at school and then I could check things up without using my laptop) etc. I found a used Sony Ericsson P990i for 1000 SEK which was quite reasonable.

It all worked fine until I transfered some music to it and the sound was all choppy and made my ears bleed. I phoned SE and they said that they never had heard of such an error. I was puzzled, what could cause this?

I tried analyzing the encoding of the files, nothing strange about it. But when I transfered a song that I considered to be more likely not to contain errors it played flawlessly. How come? It was encoded in the same way. I even checked using SE encoding and transfer tool.

Then I got it, when I played the song transfered from the phone to the computer it was still choppy. What must have happened is that SE tries to make the P990i act like a USB utility but somehow does not do it accurately (I find this likely, the phone needs a bundle of drivers), or that FreeBSD has some sort of bug in the USB handling (I find this unlikely). The first file was transfered using FreeBSD, ending up corrupted, and the second one using Windows, working just fine. This is not a pleasant surprise but now I can finally use my SE head phones.

Wednesday 5 March 2008

The curse of being an amateur photographer

The biggest curse of being an amateur photographer, is that you never ever get a picture of yourself. I still don't have a picture of myself where I don't look like a complete fool.


Last Tuesday I brought my camera to school (to take photos for KTH), a friend snatched it and tried it out and took a picture of an unsuspecting me. It's alright I suppose, but the focus is all off and I look far too serious. If it was me, I'd take another set but... that's impossible. Thanks Auno for taking it, being your first shot it's really decent ;)

Monday 3 March 2008

Stallman, the return

This is going to be a long one, bring a cup of tea and get reading.

Richard M Stallman (I will refer to him as Stallman from now on) visited KTH back in 1986 and held a famous lecture. At that time he and FSF also received a considerable amount of money from KTH as a thank for producing useful software for the university, 5000 USD I believe.

Last Tuesday he was back, this time it was not due to the computer club (in which I am a member) but by the union "Unionen" (it means "The union" in Swedish. Yes, I know, it's a terrible name).

Now, how does yours truly get into this mess of free software gurus, unions and university staff? You see, back in 1996 Stallman received an honorary doctors title from KTH, but he didn't attend the ceremony. I know one of our elder professors (he's a nice chap and I have helped him out in the past, I also look up to him as a teacher, but don't tell him ;) ).

The day before Stallman arrived I didn't know if I was to attend the lecture or not, after all, I pretty much know Stallmans opinions on software and I had a deadline that Wednesday. Then, out of nowhere comes an email and I am asked if I can help out with some things just before Stallman arrives and during the lecture. The next morning when my friends woke up I asked whether or not it was alright for me to take three hours off and help out at the lecture. They said that it was alright and I informed my friend the professor that I could help him with what he wanted and bring my camera in-case KTH wanted pictures. I also asked for three of the posters KTH had made for the event, you will learn more about those later.

Now, before we proceed you should know the following. When being awarded an honorary doctors title you receive a hat, it's a symbolic thing really. Because you don't really get to keep the hat.

FSFE (FSF in Europe) was to bring Stallman to KTH at roughly 17:15, so I was there at 16:30. F1 which is the largest lecture hall at KTH had half it's seats taken at 17:00 and we counted an approximate of 700 people (probably more) when the doors closed. It was packed, people in the stairs, I have not seen that many people in a lecture hall before. At ~17:00 Stallman arrived. Meeting him was a strange feeling, he looks like a hacker, talks like a hacker and certainly behaves like a hacker. He's very very frank, no "excuse me" just "I don't hear a word what you are saying." if you didn't speak up well enough. It took a while for yours truly to adapt from his usual very humble and nervous self. I should mention that I did not greet him or anything, picture me as the man in the background waiting for something to do, like bring this or that. My dear professor took care of all the official business.

Stallman wanted to prepare before the lecture (and plug in his laptop), so he was lead into a lecture room near F1. Unfortunately there was to be a lecture in German, so he had to leave in a hurry and was lead into the lecture hall before the huge crowd. He just relaxed, plugged in his laptop and a water boiler and waited for the clock to turn 17:30. I took the opportunity to take some photos, as you can see below. I also managed to talk to the photographer from Computer Sweden, he pointed out something about "Well, I prefer to use natural light sources, when he noticed my flash". I thought "Well, why not?" and switched from my normal zoom to my much more light sensitive 50mm lens and tossed my flash into the bag.

After being introduced by a representative from Unionen, Henrik Eriksson (the professor I mentioned earlier) took the stage.

Ironically, the best shot I got is probably the shot of him. Not one of the ones I took of Stallman, well well, I am still an amateur photographer. First Henrik asked how many that were present back in 1986, I spotted two people raising their hands, there couldn't have been more than 10. Henrik then explained how all went well that day back in 1996, cannon shots were fired (Stallman pointed out "But they missed me!" and grinned) at the doctors ceremony but no Stallman was there. After reading the text which explained why Stallman received the title of honorary doctor at KTH another professor approached him and placed the hat on his head.


Now, that's a picture that you won't see every day. For more images see my dA account, since this blog post is supposed to be more of a story, not a set of images.

Henrik then reclaimed the hat, he also mentioned that it quite looked like a magicians hat and that there probably were rabbits in it. Stallman the made a quick sprint, grabbed the hat and mimicked petting a rabbit, the crowd burst out in laughter.

Now, the main event. Stallman was to speak for roughly an hour and half. For those who don't know Stallman, he's about as radical as you get when it comes to software. You don't think software is politics? That software isn't closely related to the state of our society? Well, Stallman does, and he will tell you.

The speech was exactly what I expected from Stallman, he presented his view on how all software was to guarantee four freedoms for it's users. He made jokes now and then about software vendors and Bush. The only thing that surprised me was that he often pointed out that "Just because mentioned Microsoft as an example, don't think that this just applies to Microsoft, all proprietary software vendors are capable of doing this and many do". He also made an interesting remark about piracy, "When people ask me what I think about piracy, I say, burning ships is very bad", this made the crowd burst out into laughter once more.

To be honest, you can find a ton of better sources than me on Stallmans views so just read one of those instead of my interpretation. Instead I will present some points he made.


*Four freedoms of software and how the GPL guarantees them.
*How freedom of software guarantee a free society without unjust control.
*The GNU project and how it was like back in the good old days.
*How GNU/Linux is split into separate camps due to all the distros and this potentially stops what he wants to achieve with free software. He want users to care about what they are using, not just to go for "Well this works"
*How attitudes like Linus Torvalds hurts the movement since he won't side with the philosophy of the GPL.
*And more...

Personally, I agree with him on some of his views, for example that free and open source software might benefit our society in many ways. But in just as many ways I disagree with his views. I am happy for what he has done, but I won't stand beside him. His views are in many ways a religion, good and bad, it's all there.

The aftermath is Swedish papers has been very much about Stallman being paranoid. He mentioned a lot of things about cellphones being able to track you, programs spying on you, credit cards etc. etc. I agree that it might sound like he is all afraid of being tracked, but I think the answer is much more reasonable. Stallman is a freedom fighter, a radical one. He wants people to have, in a way, an ultimate power over their devices. He wants them to be able to choose whether or not they want someone to know anything about them. It's a philosophical stand, not a statement of some paranoia. I was once told that you should never rush to the conclusion that someone is stupid if there is a more rational conclusion, and although I am not a Stallman expert this very much seems to be the case here.

Afterwards, Stallman stayed and wrote autographs in exchange for a 30 SEK donation to the FSF. I got one for free on one of the posters which I handed to another Stacken member. He promised to put it on the wall in the computer club room. What ever you say about Stallman, he has been influential and probably will be for the years to come. For good or for bad? I guess we won't know for sure for at least another 20 years.

Sunday 17 February 2008

Observations on my way home


When walking home this Friday I noticed something peculiar. Usually when a pedestrian enter a store he moves in an arch, much like my sketch to the right. He also maintains roughly the same speed as before entering the arch until he reaches the door to the store where he slows down slightly, opens the door and enters the store.

But one store is different, here, people enter the store in a radically different way. They maintain normal walking speed and keep their eyes fixed straight forward, unlike when entering other stores where they always look around observing other stores and pedestrians. Then, when they have passed the point when at other stores they would begin their approach in an arch, they suddenly turn at a sharp angle and increase their speed substantially. They maintain this increased speed pushing the door open with force and does not appear to slow down until inside.

The reason might be, that the store is the most well known adult video store in Stockholm.

Saturday 5 January 2008

Swedish Anti-Piracy Commercial

Now and then Swedish anti-piracy agencies and the Swedish movie and music industry makes a commercial in order to tell us, the people of Sweden, how morally wrong piracy is. If you just cut the crap and don't argue whether piracy is wrong in the first place, the latest movie, and all other movies they have ever made, has a pattern. Let's describe the latest one.

A person walks up to a public toilet and pays the fee of roughly 5 SEK (about 1 USD). Just as he enters the booth, another person forces his way into the booth with him. He is then forced to pee along with a stranger although he paid for the booth himself and the stranger does various embarrassing things and is not the least embarrassed about "stealing" his spot.

Something like this is usually the theme, previously we have seen people borrowing movies from rental shops without paying.

Now, what is the problem with this? It portrays the person conducting piracy as someone who is stealing from a customer or a store. Is this really the case? I certainly don't think so, a person conducting piracy don't steal anything. They certainly do some economic damage, but they don't steal. By portraying them as simple thieves, the industry leaves an open goal, their opponents laugh at them and most Swedes just think that they are silly. They look stupid, and won't get paid.

What should the industry show instead? You don't have to be a genius to come up with an honest and probably better commercial. So, here you are STIM, APB, SF and so on, here's my suggestion, all for free. Instead of portraying the person who you so clearly, don't want to continue copying your material, as a thief, which he is not and will never associate himself with and therefore will continue copying your material and you have run down your many million SEK commercial down the drain. Why not show him what he actually does, show him how a movie is made, show him how money spent on a movie get people paid for their hard job, show him the set of actors and so on, showing numbers and faces. Don't go all silly and show sentimental letters, just facts, "When you condone piracy, all these people get nothing and to you, they give you the very best of their efforts". This will work, this is honest, this is what piracy is all about and how you might actually win. Stop acting like idiots with a multi-million SEK budget who are unable to send a message but able to make great movies, albums, etc. It ain't that hard, all you need is the ability to reason.