Posts about programming (old posts, page 3)

2004-11-15 02:20

On speaking and slides

As I mentioned before, I was at the 3rd CafeLUG event on friday and saturday.

It was a pretty large event, roughly 1300 pople, 63 conferences.

I had two of my own, and here's how they went:

Friday: The PyQt/PyKDE one. Audience: about 50 sitting, 15 standing. I had no time whatsoever to prepare this. But I was luky enough to have someone (thanks Cristian!) lend me a notebook, and so I spent the previous conference (pf/OpenBSD) working on mine :-)

I kept it on a low level, nothing too complicated, since I only had 60 minutes, but the audience seems to have liked it. Or at least they found my attempts at explanation funny.

Anyway, noone was disgusted enough to tell me to my face, and I had a general feeling of it having been good.

I was able to show a quick do-nothing app in 20 lines of code, and show signals and slots, and really really push the idea of interpreted languages as better for hobby programming (which I think is the right path). Not too many questions right then, but about a dozen kids attacked me with questions on the hall after leaving.

Saturday: My generic KDE-for-beginners speech. Audience: 100 sitting, 10 standing. I was a bit too heavy on the philosophical, but it went down nicely. Several of the guys from friday's PyQt session were there, so more evidence it didn't suck too badly.

It was fun, people were surprised by Ogg-ripping from Konqueror as usual, some fun, several questions.

All in all, a nice couple of sessions, and I think I did well, which encourages me to do it more often. Who knows :-)

2004-11-10 15:16

What linux needs on the desktop is...

... oh, screw it, why not say what it doesn't need? It's better for my blood pressure.

  • It doesn't need Be refugees whining about how BeOS was so awesome and Linux desktops suck. You know what, guys? If BeOS was so cool, and Linux sucks so much, how come BeOS is dead? Now put a sock in it and go practice your OS-necrophilia.
  • It doesn't need windows users saying "it's not like windows, it sucks". If Linux was just like windows, you would say that there is no reason to switch, so put a sock in it, because you can't have it both ways.
  • It doesn't need Mac users saying how there's no point working on it because OSX is already as good a unix desktop as there's gonna be, so why bother?. Put a (designer) sock on it, because in order to use OSX you have to buy an ungodly expensive (except the 12" ibook, that's kinda cheap and cute) computer that provides only adequate performance, and I am a cheap bastard.
  • It doesn't need old unix gurus explaining how there's no need to work on KDE or GNOME because Window Maker is lighter, and all that's needed is a way to keep their xterms sorted. Put a sock in it, because xterm sucks, Window Maker is featureless, and you can't do anything useful for a regular user with just xterms and Window Maker, so you are comparing apples to apple orchards.

Most of all, it doesn't need any "What linux needs on the desktop" editorials.

On other news, I will be speaking about Linux on the desktop at the UADE in Buenos Aires, Argentina, this saturday, and about PyQt/PyKDE programming this friday.

More information at the CafeLUG site. If you read it here and mention my blog, I will pay you a beer (offers limited to a maximum stock of three beers).

2004-10-13 16:24

On other news today...

Python code really doesn't look good on planetkde, so follow the link to my page to see it right if you are there ;-)

2004-10-13 16:03

Adventures in Hi-Fi

As I blogged earlier I am writing a game (and yes, it's pretty much playable already).

One thing I didn't mention is that I never wrote a game before. Yeah, I know everyone does it as one of his first projects, but I never did.

So, there are some things I really have no clue about [1], like sound and moving graphics around.

For the graphics stuff, QCanvas is just fine and dandy, but to make things bloop and warble and squeak when the time is right, I found Qt's sound support somewhat depressing.

Come on, NAS? Who uses that? And what about music? I had no idea.

So, I started trying to follow one of my leading principles of development: find a way to make it Someone Else's Problem (TM).

The usual way to do that is finding a library that handles the problem, write minimal glue, stick it to the side of the program, tell the program that's his new arm, and forget about it quickly.

Here's what I found.

Mi Dios!

I thought I should start by adding one of those annoying little tunes every game has. It's just a game tune, I don't want to have to include a 3MB OGG file for it, so I wanted an instrument-based format.

I remembered MIDI tunes. You may know them as ringtones nowadays, but they used to be just cheesy tunes generated by your SBPro's FM generator, not your phone.

In fact, I remember having a little proggie called playmidi, that would do that in Linux.

Well, it seems that in the past few years, either sound cards have forgotten how to play them, they fell out of fashion, or something, because the only things I found that could play MIDI are monstrosities that require a 9MB digital instrument set. And how was I to include that along with my 25KB game???

So, what's next? I had a C64, so...

MOD me up!

MOD files are like MIDI files, only the MOD includes it's own instrument set, called samples, and instructions on how to repeat and alter those samples to make a tune.

Good news: there are nice-sounding, funny MOD files that are about 30KB in size.

Better news: There is a popular library to play them! It's called Mikmod, and your distro has it (and it's a dependency for KDE's multimedia packages too).

Even better news: It has support for playing simple sounds (samples in mod lingo) by calling a couple of functions.

Awesome news: It includes a software mixer so you can just tell it to play this, then play that, then that, and a tune in the background, and everything sounds at the same time.

So, we have a winner. This baby can handle everything I need for the game!

But... is that a snake in your pocket?

I can't find a Python binding for it. I am sure as soon as I post this article someone is going to come up and tell me, here they are, moron! But I just can't find any.

So, I decided to do something I wanted to do already and learn to use Pyrex. Pyrex is a tool to write python extensions, with almost-free access to C libraries, in an almost-python language (only minor syntax differences).

That way, I could write a Python module to use Mikmod.

You know what? It was almost scarily simple [2]. I didn't wrap all of Mikmod [3] because I don't need it, but now I can do stuff for games and apps almost trivially.

Even more: Pyrex has awesome distutils support, so building the extensions, usually a pain in the rear, is trivial (mostly you just copy and delete stuff, with some search and replace).

One thing I found I did nicely is this: Mikmod requires you to call Mikmod_Update every once in a while so it fills the soundcard's buffer with stuff to play. If you don't, it skips.

So, I just started a thread that loops and takes care of it. You don't even have to know about it to use the extension. Oh, sure, if your Mikmod is not threadsafe, it breaks. Well, get a decent Mikmod package, then.

How does it look?

Here's a whole noisy proggie

#Load the modules
import mikmod, time
#Init the library
#40 voices, 20 for music, 20 for random sounds (overkill)
#Enable sound, starts the thread that pushes sound, too

#Create a module, that is, a music track

#Load two samples, just a couple of noises

#Start playing the song

#For the duration of the song, each second, make some noise


#Close the mikmod library, stop the thread, etc.

[1] As if that would surprise anyone!
[2] On the other hand... waiting for stuff to compile... how quaint.
[3] Actually, I am wrapping almost all of Mikmod, I am just not exposing it to Python because I don't need it.

2004-09-24 12:10

A good web-based password changer?

Does such a thing exist? There are dozens, but none seems very good.

By good I mean:

  • Has been maintained more recently than 4 years ago.
  • Works via PAM (and just plain works)
  • Is not awful to install
  • Doesn't make you do weird stuff like running a SUID httpd (yes, I actually saw that once)
  • secure (audited?)
  • readable sources
  • runs as a non-privileged user.

Usually this would be a SUID root cgi-bin, which is somewhat scary, and it would seem to me unnecessary.

Since the user will provide the current password, it should be possible for a non-privileged process to first switch to the desired user and then change the password, right?

Maybe someone can tell me. Or do I have to write it? I mean, it's going to be a python CGI if I do, and noone's gonna like it ;-)

2004-05-21 20:21

Qmail Address Lister

It has been way too long without posting a longer item, so... I recicled a script I wrote for a customer, and here it is:

A python script that lists (almost) all email addresses in a qmail system.

Also, a slightly tweaked CSS, thanks to Georg!

2004-05-09 15:42

Hard Python question

I am trying to do something which is, I think, pretty cool, in python.

However, I like showing things working, and I am having troubles with the last final step on what I am trying to achieve.

Since I know a few better python programmers read this...

Suppose I have this:

def fun(self,x):

class C:


What code should be in fun() so that it figures out if it has been called as C.a or as C.b?

I am thinking something like reading the higher step in a backtrace, but I don't know enough python to figure out how to do that.

2004-03-23 16:48


In a whim, I checked out kdebindings/dcoppython from KDE's CVS.

I see the README: dcopython is broken

Then I said to myself: maybe I can fix it. And you know what? It seems to be not broken! :-)

At least for simple data types, that is.

dcoppython lets your python program become a DCOP server or client.

A DCOP server is capable of being controlled by KDE's kdcop, and is a very simple way to make your application externally scriptable.

A DCOP client is something that contacts a DCOP server, so that means you can control and script KDE applications (or other DCOP servers) from python scripts.

The neatest thing here is that this stuff doesn't require Qt!

I intend to use it to make some of my apps externally scriptable without PyKDE.

2004-03-08 11:51

Goats and cars

There's a problem often used to show the unintuitive nature of probability, which has become very well known.

In that problem a contestant in a gameshow has to choose between three doors (A,B,C), on one there is a car, on the other two are goats.

After the contestant chooses, the host opens another door and shows a goat.

Then, the host offers the contestant the chance to switch his closed door for the other closed door.

Should he switch?

The intuitive answer is "it doesn't matter", because there's two doors and one car, so it's a 50-50 chance.

But the real answer is that it does matter, because it's a 33-67 chance!

While it's simple to show this to be the case to a statistically-educated dude, it's somewhat harder for a layman.

In fact, I think most explanations suck.

Here's my shot at it:

If you were offered the chance to switch between your closed door and the other two closed doors, would you take it?

The intuitive answer to that is of course, yes, because it's 67-33 for the car to be on the other two doors.

Now, regardless of where the car is, can the host open one of those two doors and show a goat? Of course, yes.

So, would you feel your odds went down because the host showed one of your two closed doors had a goat behind it? No, because he could always do that, and you know there was (at least) one goat there!

So, what difference does it make if one door is open or not?

I don't expect this to convince anyone, really, but just in case, I have a python implementation of this problem ( :-) if anyone wants it, if empiricism can convince you ;-)

Contents © 2000-2019 Roberto Alsina