BFS vs. DFS (2010-07-05 13:51)
|
XKCD recently claimed that BFS is generally superior to DFS in the context of dating. I would like to make the same claim about browsing. In the latest version of Firefox when you open a link in a new tab, the new tab is placed to the immediate right of the tab you are currently in. While it might make sense to try to place related tabs next to each other, this also has some drawbacks.
If I'm looking for something in a list (like a search result or a Wikipedia category) I typically open the seemingly most relevant links in new tabs. Then I work my way through the list of tabs opening interesting links in new tabs until I either find what I'm looking for or end because I don't seem to be headed in the right direction. When new tabs are opened at the end of the tab list, this is exactly BFS (except for the fuzzy "wrong direction" criteria). When new tabs are opened next to the one you're in, this behavior instead becomes DFS. This is not good since the frequency of relevant pages should be better in the shallow parts of the search tree (otherwise the original list was useless, and we could have started anywhere). This behavior is also the best way to get sidetracked at Wikipedia. At least with BFS you are more likely to get sidetracked after you find what you're looking for.
The new placement strategy also has a tendency to disrupt the order in the basic set of tabs that I always have open, making it harder to find often used pages. My preference would have been to be able to choose placement strategy by use of a modifier key.
If you want to have the old behavior back, enter
about:config in the location bar and toggle the
setting tabs.insertRelatedAfterCurrent.
kpc 2010 (2010-02-08 21:04)
|
The development department at Klarna, where I work, is hosting a programming contest. It started today, and during the coming month you are welcome to submit solutions. Prizes will be awarded both in the category of speed, as well as quality of solution. First prize is a job offer at Klarna.
So if you're looking for a job, smartphone or a challenge, check out our contest site.
Diamond dust (2010-01-31 22:54)
|
|
I like the current weather, it's the kind of winter I always dreamed of (and many times got) as a kid. Yesterday I was out cross-country skiing. The weather conditions where excellent, with temperatures around -20oC, little or no wind and miles of untouched snow. At one point I skied through small clouds of what I perceived to be diamond dust. I had one minor setback, when I had to spend fifteen minutes cleaning my skies of ice after I skied over a frozen lake where water had poured up throug cracks. It's hard to do the experience justice by means of photography, but that's no reason not to try. I felt this one kind of captures the mood of it. It also shows clouds of the type mentioned above.
Video editing in JavaScript... well kind of (2009-11-29 15:09)
|
Mats Bergsten solving
a 5x5x5
cube
|
Last week my dad filmed himself when he managed to memorize a 5x5x5 cube and then solve it blindfolded in a little less than thirty minutes. To share this feat with his friends on speedsolving.com, he wanted to post a link to the video there.
Since watching the video in its full length might be a bit tedious, he asked me what software to use to speed it up. My first thought was to just increase the frame rate. When he told me he intended to share the video with other people this idea immediately seemed a lot less attractive. Many systems may not handle videos with very high frame rates all that well, and the file would be unnecessarily large. I thought it would also be desirable to have the beginning and end of the video in normal speed to get a feeling of how much the video had been sped up. I don't do a lot of video editing but quickly looked through the video software I normally use, but found no obvious solution (though I'm sure there is one).
Since the simplest way of doing gradual speed changes to a video is really just a matter of deciding which frames to include, I got bored looking further and decided to do it myself. I started by splitting the video into separate frames using FFmpeg. That can be done in the following way.
I then wrote a simple script that figures out which frames to drop (this is where I used JavaScript). The script uses a list containing pairs of frame number offsets and speed factors (described as a frame drop count). The script then interpolates the speed factor between the key frames and prints a list of frames to be included in the final result. The output is in the form of ln shell commands that creates soft links to the files to be included, making it easy to experiment with different settings without messing with the original set of files. I ran the script in the following way.
The command above finds files in a folder
named frames (-type f avoids the
folder itself). The files are then sorted in the correct order
and sent to the script which produces shell commands sent
to sh
for execution. The
rhino
command is the JavaScript engine used to execute the script code
(much like the perl and python commands).
Given the speed change and the fact that a running stopwatch is shown in the beginning and end of the video, making time a central theme, I felt that adding a visible timer would be nice addition. I'm sure there are nice tools for this task to, but as I don't do much video editing, I don't know of any, so I wrote another script. Here I didn't do any interpolation, but rather just matched the time to a frame by looking at the stopwatch the first time it's shown and then added one thirtieth of a second (determined by the camera FPS) each frame. I was unsure of how accurate the frame rate of the camera would be, but the timer aligned well with the stopwatch at the end of the video.
To put the timer text into the frames I reused some C code I had written previously to visualize GPS coordinates on map data. That code also had the option to add a title screen that fades away, so I used that as well. To avoid introducing speed issues in this step I did it before the speed change step described above.
In the end I used FFmpeg to join the frames back together to a video file again. To get FFmpeg to play nice I used a script to rename the files to be joined together so that the file names where numbered from one and up without any missing numbers in the series. Then I could use the following command to do the join.
Having every frame stored as
a PPM
file at the same time takes up some space. A better solution
would have been to handle both transformations in the C code and
pipe data from FFmpeg to my program and back to FFmpeg
again. This would also have improved the running time as adding
the text to the frames would only have been done for the frames
selected for inclusion in the final result. But as I had less
than fifteen minutes of video in 640x480 this
wasn't a problem.
As a last step I also added some music instead of the original audio, which was lost by the above process. To keep a sped up version of the original audio it should have been possible to use the same method for dropping audio samples as used for dropping frames. Though transformation of a WAV file would require some additional lines of code, and there may also arise a sync issue. In this case I think music was the better choice, as the original audio wasn't all that interesting. I also believe that a sped up version of the audio would have taken away from the overall effect of the final result rather than the opposite.
The completed video can be found here.
Software Freedom Day (2009-09-19 17:34)
Today is Software Freedom Day, it's an attempt to both celebrate and spread information about free software.
The virtues of open source are many and diverse. The most important are likely related to long term effects on technology and society as a whole. But it's also just plain fun, and I think it's important not to forget this part.
In the spirit of the day I would like to mention some open source projects that I really like, and that make my every day life more efficient and fun. Instead of choosing well known projects like Linux, GNU and Apache or some that are on the OpenDisc, I thought that I'd mention a couple of other projects.
Openbox is
the window
manager that I run. It is fast, highly configurable, makes
it easy to move windows using the keyboard and window
decorations are optional. It was also one on the first projects
to have the good taste of putting configuration files in the
~/.config/ directory.
exiv2 is a command line utility to manage image metadata. Since the data is text based it's desirable to have an application that can work in conjunction with other text utilities like grep or sed. exiv2 is obviously also very useful when writing scripts that handle image files.
SquirrelMail is a webmail application that works against any IMAP server, I use it to read and manage my mail. I think their manual was the first manual I came across that was wiki based.
ImageMagick is a command line
interface for manipulating (and
viewing) raster
images. It has good support for a large set of file
formats. When doing tasks like format conversion or scaling to
some specific size, It's a lot easier to write convert
in.tiff out.jpg or convert -scale 500x250 in.jpg
out.jpg than using a
GUI.
Just like exiv2 it's of course an excellent tool for use in
image related scripts.
Command line (2009-07-21 08:42)
|
|
One of the first things I show people when introducing them to the Unix world is tab completion. If you don't use it you're a lot less likely to embrace the command line. And as any hacker knows, the command line rules! Tab completion tend to be regarded as an "experts tool" (especially by first time users), but in some ways it may have an even grater benefit to inexperienced users. The slower you type, the more time there is to gain. Even if you know and type the name of file with a short name, it may be a good idea to use tab for the last character. This way if you misspelled the name you will know. Different programs tell you in different ways how you messed up, but in this way the error response when specifying a non existing file is always the same. The response also shows up right away, and may make it more obvious what the problem is. Both these aspects are probably of greater value to an inexperienced user.
A while ago, I was amused to see that I probably follow my own advice. The surface of my keyboard is worn out next to the tab key!
Gatekeepers (2009-06-22 15:32)
When reading a few of my previous posts, you could easily get the impression that I really like Google. This came as a surprise to me, because I don't, but it's not like I dislike Google either. In fact, more often than not they produce solid, relatively open services and (as far as we can tell) behave rather well. The popularization of the phrase "Google is your friend", probably owes a lot to this fact. But when people tend to take the phrase literally it can be a problem, because Google is first and foremost a company.
Take the service YuoTube for example. In my view, more than anything else, the service is the result of the web browser manufacturers inability to agree on a tag for video. Instead YuoTube has become norm for how to publish video on the web. This centralization may have some benefit, but it also has some really major drawbacks. One of them is that Google tend to become a gatekeeper. Again, Google is not to blame for offering to host our videos, but that doesn't mean that the centralization is a good thing!
I just read an interesting text by Cory Doctorow, where he puts this well. He says:
"So hell yeah, I sympathize with companies and creators who want to keep Google or Amazon from becoming gatekeepers on culture. Not because of who runs Amazon or Google -- I know senior people at both companies whom I believe to be honorable and decent -- but because no one should be that gatekeeper."
Post Election Thoughts (2009-06-19 14:18)
|
Ok, so we got the Pirate Party into the European Parliament, and the guy who I checked on the ballot got our one seat. Needless to say, I'm very happy with the outcome!
During the election campaign, the main criticism directed towards us (surpassing any and all other criticism by the way) was not on issues where we took a stance, but that we where a single issue party. I don't share this view, but still, after having been confronted with this criticism a lot in the last few weeks, I thought I'd present my view on it here.
First off let me say that in theory I'm a big fan of the idea that every parliament member use only their own best judgment each time they vote on something (note however that this does not mean that they must vote on every single issue). In reality on the other hand you will often be able to gain influence in one question by trading for less influence in another. So the first question becomes: is this kind of trading of influence ok? My answer is yes absolutely! I'd like to be able not to do this, but there is no way I could rationalize not compromising a bit on an issue of little importance to me, in favor of one that I find vital. Every political party I know of in my country share this view. The next question then becomes: is it ok to compromise on all but one or few issues? This may seem more tricky but the answer is still the same as for the first question: If what you may lose in the trade is acceptable compared to what you think you will gain, then yes it must be ok.
Much of the criticism has been not so much on our willingness to compromise, but rather the fact that we lack opinions in many areas. The short silly remark here is: "What good are opinions that you never plan to use?". The longer more serious answer realizes, that while the party may lack opinions, it's members probably do not, but that this is where they are willing to compromise. Or put another way: the party has opinions but the interval of what is regarded as an acceptable outcome may span the intervals of most, or in some cases all, of the other parties.
So what is my reason for voting the way I did? As indicated in some of my previous posts, I think the Swedish government has started to crack down on civil rights. The only party with an acceptable plan for how to fix this problem is The Pirate Party. The name may seem silly, but what the party stands for is not. In fact, the name may even put some attention on the fact that appearance and ideology are two separate things.
The Washington Communist (2009-05-18 16:39)
Links
is
the reason
we
call it
a
web
|
I just read an article in The Washington Post that upset me. The authors of the article dislike the idea that search engines like Google "crawl the Web and ingest everything in their path" and then link to it! I have so many different objections to this that I don't know where to start. But lets start with the assumption that the source of this kind of thinking is a real problem. Ok first off nobody is forced to publish stuff on the Internet or in this case more specifically on the web. And if you choose to do so, there is still no need to let anyone access it, it could be a commercial subscription service. The natural objection to this would probably be "but then I won't have any readers!". That may be, but at least you will have avoided those pesky incoming links.
The same conditions exist in the physical world. A newspaper can either put a paper in all mailboxes or they can in some way limit who gets a copy. The first option has the potential to reach many readers, but is expensive in terms of printing and distribution. This is the reason why most newspapers choose the second option. On the Internet on the other hand, the cots of printing is zero and the cost of distribution is marginal. Therefor most papers have actively chosen the first option.
What often seems to be missing in this debate is that online you can choose the first option with a publication being available to all, but still avoid being placed in the search index. The way to do this is to use a robots.txt file describing what part of the site that should be indexed. This means that you can request just what part of your content that you want to have indexed. I usually prefer opt in systems than opt out ones, but in this case the opt out first become an option after the opt in to publish publicly on the web is chosen.
An alternate point of view beneficial to understanding this situation better, is to view the search engine index as a service targeted at site owners, where the market price of that service has reached zero. All newspapers knows this and they choose to use this service because it generates more readers and more income. If the market prize is zero from this perspective, it should still be zero even if you see the newspapers as the service providers and search engine companies as the customers. If no one is able to produce news content in an environment where people link to it and there is still demand for that material it can be sold the way it always has, but online. That is, a paid subscription service with no links to it. The only thing different from before is that newspapers will not have a de facto monopoly on ads. For me who is not that into the idea of monopolies, this is just a good thing. Any attempt to adjust this by laws is not a free market but rather something completely different!
If you don't like how the web works you should start your own (I'm not kidding!) instead of destroying the current one.
Crude but Fun! (2009-04-19 20:03)
|
Today my dad forgot where he placed his car key, so I got to open the trunk for him ;-)
To be fair I should probably note that the car is old and going to the wreck yard. I just wanted to make sure no items were left behind.
Big Brother needs new glasses... (2009-04-13 09:03)
This was originally something I put on my web page a few months ago. But as it's in the form of blog post and it won't stay there forever, I decided to put it here.
The text above can be translated as either "Big Brother needs new glasses, would you like to pitch in?" or alternatively "Big Brother needs new glasses, are you willing to pay the price?". If you don't understand what this is about (but want to), there are people who will explain it in full detail.
Getting Around Friendly User Interfaces (2009-04-01 12:25)
|
|
As any prudent person I want to keep listings of my financial transactions given to me by my bank. In the old days (before banks took their business online) this meant that each month you would open an envelop and put the paper found inside in a binder. Computers really kick ass at putting files in folders, which is pretty much the same thing. Obviously all work that previously went into this process should be basically eliminated, or? Well if Google were to get into the business of banking, I have a feeling you wouldn't need to save anything, as they would do it for you. Skandiabanken (the bank I use) keep data available for a limited period of time (about two or three years). After that they offer to sell it back to you at ridicules prices. Strange... but still ok by me, as I like to keep my own data. But when you go to save it, they only show you twenty transactions per page and the only available format to save in is HTML (copy and paste just gives you a mess worse than a HTML file).
Now this might not be worth enough to get worked up over. After all, it's still better than competing banks that just gives you three month worth of history. At least in my case you can do it once a year and it won't take more than ten or fifteen minutes a year. But it still annoys the hell out of me that something that should only involve downloading a small file takes that much time (in fact more time than needed for the paper and envelops) and also produces a result that is a lot less usable than a simple text file would be.
So, to resolve my frustration I just wrote a Greasemonkey hack that adds some much needed functionality to the site. Using the script I can download all available transaction history in one file as text or XML. I first heard of Greasemonkey a couple of years back, but this was the first time I ever used it. I must say that I really like the spirit and purpose of the system. My script is available here.
Sweden is broken (2009-02-25 22:49)
Today the Swedish Parliament passed a law that should never have been passed!
I believe that future Swedish textbooks (or their equivalent) explaining the concepts of fundamental justice and democracy will contain parts dealing with what happened today (and a few related laws already passed or in the makings). I would now like to take the oppertunity to say to those who voted yes, abstained or in other ways supported the law, that the book parts mentioned will essentially have been written by you!
HAX has put together a nice succinct text (in Swedish) describing how messed up the law is.
The Moon (2009-02-10 22:30)
|
One thing that I find fulfilling is to use inexpensive equipment to its limits (or for purposes not intended). The last decade digital cameras has become an attractive domain for projects of this kind (CHDK is an excellent example). Recently I built a rig (see pictures 1 2) to mount a camera to a simple telescope. Yesterday I used it to photograph the Moon with a decent result.
Meeting with another Jonas (2009-01-30 15:10)
|
Today I went down to the parliament building to say hi to Jonas Nordgren and express my appreciation for his efforts in opposition of the FRA law. He has been sitting outside the parliament this month in protest of the law which first took effect on January 1. Besides having an interesting conversation with him, a funny thing happened while I was there. As we were talking, a delivery guy came up to us and asked Jonas (who was wearing a sign saying 1984) "Are you Jonas?". Someone had sent him a box of chocolate addressed to "Jonas Nordgren sitting outside the parliament building wearing a sign", which I thought was both nice and pretty funny.
I love Wikipedia! (2009-01-15 22:25)
Note: This post is written to blow off steam!
Today I came across yet another post about Wikipedia and how it's not accurate or reliable and further that it's not appropriate as a reference source. Well of course it's not an appropriate reference source. The fact that people complain about this is just amazing to me (complaints about it's usage as a reference source is of course ok though). It doesn't seem to matter how much Jimbo and others points out that "encyclopedias of any type are not usually appropriate as primary sources". To me it appears as if people complaining about this likes the scope and concept of Wikipedia but that it would be oh so darn nice if you could just blindly trust everything in there. Or possibly that if they cite big commercial encyclopedias as a source and they're wrong, the have someone to blame, but with Wikipedia this just makes them look stupid. If you get upset about not being able to cite Wikipedia as a source your problem isn't that Wikipedia suck it's that you suck.
So if I can't rely on it as a reference source it's no good then? Not likely! You may understand something, find useful media, be inspired or find the reference source that Wikipedia isn't. There are plenty of things that Wikipedia can never be, but it is something new (yes still) that was not possible before. I think that most attempts to make it conform more to classical patterns would break much of what is good with this new machine. To some extent I even find the lack of reliability as having some benefit. When you understand how the articles are written it's completely obvious that they may include errors (intentional as well as accidental). This may not be the case with traditional media even in the cases where the reliability is very low. I think this will help foster an attitude towards sources of information that is more healthy.
I use Wikipedia extensively in many different areas and seldom if ever do I feel that reliability is a problem. Not because I think the reliability of the articles I read nesicerally is very high, but because most of the time a definitive answer is not what I'm looking for. When it comes to your own use of Wikipedia content, it really is a situation where you can take what you like and leave the bad behind (or change it)!
Happy New Year (2008-12-31 20:51)
As a young boy I was very fascinated with fireworks, both the esthetics and technology of it (as well as the action I guess). Fireworks at midnight on New Year's Eve was therefore a given in my family. As a teenager my interest shifted slightly to curiosity over how large an object I would be able to blow up using firecrackers. Later I started to feel that fireworks are bad for the environment (ecological as well as social). Yesterday I got the idea to write a fireworks animation, and in the spirit of simplicity it is written using Javascript, CSS and HTML with no image files involved.
Cold Weather (2008-12-29 23:15)
|
We finally got some nice weather with blue skies and more then just mild sub zero temperature. This means I can go tour skating, me and my sister was out on the ice for the first time this season.
Saffron buns and strange holidays (2008-12-12 22:48)
|
Tomorrow we swedes celebrate Saint Lucy's Day. While most people probably associate this day with nightgowns, singing and candlelight, to me before any thing else it's about saffron buns (which we call lussekatter). This fact makes today special in that it's the only day of the year when I show any culinary interest whatsoever. Today I made three batches.
Frist prost (2008-12-11 20:12)
Today I registered the domain http://jonasbergsten.com/, mostly because I need a new mail address.
Often when I do some at least mildly interesting project, I feel the urge to document it for future use. However, hacking or whatever almost always seem to be more fun than writing about it. Recently I thought that even the possibility of someone else reading it would help motivate me to write more stuff down. So that is the primary purpose of this blog. That said I'll probably also just blow off some steam from time to time, so don't expect too much.
I haven't decided on what (or if) software to use for the blog, so currently this is (just) a static HTML file. I'm kind of drawn to the idea of rolling my own. As a big fan of Javascript (or at least the good parts) I often find that a CMS tend to limit my freedom in regards to Javascript, HTML and CSS (most of the time for good reason). But the idea I just got was to write a CMS truly as a framework where free content call the system rather than the other way around. But for the time being it'll stay in this simple format.