leah blogs: February 2005

28feb2005 · Kashmir

With the recent announcement of Amrita2, I became interested in Ruby templating engines again.

Since September 2004, I’ve been using my templating engine Tangerine (small example) and have been quite confident with it. Unfortunately, the code became quite a mess and certain things (most notably, accessing the object of a higher block) were simply impossible (without extremely crude hacks using local variables, that need a ugly syntax then). In short, you couldn’t use Tangerine if you didn’t write it. :-)

Therefore, I’ve decided to largely rewrite Tangerine, and the result is now known as Kashmir (following my tradition of naming templating engines after Led Zeppelin songs…).

Kashmir tries to walk on the small path between the mess of raw evaled-ruby like ERB (you wouldn’t believe what kind of problems people have with that) and the clinical sterileness of data-driven templating like Amrita. I think I did that pretty well, though I’m not yet totally finished.

Let’s do a quick comparision:

ERB (+ 0 lines Ruby):

Not done:<br />
<% @not_done.each do |@item| %>
<%= check_box("item", "done", "onclick" => 
      "document.location.href='/todo/toggle_check/#{@item.id}'") %>
<%= @item.description %>
<%= link_to("Edit", :action => "edit", :id => @item.id) %>
<%= link_to("Destroy",
            { :action => "destroy", :id => @item.id },
            :confirm => "Are you sure you want to delete this entry: " +
                        "#{@item.description}") %>
<br />
<% end %>

Amrita2 (+ about 30 lines of Ruby):

Not done:<br />
<div id='not_done'>
   <input id="item_done" name="item[done]" type="checkbox" value="1" />
   <span> </span>
   <span id='description' />
   <span> </span>
   <a id='edit_link' href="/todo/edit/">Edit</a> 
   <span> </span>
   <a id='destroy_link' href="/todo/destroy/">
   Destroy</a> 
</div>

Kashmir (+ 5 lines of attr_reader; untested as I don’t do Rails, but you get the idea):

Not done:<br />
^not_done.each{
  ^(check_box("item", "done", "onclick" => 
      "document.location.href='/todo/toggle_check/#{id}'"))
  ^description
  ^(link_to("Edit", :action => "edit", :id => id))
  ^(link_to("Destroy",
            { :action => "destroy", :id => id },
            :confirm => "Are you sure you want to delete this entry: " +
                        "#{description}"))
<br />
}

That’s it. Fairly readable and still powerful enough not to stray pure ruby all over the place. (And please note that the Rails API was made with ERB in mind.)

Another interesting thing is that, unlike ERB, Kashmir compiles the templates into Procs for faster execution. A small benchmark for 10,000 expansions of a bit bigger template:

Tangerine       9.748724
Kashmir         4.073861
ERB            11.613445

I’ll release this week, hopefully. I especially want to add a “passive API” (weird term, I really think it’s active) as described in the Amrita2 README.

require "amrita2/template"
tmpl = Amrita2::TemplateFile.new("template.html")

tmpl.expand(STDOUT) do |m|
  # amrita2 passes a Module compiled from the template
  # with methods for dynamic elements.
  m.title("hello world")
  m.body("Amrita is a html template library for Ruby")
end

NP: Led Zeppelin—Kashmir

26feb2005 · iScroll2

Paul Battley told me about this nice extension for Mac OS X:

iScroll2 is a modified trackpad driver that adds two-finger scrolling capabilities to supported pre-2005 PowerBooks and iBooks on OS X 10.3 (“supported” meaning those which have a “W-Enhanced” trackpad, including most AlBooks and recent iBooks).

To enable scrolling mode, just place two fingers on your trackpad instead of one. Both fingers need to be placed next to each other horizontally (not vertically). Some people get better results with their finger spaced a little bit apart, while others prefer having the fingers right next to each other.

Very cool, though I still prefer a real wheel-mouse.

NP: Dan Bern—In God’s Time

26feb2005 · iRaki

Mal wieder Quotes bloggen:

Apple stellt jetzt ja auch Schnaps her: iRaki.

Auja, tot muss ich keine Hausaufgaben mehr machen!

Uns gehts doch abnormal gut: Du hast Internet, was zu essen…In der Reihenfolge ists wichtig.

LSD LSD LSDAP…Ist das von Dandser?

Und geht nicht wieder Wasserpfeife rauchen…!Nee, heute gehen sie richtig kiffen.

NP: Dan Bern—Cure For AIDS

23feb2005 · Grabbing SXSW 2005 music

See you in the Pit, a weblog about SXSW 2005 that daily posts fresh music by the performing artists recently refered to this giant podcast by Dan Budiac that links to over 2.3 gigabytes of music.

I wanted to get quite some of them. :-)

Some quick tries with iPodder were unsucessful, though. I don’t want to get all of this stuff. Fortunately, there is a .m3u available too; that is more easily handable with ordinary tools.

The method I do it now is:

  1. Import the list into iTunes.

  2. Pre-listen to all “interesting looking” tracks.

  3. Toggle their “playability”, to mark them as listened.

  4. Move them to another list, if you like them.

  5. Export the list to a text-file and wget as hell. :-)

NP: Harvey Danger—Carlotta Valdez

21feb2005 · Toki Pona

Alexander Kellett showed me Toki Pona, “the simple language of good”.

Toki Pona is an easy, small, artificial language with a minimal vocabulary of only 118 words. I think I totally got hooked :-) I have been translating stuff in my head to Toki Pona for the whole day now, even though I only have heard about it yesterday. (That’s not true actually, I’m pretty sure I’ve stumbled on above website already, but I didn’t read it too closely.)

The funniest section of the site is probably angst-ridden teenage poetry:

Even mediocre, angst-ridden teenage poetry can be expressed in Toki Pona:

mi lon pimeja.
waso ike li tawa sike lon lawa mi.
pipi jaki li moku lili e noka mi.
mi wile e pini.

I sit in darkness.
As evil birds circle my head.
And cockroaches nibble my toe.
I hope for an end.

Learn Toki Pona!

toki pona li toki pona. :-)

NP: Dan Bern—God Said No

19feb2005 · TinyWM

I just stumbled on this wonderful small window manager, TinyWM by Nick Welch, which is only about 60(!) lines of C long:

TinyWM is a ridiculously tiny window manager implemented in nearly as few lines of C as possible, without being obfuscated or entirely useless. It allows you to move, resize, focus (sloppy), and raise windows – that’s it! TinyWM’s main purpose is to serve as a quick example of some window manager programming basics.

Somehow made me change my mind about the complexity of X11. :-) Nick Welch is (or was?) related to Kahakai and Waimea, two other, “big” windowmanagers, too.

He also provides a nicely commented version.

NP: Dan Bern—Black Tornado

17feb2005 · On Groupware

With the announcement of Hula and JWZ’s writing about it, it seems to get modern again to blog about “groupware”.

I think, the way web-based groupware like Hula (which really is webmail and a calendar turn-key ready) and, for example, PHProjekt (just taking that because I already tried it) work is wrong. To make groupware usable to programmers, it must be accessible by other means than the WWW.

Don’t get me wrong, I certainly like a WWW interface for access from some other box, but on my main computers, I want a more convenient and better-integrated environment.

Also, and this requirement is impossible to do with mainly web-based solutions is the ability to work offline. Not having access to your calendar or mail (in case of IMAP) when commuting in a train can be very limiting.

My ideal “groupware” would quite be like darcs, in that you pull other’s data now and then do update your local information database. (You also should be able to push your stuff onto a webserver for the nice frontend.) Then, you write some scripts (or adapt existing ones) to manage dates, merge address entries etc.

JWZ is right that groupware should be for people, not for suits. But programmers have different needs than Aunt Tillie or J. Random Worker, and Hula doesn’t reflect that (yet).

(I actually wanted to write a rant about Chandler a week ago, but I saved my energy. If you want to try it, go ahead and be astonished.)

NP: Dan Bern—Lightning Jazz

15feb2005 · Archilab

As reported by MoCo Loco, Tokyo’s Mori Art Museum features a nice exhibition on modern architecture dubbed “Archilab: New Experiments in Architecture, Art and the City”. At Japan Design Net, they have a nice photo coverage of the exhibition.

They have lots of nifty stuff over there.

By the way, don’t miss these hot lamps at MoCo Loco. (And now, to lift the geek factor: Isn’t there a xscreensaver that makes similar patterns?)

NP: Bob Dylan—One More Cup Of Coffee

13feb2005 · TeX in Ruby, or: Raft

My last experiments porting the layout part of TeX into a Ruby library now officially have a name: Raft, Ruby’s Advanced Framework for Typesetting. Thanks to Gabriele Renzi for proposing qraft where I simply dropped the first letter. Also note that Raft is Craft without C. :-)

On the technical side, I today shipped the first hbox consisting of letters and glue. You can see it, packed at various sizes, here. Note that I don’t have vboxes yet, the PDF code of the different lines is still assembled “manually”.

Before I look into vboxes, I have to do a major refactoring on the PDF generation side, to make it actually usable by the packer directly. PDF generation for typesetting turned out not to be that difficult, alas, the pdfTeX code for actually shipping out (minus the utility functions) is mere 3 pages of code.

Also, it’s time to be more exact with units. I should drop all uses of floating point arithmetics and rather use BigDecimal. Furthermore, the inch will stay being 72.27 Raft points. All this still has to be written…

Proper font handling will get a very difficult job. I currently use a simple-minded .afm-parser to get the bounding boxes and use some ideas of ttf2afm to calculate proper values from them… Having to fiddle with accents to get proper heights for accented chars totally turns me off. I’d rather do Unicode all the way, but I couldn’t yet get much information about OpenType and other unicode supporting font formats yet.

Next week, I’ll be on a one-week intern and probably don’t have a lot of time to hack, we’ll see.

NP: Dan Bern—Chelsea Hotel

11feb2005 · TeX in Ruby, part 2

Yesterday, I started (re-)reading “TeX: The Program” and “The TeXbook”. Knuth’s code is very dense and some parts are very optimized. He uses linked lists everywhere, which doesn’t ease rewriting the code in a object-oriented way, as you may guess.

Nevertheless, I started porting the Packager, the part of TeX that “sets the glue”, as printers would say. It replaces the infinite measures of boxes (TeX has three levels of infinity) with concrete values to make them ready for output.

It’s a fairly easy task, actually, as Knuth describes what happens quite well. Nevertheless, I stepped into some traps and only did hpack so far. I expect far more trouble doing linebreaking and alignments, though. The hyphenation part is already done, as TeX::Hyphen (and the comparable, but not file-compatible Text::Hyphen) exists for Ruby. Puh. :-)

I also started writing a PDF generator, which isn’t a trivial task. So far, I use the approach of serializing Ruby structures directly to PDF… we will see how that turns out to work. Austin Ziegler’s PDF::Writer would be an option too, but I haven’t yet looked closer into it.

I had a great time hacking the last days, I don’t think I enjoyed programming like that in the last time.

Oh yeah, one thing… I need a name for it. :-) Mail or comment your ideas.

NP: Pearl Jam & Neil Young—What Happened Yesterday

09feb2005 · TeX in Ruby

Today in #ruby-de, I came up with the idea of re-implementing TeX in Ruby. What first looks like “Mission Impossible” turns out not to be as hard as it seems (I hope, at least :-)):

  • The font issue is solved. Knuth did a great job doing Computer Modern in Metafont, and there is no reason to repeat that amazing work. Metafont fonts (rather, their output) should be easily usable and TrueType/OpenType support can’t be that hard either.

  • We live in the 21th century. There is no need to reimplement the Pascal “standard” library anymore. (And neither doing our own dynamic memory stuff, or transforming the host character encoding to ASCII.)

  • PDF should be the main output format. Although other output formats would be possible (please, let DVI rest in peace), PDF is the most popular and widely supported format for printing. (Postscript would have been a possibility, but lacks good graphics support and hyperlinking.) If pdfTeX can do PDF, we can too.

  • We have Unicode. Unicode should be the default encoding, addressing issues that Omega tries to solve.

  • We have Ruby. Ruby should be used for all issues addressing programming. No more ugly hacking, fiddling with \expandafter or \catcode. Ideally, we would have a high-quality output library that gets driven by:

    1. XML (possibly XSL-FO?)
    2. A LaTeX-like system (the library should not care about semantics)
    3. plain TeX (this will be a mess to implement, and is probably not needed)

We should not strive for bug-to-bug—whoops, those don’t exist in TeX—bit-to-bit compatiblity with TeX, as this wont result in progress, but rather playing at the same level of output quality. I hope the result will be more satisfying to use than TeX, which clearly shows it’s age.

If you are interested about helping/starting this, not-that-easy task, please show up on IRC or mail chneukirchen@gmail.com. This is a task that cannot be done alone. (Hey, I’m not Knuth…)

Right now, I’m investigating a reimplementation of the formula subset of TeX in SML, as I have no idea of the internals of that.

NP: Dan Bern—Are You Gonna Follow Your Soul?

07feb2005 · Qt4 GPLed for Windows

Usually, I don’t especially care for Windows as a platform for free software. If software runs there without major changes, it’s nice, but if it doesn’t, I wouldn’t waste lots of work to get my stuff run on Windows.

However, if software technically runs on Windows, but you are forbidden to use it freely, I get crazy. This was the main reason not to use Qt: Although you freely could use it on Linux for your GPL programs, there was no way to get it run on Windows without getting a commercial license by TrollTech. (Some free software developers seem to have gotten licenses for free, but this doesn’t change the general fact that free software development for windows used to be impossible with Qt.)

Note that I wrote “was” above, as this has now changed. With Qt4, TrollTech’s next version of Qt, GPLed software is now allowed to freely use Qt4 for Windows too.

I think this is great news and I don’t see any reason not to use Qt4 for your free software projects. (Yeah, I still prefer GTK+—mainly because it doesn’t force C++ on me–, but nevermind.)

NP: Bob Dylan—This Was My Love (Take 1)

06feb2005 · About Atheism

I just found this real gem on the Wiki:

Believer: You are so stubborn. I bet if God zapped your butt with lightening, you still wouldn’t believe.

Atheist: Try me!

Suddenly the sky opens up and a huge bolt of lightning flies straight down at the atheist’s rear end and the shock knocks him 10 feet away.

Atheist: I bet you are not God up there; you are just an alien with advanced technology.

Sky: Oh yeah, take this!

Atheist: So you can give me duck feet. You are still just an alien with advanced technology.

Sky: How about this!

Atheist: So, you gave me women’s breasts. You are still just an alien with advanced technology. Nice work, though.

Sky: You have offended the Great Lord one last time. I am ending this now!

(Loud thunder followed by a blinding flash)

Atheist: Wow! That really was God! I have to go tell everybody.

(Atheist runs off down the hill shouting religious slogans)

Believer: God, that was a pretty impressive display. But if you don’t mind my asking, how did you make him believe?

Sky: I simply directly turned his mind into a believer’s mind. By the way, I really am just an alien with advanced technology. Ta ta…

Priest: You know, Scribes, I don’t think you need include that final exchange in the next edition of the Holy Scriptures.

Made my day…

NP: Bob Dylan—Dark Eyes

04feb2005 · Icehouse

shapr of #darcs introduced me to Icehouse, a “generic game”, i.e. one you can play with many—and totally different—rules.

Icehouses essentially are stackable plasic pyramids in different colors and three sizes. I’ve been reading about some popular games people play with it, for example:

  • IceTowers is a kind of distributed Towers Of Hanoi where you must try to make as many as possible towers with your color on the top, but you only can stack smaller pieces on larger ones.

    The fun thing in the game is probably that everyone is allowed to play at the same time, no waiting till it’s your turn anymore. :-)

  • Zendo is a kind of Mastermind on steroids where you need to figure the masters composition of Icehouses.

  • The original Icehouse, which looks to me like a kind of chess, except there is no board. ;-) And like with IceTowers, there are no turns. Also, you usually aren’t allowed to move your pieces. OK, it’s probably totally unlike chess. *g* Maybe more like Domino.

  • Volcano, which reminds me of some chain-reaction games.

These plastic pieces, although very simple, seem to be extremely flexible in gameplay. Heck, I want a few stashes of them… but where do I get those in Germany?

NP: Elliott Smith—Coming Up Roses

02feb2005 · Wintersporttag 2005

Im wesentlichen genau dasselbe wie 2003 (2004 scheine ich um diese Zeit nicht gebloggt zu haben, wie die Zeit verinnt…):

Yeah, today was winter-sports day in our school.

You could choose between skiing, tobogganing (boy, the english language has weird words) and swimming. I went swimming, since I think swimming is a great winter-sport. [deep sarcasm]

Dieselbe “Zeitverschwendung” wie jedes Jahr. Eineinhalb Stunden im Bus, wenn’s hochkommt zwei Stunden im Wasser. Thermalbecken (scheinbar warm) und Schwimmbecken (25m) sind für Schüler natürlich gesperrt.

Außerdem wurde meine Theorie bestätigt, dass man nach fünf Jahren eigentlich jedes Schwimmbad abreißen kann und sich was neues ausdenken sollte.

Trotzdem besser als Tageslichtprojektoren putzen… :-)

NP: Interpol—Public Pervert

01feb2005 · Sternchenthemen

Deutschlands Klassenzimmer’ gesammelte Ergüsse (wow, doppelter Genitiv):

do re mi fa so le mi o [die italienische Tonleiter]

Ich glaub’, ich bin von lauter Trotteln umgeben.

Herr …, koksen sie? [hat Kreide im Gesicht]

Vatinin

Macht keine Witze über Bulimie. Das ist zum Kotzen.

Metriologen

Die bewegen sich auf einer epileptischen Form. [über Planeten]

Sagen wir, ich fahre nach Thailand…Sie Sau!

Was nächstes Jahr Sternchenthema ist, steht in den Sternen.

Seit gestern neues Schuljahr (Im Zeugnis^WHalbjahresinformation war mein Schnitt 2.08, übrigens…) und morgen ist Wintersporttag, da gibts dann ‘nen netten Repost von vor zwei Jahren.

Nach Ferien und BOGY (jeweils eine Woche) gehts dann wieder mit gewöhnlicher Schule weiter. *gähn*

NP: Elliot Smith—Division Day

Copyright © 2004–2022