Tuesday, September 08, 2009

Duck Typing

So, in Python there's this concept of Duck Typing. First time I read about it (shortly after getting into Python,) I passed it off as a curiosity. No idea how to take advantage of the concept.

So now I'm taking a Java class (mostly because the Uni doesn't offer Python classes.)
import university

class Python:
    pass

university.CompSci.add(Python)
No not that kind of class!

Well, apparently in Java when you have a function that could just as easily work on int arrays as String arrays as float arrays, you need one copy of that function for each type. Which means in certain situations you have two otherwise identical functions (and I mean character-for-character identical, as in Ctrl-C, Ctrl-V identical, aside from the function signature.

So I'm just staring at this pair of functions now, and I really ought to be wrapping up the assignment, but I can't shake the feeling that this is wrong.

Sunday, September 06, 2009

Open Letter to all webcomic artists

And those with any other periodically updating website, and especially if it doesn't get updated on a regular basis.

Use RSS or Atom feeds on your website. If you have a webcomic, make a new entry for each new comic. Link directly to the comic. If possible and practical, inline the image directly into the entry.

Now, you don't have to roll a custom RSS feed. You could simply open a blog somewhere (Blogspot, Wordpress whatever floats your boat,) and drop a new post in when you update the comic. Hell, even Twitter would work

Now, why do I emphasize those sites that update infrequently? Nothing kills the mood like hovering over a bookmark and wondering to yourself "Is this even updated? Am I just wasting my time?" There are comics I read that update like clockwork and have no RSS feed. Glance at the clock and at a certain time chances of the site having been updated increases greatly. But there are others that post new pages seemingly at random. These comics actually have a special tag in my bookmarks: Sporadic. It exists especially for comics that are floating in the purgatory between irregular updates (which I check on Sundays) and comics that have been placed on Hiatus (which I check about every 6 months, and leave a note in the bookmark the last date/comic number I read.) I check this grouping of sporadic comics sporadically. A lot of them probably have more updates by now, but I can't remember where I left off. Shame really, since many are good.

Remember, with RSS feeds you subscribe and leave them alone, because they tell you when there is new content. You never have to look at an RSS feed and wonder if there's anything new (unless your feed is broken. Yeah, I'm looking at you Altermeta, your RSS updates, but something is wrong, new posts get inserted halfway down with bad publish dates.)

So there. Keep your readers. Bring them back regularly to bask in your stunning artistic prowess (and possibly some adverts,) build an RSS or Atom feed for your comic today.

Tuesday, August 25, 2009

Getting sources, source keys, and package lists out of an installed Ubuntu from a Live CD

When reinstalling Ubuntu, you may often find a large quantity of time becomes taken up afterwards as you look for applications that you had installed but failed to install after you finished reinstalling the OS.

There are ways to export and save this data before running reinstalling, backing up /etc/apt/sources.list is most commonly referenced, which gets you all the repositories you had, but you still have to reinstall the individual packages, and obtain the verification keys for them.

From a working system, you'd just

# If you want to preserve deinstalled packages, just omit the grep command 
$ cp /etc/apt/sources.list ~/sources.list
$ dpkg --get-selections | grep -v deinstall > ~/packages.list
$ sudo apt-key exportall > ~/sources.keys

In a Live CD, a situation I recently found myself in (I borked GRUB and decided that halfway through the potential fix was a good time to prepare for a possible reinstall,) it's a little harder. Those commands will get you the sources, packages, and keys from the Live CD rather than your install. Obviously, /etc/apt/sources.list is a simple copy-to-backup-partition away, but the other two are behind applications.

The solution (hijacked from ubuntuforums user 5-HT and pieced together with this Upgrade or Reinstall post by Daniel Bo) is to chroot into the old install, and then run those commands. Here's how to do that:

# /dev/sdb2 and ext3 was my install partition and type, replace those values with your own.
ubuntu@ubuntu:~$ sudo mkdir /mnt/root
ubuntu@ubuntu:~$ sudo mount -t ext3 /dev/sdb2 /mnt/root
ubuntu@ubuntu:~$ sudo mount -t proc none /mnt/root/proc
ubuntu@ubuntu:~$ sudo mount -o bind /dev /mnt/root/dev
ubuntu@ubuntu:~$ sudo chroot /mnt/root /bin/bash

Now you are root in your install partition. Now you need to mount the partition that you will store these on. If your home directory is on a different partition, you can use that/ If it's not, get another drive and back up your home partition to that drive as well as these files. You can't use nautilus for this, so here's what I did as a hint:

# Again, /dev/sda1 is for me, replace that value with the one applicable to your system.
root@ubuntu:~$ sudo mkdir /media/disk
root@ubuntu:~$ sudo mount /dev/sda1 /media/disk

Once you have the partition mounted (I'm going to assume /media/disk as described above,) you can simply run the commands:

root@ubuntu:~$ cp /etc/apt/sources.list /media/disk/sources.list
root@ubuntu:~$ dpkg --get-selections | grep -v deinstall > /media/disk/packages.list
root@ubuntu:~$ sudo apt-key exportall > /media/disk/sources.keys

If you have any other files in the filesystem you need, such as apache2 configs or the /etc/hosts files, now is a good time to get them.

Now, when you have your fresh install, you can restore the data by replacing or adding to the new sources.list file (remember to change the lines if you changed Ubuntu versions,) adding the keys back into apt, and re-installing all your packages. Ironically, the hardest part now (possibly) is the sources file if you need to alter it. If it's the same, just drag it into the Third-Party tab in Software Sources app (System > Administration > Software Sources) and have it add them.

The keys file can be done the same way, except in the Authentication tab.

Now that the repositories and their keys have been added, reinstall all your packages with:

$ dpkg --set-selections < /path/to/packages.list && sudo apt-get dselect-upgrade

Or with Synaptic, File > Read Markings and press Apply.

Saturday, May 16, 2009

Simple Extension implemented in Shimmie core

Simple Extension functionality was imported into Shimmie core earlier this week. If you have this extension active, PHP will complain that you can't define SimpleExtension twice.

There were some changes during the import due to some problems with the Shimmie forum (broke during upgrade to phpBB3) and Shish ended up re-implementing it in core rather than performing a true import.

Unlike my version, which merely forwarded execution to functions of the same name as the event, this implementation prepends "on" and removes the trailing "Event." So an event PageRequestEvent will call a function onPageRequest.

This method, however, removes the need for the acrobatics my version was performing to prevent the forwarding from calling the receive_event and new i_am functions. The event_method_callable function is thus not needed and was not used.

I have not yet updated the source of my extensions that used this, though Shish has already made most (if not all) of the core and core-maintained extensions use it.

Thursday, February 26, 2009

KFI Internet Stream URL

Update (2010-07-22): Recently KABC also changed their streaming method. Neither station can be played in a dedicated player now.




Update (long ago): About a week ago, Clear Channel updated their internet stream again, this time to a flash based thing. Unfortunately, in this update they no longer serve the XML expected by this script to the Sonos user-agent.

If anyone has a way to grab the stream URLs from the new player, please leave a comment.




If you've been trying to play the KFI radio stream in an external media player like totem, mplayer, or VLC, you've no doubt suffered annoyance at the number of hoops you have to jump through to acquire it. Further, the url needs to be refreshed every few hours to get the new authorization code.

Luckily, there's a solution. If you set your User-Agent to "Sonos" when you go to the KFI player it will send an XML file containing the stream URL instead of redirecting to the new browser player.

You can change your User-Agent string in Firefox with User Agent Switcher, or you can fetch the url with
wget -U "Sonos" http://www.kfi640.com/cc-common/ondemand/player.html
.

Once you have the file you can just copy the URL into the player of your choice.

Or you can use a Bash script that wget's the file, parses out the url with sed, and loads the results into totem.



I can't claim complete authorship of the bash script, as I found a version on a forum first, and have only subsequently made modifications to keep it working through Clear Channels streaming changes and to add a switch for another station I listen to.