Pro tip of the day

April 15, 2011

Just saw on Twitter: “C++ Tip: Avoid the blame for bugs by placing all your code in namespaces named after other programmers on your team.”

It’s not only the privilege of C++ coders: you can use it in any language which supports multiple namespaces.

Time to amaze your colleagues!

blog revived in 3D

April 13, 2011

Woa! It was quite a long time ago since I posted anything. I even forgot I had a blog. Well, time to start…

I got my hands dirty with Python & OpenGL (PyOpenGL) and started reading The Red Book. It’s now much easier to write fancy programs. What took days, now takes minutes. Back in the days you actually had to roll your own graphics library. It went something like this:

  1. Write a routine to display a point (pixel). It’s not difficult at all, but first you have to map 3D coordinates onto the 2D display. Then you can display it on the screen (preferably by directly addressing the video memory).
  2. by using your awesome point routine, you can draw a line pixel-by-pixel
  3. Ok, triangles next. All objects are made up of triangles, you know that, right? Even spheres.
  4. Still there? Good. Now we can create rectangles, cubes, spheres and so on. You have to build them up by using triangles. Sometimes it can be rather tedious.

We used to write it in Assembly, which further complicated things (especially x86 Assembly, which was a pain at that time (memory segmentation, too few registers, to name a few annoyances)). But anyway after writing these pretty basic things we have our shiny new library. It’s time to start working on funny stuff like animation, texture mapping, hidden surface elimination, transformations (scaling, translation etc.), lighting, shading… The list goes on. It’s a lot of work and maths (vectors, matrices, linear algebra etc.). And we’re still not cross-platform.

Well, that’s it for a start.

Metacity (According to that page, there is no Metacity homepage. While there might be some truth to it, the site also says: But this is a place where you can find out about Metacity. (emphasis theirs), so we can treat it as such.) is my current window manager, because it’s simple, relatively fast and doesn’t look like a Unix window manager from the ’80s. I don’t need the eye-candy Compiz Fusion provides (though there are some useful not-only-for-the-eyes features in it, I prefer speed) and it’s not fast enough, since I don’t have a fast video card. Metacity also supports compositing, but that’s slow too.

One thing I always wanted in Metacity (and, for that matter, in every window manager) is forcing specific applications to specific workspaces. Metacity is meant to be a somewhat minimalist WM, so it doesn’t support placing windows according to user-definied rules. Devil’s Pie to the rescue! It is:

A window-matching utility, inspired by Sawfish’s “Matched Windows” option and the lack of the functionality in Metacity.

Just what poor Metacity users need. Now one can do

(if (is (window_class) "Firefox")
    (begin
      (set_workspace 2)
      (undecorate)
      (maximize)))

to constrain Firefox windows to the 2nd workspace, remove the borders (i.e. the WM decorations) and maximize it. Or

(if (and (is (window_class) "Skype")
         (is (window_role) "Chats"))
    (set_workspace 3))

to send Skype chat windows to the 3rd workspace.

It can even resize the windows, make them sticky or transparent &c. Basically everything what the WM can do. While the included documentation is very brief (to say the least), make sure you read it. There's a good article about its configuration (and supported expressions + examples) on this page. I won't repeat it here. Basically the configuration file format is s-expression based, so I can almost feel at home.

Monty Python on YouTube

January 26, 2009

In case you didn’t know: the Monty Python team put some of their sketches online. See their YouTube page. Quote from the page:

For 3 years you YouTubers have been ripping us off, taking tens of thousands of our videos and putting them on YouTube. Now the tables are turned. It’s time for us to take matters into our own hands.

We know who you are, we know where you live and we could come after you in ways too horrible to tell. But being the extraordinarily nice chaps we are, we’ve figured a better way to get our own back: We’ve launched our own Monty Python channel on YouTube.

No more of those crap quality videos you’ve been posting. We’re giving you the real thing – HQ videos delivered straight from our vault.

What’s more, we’re taking our most viewed clips and uploading brand new HQ versions. And what’s even more, we’re letting you see absolutely everything for free. So there!

But we want something in return.

None of your driveling, mindless comments. Instead, we want you to click on the links, buy our movies & TV shows and soften our pain and disgust at being ripped off all these years.

I wish them good luck! It’s time to order `The Complete Monty Pythons Flying Circus – Collectors Edition Megaset’.

Some of my favorites include:

CLOS hint #1

January 26, 2009

Keene’s `Object-oriented programming in Common Lisp’ is the book generally recommended for starting with CLOS. While it’s a very good book and I too recommend it, it was written before the Common Lisp standardization process was finished. Therefore it has some inconsistencies (but so few that you don’t actually have to worry about them). One of them is specializing describe on page 40 (and 41, 49, 56 and 241):


(defmethod describe ((l lock))
  (format t "~&~S is a lock of type ~S named ~A."
          l (type-of l)
          (if (slot-boundp l 'name)
              (lock-name l)
              "(no name)"))
  (values))

This won’t work, since describe is an ordinary function, so you can’t specialize it. You have to specialize describe-object instead, which takes a stream as its 2nd argument. Apart from that it’s the same:


(defmethod describe-object ((l lock) stream)
  (format stream "~&~S is a lock of type ~S named ~A."
          l (type-of l)
          (if (slot-boundp l 'name)
              (lock-name l)
              "(no name)"))
  (values))

See the documentation of describe and describe-object.

Again, this is a good book on CLOS and the code examples are clean. Also, I recommend Practical Common Lisp by Peter Seibel, though it’s not a book on object-oriented Common Lisp, but a general introductory book to the world of Common Lisp.

Follow

Get every new post delivered to your Inbox.