Random Updates

Posted by MSch Wed, 10 May 2006 10:22:00 GMT

I’m currently under quite some stress with the approaching final exams, but I’ve nevertheless two findings worth sharing:

  • Necklaces resembling neurotransmitters
  • A YAML parser in pure Ruby, that supports using a mapping as a key in one line.
    [123, 123]: asd
    This is something Syck won’t parse, although it’s correct YAML, as xitology from #yaml told me. He also informed me about his SoC project called libyaml, that would be a fast, feature complete alternative to Syck. If Google accepts his proposal he expects a release in 3 to 4 months.

Tags , ,  | 2 comments | 3 trackbacks

How to write DSLs with Ruby

Posted by MSch Sat, 01 Apr 2006 20:51:00 GMT

Recently I needed a DSL like the one in Rake for one of my projects. At first I just googled around a bit hoping to find a comprehensive tutorial. I did gain some more or less useful insights, but what I wanted was something as clean and coherent as a Rakefile:

  namespace "samples" do
    task :build do
      # Build the sample programs
    end
  end

After reading lots of tutorials and gaining come clues all I managed to code was:

  namespace do |n|
    n.task do |t|
      # Build the sample programs
    end
  end

I felt terrible and started reading the Pickaxe, desperate for a solution. Proc, Binding, Object, Kernel. I was looking everywhere for some clues on how to make my DSL as great as Rake’s. Finally I found what I was looking for: Object#instance_eval!

I’ll spare you any further explainations and present you the source (abridged, download full version) to my DSL implementation:

class PseudoRakefile
  def evaluate(&block)
    Tasks.new({}, {}, self, &block)
  end

  protected
  class Tasks
    attr_reader :parent
    def initialize(args, options, parent, &block)
      # snip
      instance_eval &block
    end

    def task(task, args = {}, &block)
     Tasks.new(@args.merge(args), @options.merge(:task => task), self, &block)
    end
    def namespace(name, &block)
      Tasks.new(@args, @options.merge(:namespace=>name), self, &block)
    end

    # snip
    def puts(msg)
      Kernel.puts "#{@options[:namespace]}:#{@options[:task]} #{msg}"
    end
  end
end

rakefile = PseudoRakefile.new

rakefile.evaluate do
  namespace "samples" do
    task :build do
      develop('deal', :do_it => :great)
      sleep 2
      develop('solution', :do_it => :sloppy)
    end
    task :destroy, :probability => 1 do
      puts "Tear everything down like a little kid"
      rm("Schroedinger's Cat", :probability => 0.5)
      rm("some unimportant file")
    end
  end
end

It’s free to use for anyone, but you’d make this boy very happy by leaving a comment, especially if you have improved the core idea or actually use my code in your projects.

Tags ,  | 1 comment | 2 trackbacks

Presentation techniques

Posted by MSch Thu, 09 Feb 2006 14:47:00 GMT

Part of my education is learning how to do presentations. It’s no standalone course but rather an integral (or not so integral) part of every subject.

Some time ago I stumbled about some great advise when doing presentations: The Takahashi Method. After deciding that Takahashi’s way of conveying information was a little too pure for me, I settled with copying the Ruby On Rails Presentations.

This approach is not only clear enough to keep the focus on the presenter but also puts some real (scientific) data across.

Tags ,  | no comments | no trackbacks

F still comes before S

Posted by MSch Sat, 07 Jan 2006 20:24:00 GMT

Some time ago David Felstead, a senior Site5 engineer, said that Site5 was considering switching from FastCGI to SCGI and so I decided that if Site5 was considering it, I could simply do it.

He wrote about some major pains in the proverbial with FastCGI:
  • It’s hard to set up
  • It’s hard to monitor
  • It requires dedicated tasks to keep working (reaper, spawner, spinner anyone?)
  • Currently no one is actively developing the Apache module.

According to him SCGI is better, because it only took him 15 minutes to set up properly. And now for the but:

As you, dear well informed reader, of course know one feature of FastCGI is to keep multiple instances of the Rails dispatcher open. SCGI in combination with the Apache module supports exactly one instance of the dispatcher. There is one obscure and in reality impossible way of changing that but believe me you don’t want to do this.

For me monitoring seemed easier because reaper, spawner and spinner already exist for FastCGI opposed to my self-written Ruby script that tries to do the same for SCGI.

And if that wouldn’t be enough SCGI also simply delegates every request below a defined path to Rails, which of course sucks if you have static content in your application. You can try to work around that, but once you generate .js or .css files through Rails, you pretty much start hating SCGI.

But uninformed as I was, I just went ahead and let SCGI handle my requests. Till today. Today I made Rails use FastCGI. I didn’t exactly follow the instructions in that article, instead of compiling anything myself I just let apt and RubyGems do all the hard work:

sudo apt-get install libfcgi-dev
sudo gem install fcgi

For me switching from SCGI to FastCGI brought nothing but relieve: My requests seem to get handled faster (probably because of the multiple instances running concurrently) and I no longer have to breach DRY, as my .htaccess doesn’t need to exclude non all rails handled requests.

Tags , ,  | 1 comment | no trackbacks

Real-time collaborative editor shootout

Posted by MSch Sat, 17 Dec 2005 13:26:00 GMT

Wolfgang Sommergut found SynchroEdit an open-source browser-based simultaneous multiuser editor. But unfortunately the Demo seemed broken when I tried it out, so I started to look for alternatives.

And alternatives I should find: Wikipedia has an article, that although sparse on content contains links to seemingly every collaborative editor there is. JotSpot Live is a hosted application that works (I actually tried the free plan) on Firefox and Internet Explorer, but not Opera. It once told me it lost it’s connection while I was typing on IE, but apart from that it seem slick, stable, WEB 2.0 like.

There’s also LivePad, a Mozilla only browser based rich editor, that’s free as in speech and works flawless, but takes quite some processor power.

Because i couldn’t find any really mind-blowing web applications, I decided to give standalone applications a look. Although there are two working, free solutions, I’ll ignore MoonEdit and just describe my experience with the better looking, cross-platform Gobby, because Gobby is what the developers of the great game Clonk use.

After some initial work to get Gobby running on Windows (you have to download and install GTK support packages), Gobby itself is a great piece of work. Editing works smooth and changes are visible immideatelly. Furthermore multiple documents, syntax highlighting (even for Ruby) and a seperate chat during the editing process are supported.

All in all I have to say, whenever possible I’d use Gobby, because it’s simply ten times more powerful then it’s web based equivalents, and free. If I’d to go with a Web Application I’d choose the non-free JotSpot, because it supports many different browsers and just works out of the box.

Tags  | 1 comment | no trackbacks

Convention over configuration

Posted by MSch Sat, 17 Dec 2005 12:31:00 GMT

Lucas Carlson tried to fix ERB’s html_escape to escape special characters, because he didn’t like that Rails produced instead of with this statement:
button_to '< Back', :action => 'view', :id => 3
So he went on and patched ERB so that it supported escaping of ampersands (by prefixing them with a \) and till yesterday that seemed like the Ruby like solution to my. But then I woke up today and everything seemed clear.

I was a fool. Not only did I completely ignore the potential security breach (XSS) that was introduced by essentially removing html_escape’s teeth, but I also neglected to see the really Rails like solution.

Rails is based on many principles that sound like buzzwords, but in fact aren’t. Convention over configuration is one of them, and it means that there’s always one favoured way to do something. And for his problem this way is replacing the &lt; with a plain old <:
button_to '< Back', :action => 'view', :id => 3

Tags  | no comments | 1 trackback

How I updated my typo installation

Posted by MSch Fri, 16 Dec 2005 16:43:00 GMT

Yesterday I went from some revision I never cared to remember to the new and shiny 762. But not everything went smooth. While the svn update worked perfectly, the migrations simpley kept on failing. I even considered looking at the SQL for myself, but thankfully I rerun them once again, and voila, everything worked. This is a documented bug, but no fix is available as of now and why my “solution” worked is incomprehensible to me. (Also, I didn’t investigate)

In other news: Typo has lots of javascript problems

Even considering all these bugs Typo is still the best blogging software around (not only because it’s written in Rails) and I’ll happily keep on playing beta testing guinea pig.

Tags ,  | no comments | 1 trackback

New (Swiss) Money on the block

Posted by MSch Thu, 15 Dec 2005 17:03:00 GMT

Switzerland, the country we all wish to be our home, held a competition to find a new design for their upcoming series of Swiss Francs.

Although they amongst others feature a rendering of the AIDS virus and some people seem to object to that, I can’t help but admire this great design and the message it carries: The future (as the past) belongs to science and progress! Yay!

Source: BoingBoing

no comments | no trackbacks

Oil Expert To Address Theory That Peak Oil Has Arrived

Posted by MSch Thu, 24 Nov 2005 14:25:00 GMT

Oil Expert To Address Theory That Peak Oil Has Arrived from PhysOrg.com

Princeton University emeritus professor and renowned oil analyst Ken Deffeyes thinks that the all-time production peak for petroleum, or “peak oil,” will occur on or around this Thanksgiving.

According to the article the professor already correctly predicted the US Oil Peak in 1970, so there might be some truth to it, but as the Austrian cabaret artist Josef Hader says: “I can’t stand all the people that rant about people more than 100m away.”

Tags  | no comments | 4 trackbacks

iRiver H10 USB Connectivity

Posted by MSch Tue, 22 Nov 2005 14:00:00 GMT

Today I tried to connect an iRiver H10 to my Windows XP Professional SP 2 Notebook. At first everything went fine, XP recognized the new device and showed the “Add new Device” Dialog, but the driver installation failed. Windows Update didn’t have any drivers and neither did the iRiver Homepage. Firmware updates, check. Manuals, checkk. Drivers, fail.

And to make my day worse it also failed on two different machines in the same way.

That means no iRiver for me.

Tags  | 3 comments | 1 trackback

Older posts: 1 2