When a person can no longer laugh at himself, it is time for others to laugh at him.
Thomas Szasz, "The Second Sin"

cygwin essentials

July 21st, 2010

This isn’t really appropriate for a blog entry, because it’s bound to be updated over and over, but I need a place to keep these notes.

Essential packages (not including pre-selected):

  • xinit. Effectively what is called Cygwin/X. (Creates a new shortcut in the start menu called XWin Server that you probably should stick in your startup list.) With this you can run gvim, xterm etc.
  • file
  • git, gitk
  • openssh
  • ping
  • python
  • rsync
  • vim, gvim
  • wget
  • zip
  • make/patch

Decent terminals:

  • mintty
  • puttycyg (ie. putty modded to use locally) You have to get this one separately, but it has a nicer feel to it imo.

Rome on foot

July 8th, 2010

This summer I spent 4 days in Rome in June. As with vacations in general, I did quite a lot of walking. At times it seemed like more than just “a lot”, so I traced my walking on a map so that I could figure out how much “a lot” really is. It turns out that you can cover pretty much all the sights in Rome on foot, they’re not that far apart. A walk would take anything from 1.5h to 2.5h. It turns out I would cover up to about 13km in that time. In three and a half days (also took a half day trip to Ostia Antica) I did about 40km of walking.

rome_on_foot

Tele2: so cheap it hurts

June 30th, 2010

In English the word “cheap” has two meanings (probably more than two, but let’s not get into that right now). Thus, when someone describes a thing as cheap you should hesitate to assign to it the more laudable of the two meanings, that of being good value for money. Because it may also be that the opposite meaning is sought, namely little value for little money.

I imagine this being the reasoning which compelled Tele2 to choose their slogan so carefully: “born to be cheap”, which they apparently use untranslated in every country where they operate.

The fact is that if all you want is an internet connection at home then there is no cheaper option than Tele2 on the Dutch market, at least to my knowledge.  Wherever you may go you will end up forking over 20 bucks per month, plus the 5 bucks ransom paid to would-be roadside bandits KPN for their generous permission to use your phone line. What you get in return for the 25 may vary, but noone will give you a better price. At least there is no sign-up fee, or installation fee, or additional surcharge on the precharge etc.

The 15th of May contact is made, Tele2’s website affirms they are able to connect me at my new address. I immediately dispatch the order form. A week or so later, not having heard so much as a dolphin sqeak from Tele2, I call their support department. They’ve never seen my order. What’s more, they’re saying there’s another customer at my address (previous tenant probably) whose personal information must be wiped from the record before they can take my order. This could take as long as a week.

A few days later, just as a sanity check, I try to re-make my order on their website. The order number printed on the screen is 0. Their system is hosed. It was probably like that the first time, but I failed to notice amid all the other output. So I call again. This time they have to do some deep digging to ascertain the fitness of my phone line vis a vis the yadayadayada. But at least they have my order now, per phone. Unless they lose it we’re one step ahead.

A week rolls by. I finally get the letter in the mail, I’m proud to call myself Tele2’s newest customer. The order is in, the letter has been sent out, surely it’s imminent now. I have a tentative activation date on June 15.

Another week and a half and the modem arrives. Albeit in many small pieces and totally banged up. The package is rejected and Tele2 is tasked to send a modem that has the plastic shell intact. A week before the end of June it arrives, all is set now.

To my great satisfaction, DSL service has come such a long way that you don’t need a technician to come to your house anymore, they send you printed instructions instead. You pay less and you get it sooner. So I set it up as per the instructions, only to realize that they’ve sent me all the pieces except the actual plug that plugs into the telephone socket. Oh, it’s in the picture, but it’s not in the box, why would it be? Don’t you like when they get you involved with the problem solving too? I bet you can figure out where to buy a plug like that, you clever devil you.

Alas, the plug fits, but the modem works not. 20 minutes on the line with the support guy leads me to the illuminating realization that just because there are telephone sockets in the apartment doesn’t imply they are connected to anything. So now they have to send an engineer anyway, albeit Tele2 is paying for it.

The guy termed the engineer is precisely what I expect him to be, a guy from KPN, the overlords of the telephone networks. He goes to work downstairs in the entrance hall. Says the phone line reaching as far as the apartment building works just fine, to which I ask him about the phone sockets in my apartment. “No no, that’s not up to KPN, that’s up to you or your provider, Tele2. We only check that it works up to this point.” How terribly helpful of you. What they call the “ISRA punt” is a thick blue wire, the master phone line into the building. This goes into a gray connection box, which provides a connection point for every apartment in the building. Some of the wires going up to the various apartments are plainly disconnected from the box entirely, including mine. It might just be a matter of trying all the disconnected wires into my socket, one by one, and see if that makes it work. If I could borrow the guy’s tools for 10 minutes I could try that. But he left.

So I’m back on the phone with Tele2. It turns out they don’t give a rat’s ass if the phone line in your apartment works (even though, I should mention, they’re also a telephone provider), just as long as it works in the basement of your building where you may plug in at your convenience. So now I have to get their technician to come afterall, paying the 69.95 installation cost. This on top of probably 30 bucks I’ve already spent calling their not-at-all-cheap support line a dozen times.

It’s six weeks since I made my order and I still have nothing. This isn’t a phone line in rural Afghanistan, it’s in The Hague. I have *several* Tele2 wireless networks in range of my laptop. I just can’t get mine.

pretty printing for everyone!

April 25th, 2010

I’ve been toying with the idea of trying my hand a generic pretty printer module for a while. Lately I’ve had to deal with cyclic object graphs and things like that, where having a dump of the data is pretty handy. Granted there is a pprint module in the standard library. But what it does is format and print iterables (lists, dicts, tuples..), it doesn’t attempt to show you the contents of an object. Of course, when you’re messing with objects this is very useful to have.

So I thought that I would build a recursive iterable that I can give to pprint. Here’s an example:

class Node(object):
    classatt = 'hidden'
    def __init__(self, name):
        self.name = name
 
a, b, c, d = Node('A'), Node('B'), Node('C'), Node('D')
a.refs = [b, d]
b.refs = [c]
c.refs = [a]
d.refs = [c]

Download this code: pretty_printing_object.py

This will give you:

{'__type__': '<Node {id0}>',
 'name': "'A'",
 'refs': [{'__type__': '<Node {id1}>',
           'name': "'B'",
           'refs': [{'__type__': '<Node {id2}>',
                     'name': "'C'",
                     'refs': ['dup <Node {id0}>']}]},
          {'__type__': '<Node {id3}>',
           'name': "'D'",
           'refs': [{'__type__': '<Node {id2}>',
                     'name': "'C'",
                     'refs': ['dup <Node {id0}>']}]}]}

Download this code: pretty_printing_output.py

There are two things being shown here:

  • node C is reachable through ABC and ADC.
  • A takes part in two cycles: ABCA and ADCA.

It would be nice to have a way to see this from the output. So aside from the object attributes themselves there is also a __type__ attribute which tells you the type that you’re looking at. And it has a marker of the form {id1}, where id1 is an identifier for this object, so that you can see where it pops up in a different part of the graph.

Now, suppose we follow A to B to C and then to A. We are now seeing A for the second time. Instead of printing the object again we print a duplicate marker: dup <Node {id0}>. The identifier is supposed to be vim * friendly, so if you pipe the output to vim, put the cursor over it and hit * (also might want to do set hlsearch) then you’ll see it light up all the other instances of it in the graph.

pretty_printing_gvim

Well, that’s all for now. It’s definitely not the last word in pretty printing, but it’s useful already.

I thought maybe github’s gists would be appropriate for something like this:

lessons from “Coders at work”

April 16th, 2010

I already mentioned Coders at work in an earlier entry. The point of this one is not to write a review, but to make a note for myself of what I’ve gotten out of the book. I think I could do better to read more books with a pen and a pad so I have a better chance of exploiting the content.

So these are notes to myself. I wouldn’t take it upon myself to summarize a more general listing of notes that would somehow apply to the average person, because I think we’re all in very different places in the universe that is called “learning to program (well)”, and every person has to figure out for himself what he most needs to learn relative to where he now is.

Advice: Read code

Read other people’s code, “open black boxes“. This is something I never really do, I should start. Just take some codebase and check it out, get used to the practice. Reading code is not the easiest thing to get into, so here are some tips:

  1. First, get it to build.
    Sometimes everything you have to do to build it already teaches you a number of things about the codebase. And once you have it built, you can start making changes to it and try out little things dynamically.
  2. Read while building.
    Making builds for any codebase can be hairy and painful, so parallelize this activity with code reading. Great way to use the time you’d otherwise waste in between debugging the build.

Advice: Write unit tests for new library

You’ve found a library for something that you’ve never used before: how do you figure out how to use it? Write unit tests. Some libraries have bad unit tests (or no tests) to begin with, so it could be a way to improve it. In any case you can test your basic hypotheses of how the library works.

Ideas to investigate

  1. OO and classes vs prototypes (JavaScript).
  2. “There is a lack of reuse in OO because there is too much state inside”. Libraries must expose too much of their innards through APIs, functional programming model should be better at this.

Pointers

Articles:

  1. Richard P. Gabriel – Worse Is Better

Blogs:

  1. How to read code – a primer

Books:

  1. Douglas Crockford – JavaScript: The Good Parts
    In the absence of the book, Crockford’s lecture series on JavaScript is probably a good start.
  2. William Strunk, Jr. and E.B. White – The Elements of Style
    For writing better English.
  3. Steve McConnell – Code Complete
    On software engineering process and best practices.
  4. Gerald Weinberg – The Psychology of Computer Programming

Talks:

  1. Joshua Bloch – How to Design a Good API and Why it Matters