#!/usr/bin/env ruby lines = [] while line = gets() do lines << line end while ! lines.empty? do idx = rand(lines.length) puts lines[idx] lines.delete_at(idx) end(Any Ruby afficionados out there, feel free to e-mail me and tell me what egregious sins I've committed). I think it looks reasonably neat and clean, it's certainly simple, and the use of real Object Orientation makes for a certain readability (I think the method call lines.empty? is particularly cute, although I did initially consider the use of a question mark in a method name to be a crime against humanity). So, will I be using Ruby more in the future? I think so. There are some features in Ruby which I'm hoping to get a lot more cosy with -- the idea of "blocks" looks particularly interesting, and I don't think the utility of languages that have been designed, top-to-bottom, to really live the OO ideal has been explored enough (you SmallTalk bigots can stop glaring at me now -- really, I mean it -- stop it!). It's far too early to tell whether Ruby will become my "go to" language for random development tasks, but anything that stops the nightmares (where I start thinking about using PHP as a general scripting language) cannot be all bad. And, if I continue to make new webapps, Rails will probably come in handy. Update: HTML <pre> tags don't like having < inside them unescaped. Also, Philipp Kern pointed out that the Ruby documentation browser is called ri (not ir as I originally wrote). Philipp was also kind enough to provide a much shorter version of my original script, which shows the power of Ruby so much better:
lines = [] STDIN.each_line line lines << line lines.sort_by rand .each line puts lineNow tell me that isn't a language worth using!
Earlier I dismissed the
quod libet music player
since it needed 20% of my laptop's cpu to play music. The new
version has been improved, it only needs a still exorbitant 13%, but at
home I use my shuttle PC for music now, so CPU usage doesn't matter. And I
think quod libet is worth the slightly lowered battery life on the road
too.
There's no end to the features -- and plugins full in all kinds of
interesting edges (onscreen display, audioscrobbler, alarm clock) -- and
while it's still under development with a rough spot here and there, mostly
around the plugins, it mostly just works.
I'm especially impressed at how powerful the tag editing is in quod libet.
It makes it so easy to clean up the missing and broken metadata in even a
large sound library like mine, and the effects are so immediate and nice as
things get sorted into the right place, albums ordered as missing track
info is added, album covers displayed, that it's addictive just to putter
around in there.
Some other features that IMHO make it worth using include the ramdom album
plugin, which lets it pick a new album at random when it finishes playing
the current one (my collection is too varied and big for random track play
to work, but this, mostly, does), the gorgeous album list, and the queue,
an odd little feature that lets you insert any songs you like into a play
queue, to play after the currently playing song. Which solves a lot
situations I've been in before.
And the little details are all there too, little things like right-clicking
on the play button to turn off the music player after the current song
finishes; and automatically and quickly finding new music on startup; and
properly supporting multiple artist albums.
And that just scratches the surface of things I've found to like over a
day.. there's a whole regexp/tag based search engine in there, a music
prefernces learning system with weighted playback, internet radio,
playlists and more. And it's actively developed, and kinda oddly marketed
squarely at Debian users.
Buh-bye rhythmbox..
Sony claims that it needs to install dangerous, malicious, underhanded software on its customers' computers to protect its copyrights, but in order to write this malware, it has no compunction about infringing on the copyrights of public-spirited software authors who make their works available under free software licenses like the GPL. I suppose it's natural to believe that everyone is at least as sleazy as you are: for Sony's rip-off artists, assuming that paying customers are planning to rip them off must come easy.How can anyone even vaguely involved in the tech industry possibly believe that anything they write can't be popped open and peeked in, to find out what naughtyness they've done? The mind boggles. Sony, you are on my official shit list. It's a long and prestigious list, but you've managed to climb very quickly to the upper echelons. May the fleas of a thousand camels infest the nether regions of every Sony executive who may have had anything to do with this whole fiasco. The original article is available, and is quite informative. Yay for BoingBoing, also, who provide me with so much of my daily interesting news.

The skyline of South Manhattan
We walked over the Brooklyn bridge, giving me other very cool views of
Manhattan, while I hammered Clint with questions about this and that. I saw
that since 9/11, you can't go past the Town Hall. "Security reasons", of
course. I was very surprised to see police cars in every single street. It's
like a Police State, and if you ask me, it didn't make me feel safer.
After some walk, we finally got in Chinatown, which is the craziest place
ever. People sell stuff on the sidewalks, and many streets are packed with
people. We had to meet with mikah, biella, dilinger and his cat at some Chinese
place for breakfast/lunch. The place, as Chinatown itself, was crazy. As soon
as we sat down a few waitresses landed a few plates on the table, without
asking or anything. A few minutes later I could see that the way they serve you
is going around with carts with lost of food, and you either want it or
not.
We left dilinger at the metro station, and moved on to the SoHo. I wanted to
go to the SoHo Apple Store to see if they knew about replacement Spanish
keyboards for my Powerbook. My powerbook was bought in the US last year, so it
has a US keyboard. This is mostly ok, but only mostly as it's missing a
key.
After SoHo, we went back to Chinatown to pick up bubbles. It was nice to see
her after Debconf, and she made the effort to come just for a few hours even if
she was ill and had lots to do in Philly. We headed to South Street Port, where
I had a long chat about Cuba with micah while we sat on a bench looking at
Brooklyn bridge.
And then, we gathered all our braveness and headed to the heart of the
beast, to the kernel of the system. We walked into the Financial District, and
soon enough I was walking in Wall Street no less. If I breathed hard, I could
smell the money. The road was paved in gold, and there were skyscrapers
everywhere. I discovered the rulers of this world had opened a "public space"
in JP Morgan's building. To their despair, probably, it had been taken over by
the poor. I wonder what Bloomberg will do about it.
As I walked up the street, a strange feeling in my heart grew and grew,
until, behind a corner, I saw it. The source of all evil was ahead of me,
guarded by George Washington himself.

The New York Stock exchange and it's black evil aura of Capitalism
I was standing ahead of this building where so many people behave like
bastards everyday, pushing millions to povery for a bit more profit margin. The
doors were closed and surrounded by security officers, which despite being
asked politely, didn't let us in for "security reasons".
Next to it was the Church of Capitalism, at the end of the street. It's
curious that such an old church still stands where it was build near the
harbour probably a century ago, now surrounded by some of the most modern and
tallest buildings in the planet. And then, we visited the bull, which I didn't
know is the "friendly" symbol of how Capitalism works.

I had Capitalism by the balls
We moved down to Battery Square, past the old US Customs building with the
four statues representing the four continents. We saw the damaged sculpture
which lived in the WTC, and sat down at the pier to watch a beautiful sunset
over the Statue of Liberty.

The Statue of Liberty seen from South Manhattan
At that point, biella and micah had to meet some friends at one cinema to
see the Wal-Mart documentary. We went to a funky place to have some tea,
decided to go see Times Square and then walk to Central Park. At the time, mako
was arriving to NYC on the Chinatown bus, so we agreed to meet in a restaurant
to have lunch. Paul Sladen finally managed to get lost, after many tries during
the day, and wasn't seen until we got back home.
Mako and Mika waited for us at the door of an... ethiopian restaurant in the
SoHo, despite Mako knows I can't stand spicy food. But in the end it wasn't so
bad, I just needed a few more glasses of water than average. And I finally got
to know mika, after lots of time of chatting over IRC. Greg, SPI's lawyer, also
appeared, and was a nice addition to the group.
Mako knew where to take us after that. The Belgian bar was packed, but there
was a private party in one of the spaces and we took over some of that space.
After a few rounds, we were ready to leave the pub and go for Falafel and some
tea. I was terribly falling asleep though, so instead of tea we took a cap back
to Brooklyn, where we found Paul waiting at the door.
After an hour of inflating a mattress, we were ready for sleep, at 4AM. It
didn't look like the morning after would be very productive...
It seems to me the argument that linking a GPL application to a CDDL library and asserting that that somehow makes the library a derivative work of the application is, to say the least, a stretch&emdash;not to mention the fact that we're talking about libc here, a library with a highly standard interface that's been implemented any number of times and, heck, that's even older than the GPL itself. It's interpretations like this, folks, that give the GPL its reputation of being viral, and I know how much Richard Stallman hates that word.The core misunderstanding there is that the GPL somehow claims that libraries linked into a GPL-licenced binary are derived works. Nothing in the text of the GPL states that, and a quick scan of the GPL FAQ doesn't provide any opinions of that nature, either. What the GPL does state are a few conditions which you have to abide by in order to be given permission by the copyright holder to exercise rights ordinarily held exclusively by said copyright holder. One of those is that, in order to be given permission to distribute a compiled binary, you must be able to provide source code for the binary itself, as well as all interface definition files, build scripts, and modules contained in the binary, and that all of this material must be provided under terms no more restrictive than those of the GPL. The GPL isn't trying to lay a "derived work" claim on any of those other parts. It's just saying to you, as someone who wants to distribute a binary, "here are some other things that must be OK if you want to do this". A similar clause exists with regards to patents and court judgments (section 7, for those of you playing along at home). This doesn't mean that the GPL is attempting to claim that the patents or court judgments are derived works. A licence could also say "you must delete all copies of any Microsoft product from your hard drive before duplicating this software", but that wouldn't mean that the licence is attempting to claim that all Microsoft products are derived works of the licenced software! As anyone who's looked at a typical proprietary software EULA probably already knows, a software licence can claim pretty much anything (and, apparently, thanks to the DMCA, in the US they can make it stick). The licence doesn't make the claim on the basis of derivation, it makes it because that's just what the licence claims. The GPL is no different in that respect. If you can't fulfill the licence conditions (either because you don't want to, or because -- as in the case of the clause under discussion -- the module you are including in your binary can't be licenced under terms equivalent to the GPL) then you can't do whatever it is that the licence would otherwise allow you to do. To be fair to Ian, some of the comments he made to his blog post indicate that he does understand the distinction between a claim due to derivation and one due to a simple licence term, but I thought it worth making the point crystal clear to everyone out there in the blogsphere, because it's a very common misunderstanding, and I'd hate for it to spread any further than it has already.
pickle.dump(library.values(), file). When it loads, it does something like for song in pickle.load(library): if song.valid(): library.add(song) where song.valid() reloads the song if its mtime has changed or removes it if the file no longer exists.
So what’s the problem with this code? I sure didn’t see one until this morning, when our Italian translator complained about interestingly long cold cache startup times. The answer’s at a lower level than Python programmers usually have to work at: This sucks for disk cache.
library.values() dumps the file in Python dict order, which is not only not meaningful, it’s actually semi-random for security reasons. When I reload the dumped file and iterate through the songs in it, I’m stat(2)ing files in an order designed to be as unpredictable as possible. How is the cache supposed to cope with that? The answer is, it doesn’t.
Sorting the songs by filename when saving the dict costs almost nothing (Python out-sorts every other language as far as I know), but saves 10% wall clock time for me when starting - it will probably save even more on filesystems that perform poorly on stats of large files (reiser3), and directory trees that go more than 2 levels deep.
Lessons learned: First, CPU profiling is good, but doesn’t have all the answers; profile.py insists the program is slower because of the sorting on exit. Second, ideas that work fine for n=100 don’t work well for n=10000 even if the algorithm you chose scales well with regard to complexity theory. Finally, the fundamentals still matter; fixing slow Python code still makes you consider OS/hardware-level cache effects.
Next.