September 2010 M T W T F S S « Jan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -
Recent Posts
Tags
apple awesome beatday browser cli DR exherbo festival fortune gmail homebanking ipod touch irc irssi itunes jailbreak java KDE konqueror last.fm LaTeX mac matroska mplayer music Open Source Days open standards package maintenance perl radio repositories rss scripts twitter vim waste of time wmname writeroomCategories
Stuff
Tonight we boot in hell!
Posted in linux
Leave a comment
Web 2.0-sy in a classy way
I’m not very web 2.0-sy.. I haven’t joined any social wobsite and while I do blag every once in a while, it’s not as frequent as all the hip people and it’s usually a lot less interesting.
Nonetheless, I’ve wanted something simple to toy with awesome 3.0 (it became 3.1 while I pondered) and the lua configuration thingie. To be honest, I preferred the old libconfuse-based config system – it was a lot easier to wrap my mind around it and it was a lot easier to debug when something went wrong. I’ve seen the various mpd widgets, volume widgets and many, many monitoring widgets but I wanted to play with something that, to the best of my knowledge, hadn’t been done before.
So I thought of making an awesome widget for Twitter. It was a stupid idea so I promptly went on with it.
The first minor snag I hit was that I’ve actually never used Twitter. That was easy to solve though. Now with moar web 2.0!
I quickly gave up on writing something to actually interface with Twitter. There are countless of scripts, language modules/libraries and whatnot for doing that and while lua seemed to lack a Twitter-library I didn’t want to try my luck at writing that since I seriously lack lua skills as well. So I used the Net::Twitter perl module and wrote a short wrapper script to do the job. All that was left then was the awesome configuration. All of the following lua-code goes somewhere in your rc.lua.
First of all, functions. It seems these has to be defined earlier in the file than where they’re called…
function updateTwits()
local twits = {}
local fh = io.open("/tmp/twitlist")
if not fh then
mytwitbox.text =
"<small><b>No twits present!</b> I suggest looking at the gentoo community</small>"
return
end
for line in fh:lines() do
table.insert(twits, line)
end
if #twits > 0 then
mytwitbox.text = awful.util.escape(twits[math.random(1, #twits)])
else
mytwitbox.text =
"<small><b>No twits present!</b> I suggest looking at the gentoo community</smal>"
end
end
function postTwit()
awful.prompt.run({ prompt = "Twit: " }, mytwitbox, function (msg)
os.execute("/home/arkanoid/bin/twit post \""..msg.."\" &")
mytwitbox.text = "Tweet posted! Go grab a cup of coffee ;-)"
end, function () return nil end)
end
The first function, updateTwits, grabs a random tweet from a list of tweets generated by the twit.pl script and updates the text of the twitter-widget. postTwit spawns a prompt and posts your tweet to twitter.
To actually use this we define a textbox widget and fill it.
mytwitbox = widget({ type = "textbox", align = "left" })
mytwitbox:buttons({ button({ }, 1, updateTwits),
button({ }, 3, postTwit) })
updateTwits()
This way a left mouse click on the textbox will fetch another tweet and a right click will give you a prompt so you can submit a new tweet.
Remember to add the widget to a wibox. In this case I added a second wibox (statusbar in pre-3.0 terminology) which is located at the bottom of the screen.
mysecondwibox = wibox({
position = "bottom",
fg = beautiful.fg_normal,
bg = beautiful.bg_normal
})
mysecondwibox.widgets = { mytwitbox }
mysecondwibox.screen = 1
I might as well make awesome fetch a new list of tweets from twitter as well.
awful.hooks.timer.register(60,
os.execute("/home/arkanoid/bin/twit friends >/tmp/twitlist &"))
The main reason for not doing this in updateTwits is that the command might take a few seconds and awesome would be frozen while it ran. So I grabbed an idea from the awesome wiki and made a second timer that ran the fetcher in the background.
Add another hook to update the twitter-widget at a reasonable interval:
awful.hooks.timer.register(20, updateTwits)
Lastly a keybinding to post a new tweet by pressing Mod4+Shift+t:
keybinding({ modkey, "Shift" }, "t", postTwit):add()
And you’re all set – one very classy awesome twitter-widget fully operational. It is in the lower left corner:

It’s a pity I really don’t give a damn about twitter and probably won’t use it for anything. But at least it served as an icebreaker to awesome and lua for me.
And as for awesome and lua… it seems a lot less silly now than it did five hours ago.
Santa came to town…
<rant>
First of all, merry christmas!
Second of all, yay! I got an iPod Touch for christmas which was definitely a nice surprise. I take it as a sign that I’m probably past the “just-moved-away-from-home-must-give-kitchenware”-stage. While being nice and useful and all that, it’s really hard to get wound up over a frying pan.
Anyway, I’ve been toying around with the Touch since yesterday. It turns out that I have a 2nd generation machine, which means no jailbreak for it yet (as far as I could google… feel free to correct me). Now, I’ve always steered clear of apple, not out of spite og dislike for their products but mostly because of their price level. I’ve never ever touched iTunes but I’ve spent a fair amount of time and effort to organise my collection of music and make sure I can listen to anything when I want anywhere in my apartment or in the near vicinity. A combination of MPD, icecast, picard, flac and a handful of other nice tools made that possible. So I look forward to being able to integrate the iPod into that system, once it’s jailbroken.
Being a sucker for shiny stuff, I obviously won’t leave it idle until then so I dug out a windows installation, threw iTunes on it in order to sync my music to the little beast.
What a disaster!
I am certainly not at home using windows or an apple application so maybe it’s just me being stupid. But for the life of me, getting music on the iPod wasn’t a pleasant experience.
I used winscp to copy the music (in flac format) to the windows machine but wait, iTunes can’t handle flac… away to google I went only to see that iTunes + flac apparently required me to use mac osx. Not an option! So off I went, downloading the official flac tools and converted the flac music to wav, losing the tags in the process – sigh. But lo and behold: iTunes can read wav. In that case, problem solved. I should be able to just make iTunes convert the wav-files to their stinking aac-format, retag them and the nsync them onto the iPod… but no! You cannot convert wav files apparently, only mp3 and ogg. In that case, let’s convert the wav-files to ogg and then convert them to aac from within iTunes… it only takes about 4-5 minutes per track. iTunes is currently in the process of converting the second out of god knows how many albums. I guess I’ll go to bed soon and hope it’s done when I wake up. In the long run, I’m probably better off doing the flac->ogg conversion in linux, run windows xp in a virtual machine and iTunes in there. At least until I can jailbreak it and use either Amarok or gtkpod.
So much for actually getting music onto the iPod. But during these few hours, I’ve really grown to hate iTunes. I find it slow, buggy, unintuitive, annoying and difficult to navigate efficiently – and this is compared to Amarok, which is generally considered a serious ressource hog! I ran iTunes on a pentium 4 processor, running at 3.2 GHz. The system had 1gb memory and plenty of free diskspace. The windows installation was fully up to date (service pack 3 and all that crap), there’s a decent graphics card in the machine (decent enough to play Civ 4) and correct drivers and 3d-acceleration working. So I really, really can’t understand why iTunes made me feel like I was back in the glorious days of old and obsolete hardware. Some of the slowness seemed to be caused by lockups whenever iTunes interacted with the iPod.
In conclusion: I hate iTunes.
That being said, the iPod Touch itself is really nice, responsive, intuitive and a real pleasure to play with. Getting it set up to my basic preferences was way easier than I had expected, wifi just worked and finding free (as in free beer, mostly) apps that did what I needed (radiostreams and MPD controller among other things) turned out to be easy as well.
I guess apple’s stuff shines the brightest when you combine their hardware and software.
Oh, and did I mention how constrained I felt trying to do anything at all in windows?
</rant>
radio.pl killed the video star
A little while ago, I wrote about a small perlscript for playing internet radio stations. Since then, a few more features have crept in, such as resume support (‘radio start’ will play the last station you listened to).
Another idea I had been toying with was adding scrobbling support, so I could submit the tracks to last.fm. Their API isn’t extremely advanced but it did require some information that wasn’t readily available, such as the unix timestamp for when a track started. But thanks to an ugly hack (piping mplayer output to `perl -nle ‘BEGIN { open STDOUT, “>”, $lfmfile or die $!; } print time, “:”, $_;’`, someone please give me a better solution), that was solvable. Another issue I haven’t figured a not-completely-horrible solution to is calculating the length of a track, since last.fm doesn’t want tracks that are shorter than 30 secs (those are usually ads anyway).
But in conclusion radio.pl now supports submitting your tracks to last.fm, if you provide your credentials. Basically, just create a file ~/.radio.cfg with the following content:
lastfm_user = arkanoid
lastfm_passwd = md5:117a520adbd19eff51100215aa7a7fbf
and it should work (provided the radio stream actually contains the proper information in ICY, which at least SomaFM, SKY Radio and Digitally-Imported streams seem to do). You can also add your password in plaintext (without the md5: prefix), but that’s just silly.
The current support is quite ugly so expect breakages. If you want to know what’s going on with the scrobbler, just add –lfmfile /tmp/lfmlog when you start the script and tail that file. Please do that as well, if you submit a bugreport.
Download the radio script
A sample .radiostations file
Please note that compared to the old script which only spawned mplayer, you will now have three processes spawned (mplayer, a perl process for adding timestamps to mplayer output and a fork of the radio script for handling last.fm submission) if you enable last.fm submission (by adding your credentials). This version also leaves the radio.state file behind when you stop it, since it’s used for the resume feature.
Go ahead and break it!
Adding scrobbling support took less than a day, thanks to last.fm’s really simple and quite well-documented submission protocol and their quick response when I asked for a client ID. The only snag I hit, was with the length of a track, “l[0]” in the postdata. According to the documentation, this is optional for radio scrobbling, but in fact you need to pass it along, although you can just set it to zero. I guess my interpretation of ‘optional’ differs from their.
Grey java windows
A problem I’ve hit many times is the grey window java issue, where java-windows will be all grey and have no content. Danske Bank uses java for their homebanking solution and for every transaction a java-windows pops up. So this bug meant no homebanking for me (or rather, forced me to use a windows-based PC for paying my bills).
Today however, I stumbled across a mail on the awesome mailing list mentioning a tool called wmname that apparently solves this issue, by setting a proper netwmname… and lo and behold, this small (53 lines of C code) program actually made homebanking work again \o/. Just compile, install and run it with an argument (the name of your window manager, could be anything).
Is this awesome? (y/Y)
It is actually doable!
See DR, it’s not impossible to give people access to your media archives in an easy way. Please get your act together and start working on something like that instead of that lame web-based player and your sucky “Bonanza”-imitation.
Since I’m forced to pay a fee to you because of my internet connection, please give me (and everybody else, not just us “opensource freaks”) content for my money’s worth.
Pointless project of the day
I came across a link to Writeroom today. Apparently it is an application designed to give you:
- A full-screen window with a minimalistic text-editor
- No weird widgets, buttons or paperclips
- No automatic spelling and grammar corrections
- Menu-bars that only appear when you need them
- Support for different kinds of cursors. The standard mouse-cursor, a blinking/non-blinking bar and so on
- It runs either standalone or as part of other applications
- Saves to plain-text
- Choose your own fonts and colours!! ZOMG!
But wait, this sounds familiar right? I’m writing this in my favorite editor in my favorite terminal. Let’s see: A full-screen window and minimalistic text-editor? check. No widgets? check. No interference from spelling bees? check. No menu-bars unless you need them? check. Different cursors? check. Standalone and embedable? check. Saves to plain-text? check. Support for different fonts and colours? check.
Oh, and it’s free too!
Those who don’t know UNIX are doomed to reinvent it — badly
The worst thing…
The worst thing about Open Source Days [danish] isn’t choosing which talks to attend (I never have time for talks anyway). The worst thing is doing weird LaTeX hacks to get their logo placed correctly in the agenda…
Turns out there’s this cool environment for wrapping figures in text named ‘wrapfig’ (gee, who thinks up all these names) that you can use for positioning an image a little more intelligently than the default, left-aligned placement. Alas, said environment (or something else – I am by no means a LaTeX guru), doesn’t play nicely with tables and as the majority of the page is made up by the actual agenda in a table, that means the logo ends up whereever it fits; in this case smack in the middle of the page. A lost cause? Of course not! <leonidas>This is LaTeX!</leonidas>. Take a look at this beauty:
\AddToShipoutPicture{
\put(0,0){
\parbox[b][420mm]{530mm}{
\vfill
\centering
\includegraphics[width=60mm]{logo2008_small}
\vfill
}
}
}
[courtesy of the same guy who wrote the aforementioned blagpost, Jesper Nyerup]
Of course, you might have to fiddle with the actual placement of the parbox but as far as I could tell from my experiments, this will place the image whereever you want it, no matter what is above or below it layerwise. At the point where Jesper pasted that, I had been driven to the nastier corners, fiddling with boundingboxes and another parbox-hack, none of which worked remotely as well as this solution.
An ugly hack, nonetheless, don’t use it if you can avoid it.
Also, this requires you to include the eso-pic package in your preamble.
Also, if you happen to attend Open Source Days on saturday, by all means come by the Exherbo user stand where we will be happy to act like the elistist bastards people assume we are and tell you exactly why you shouldn’t use Exherbo just yet.
radio on the command-line
I got bored of remembering paths to playlists for streaming radio all the time, so I wrote a short script to do the job for me.
Rather than explaining what it can and can’t do, here’s some of the output from –help:
The following commands are recognised:
radio tag
plays the station associated with tag
radio info tag
shows information for tag
radio stop
stops playback
radio status
prints status
radio random
start playing a random station from your list
radio np
prints the currently playing track, if the stream supports it
radio
prints a list of stations. Use -v for detailed information
The script will fork, exec mplayer and then kill the parent so you won’t need to have the script running all the time. State is saved so you can get status info at any time (if you want now playing support in your IRC client of choice, for example), stop playback or switch station (if radio is already playing a station when you ask it to start playback, it will kill the old one first) and so forth.
The script needs mplayer, perl and the YAML perl-module. YAML is available from cpan and probably also from your distribution of choice.
The .radiostations file is a YAML-file with a simple layout:
tag: name: Name of the station desc: Description of the stations path: Path to the station's playlist (a .pls file, usually) stream: Misc. stream information.
The tag is what the script uses to identify a station, when you ask it to play one. It must be unique or a later station with the same tag will override the first one.
The radio script
A sample .radiostations file
The .radiostations file contain all SomaFM, DI.fm and SKY.fm stations and a few stations from DR (p1, p2, p3, boogie, barometer and electronica).
Note that the “Now Playing” feature is somewhat suboptimal. It reads the info from ICY, but not all streams use that and not all streams keep it updated. There is no general solution though, and for most sane stations (SomaFM and some DI and SKY.fm streams at least) it should work just fine. The DR streams won’t have np-support since DR sucks big time…
As usual, no guarantees or anything else. Use it if you want to :-)
There’s a similar shellscript [danish] written by Jesper Nyerup if you want to avoid perl and the YAML-module.

