Posts Tagged ‘ruby’

TextMate Snippet Power für gettext

Sunday, February 17th, 2008 by Thilo Utke

Es ist super wenn die Werkzeuge, die man verwendet mit einem wachsen. Deshalb bin ich von Ruby und TextMate begeistert.

Für die, die TextMate nicht kennen: TextMate ist ein TextEditor für OS X, der sich in meinen Augen durch zwei Besonderheiten als Entwicklungswerkzeug hervortut. Erstens die leistungsfähige Live-Suche, die alle Mausklicks zum Navigieren im Projekt überflüssig macht. Zweitens die wirklich mächtigen Skriptingmöglichkeiten, die ich wohl noch lange nicht erfasst habe.

Jedenfalls musste ich Rahmen der Internationalisierung eines Projekts alle Strings in eine Übersetzungsmethode von gettext wrappen. Also ggf. Texte in den Views in Inline tags und in doppelte Anführungszeichen zu packen. Das gewünschte Ergebnis sieht etwa so aus: <%= _("Zu übersetzender Text") %>. Die ganze Arbeit ist ziemlich stupide, ließ sich aber mit TextMate auf simples Markieren des entsprechenden Textes und das Drücken des Tastenkürzels ctrl+alt+t reduzieren.
(more…)

EURUKO 2008

Wednesday, February 13th, 2008 by Alexander Lang

Die Konferenzsaison fängt an. Kurz vor der re-publica geht’s am 28./29.3. nach Prag zur European Ruby Conference. Letztes Jahr in Wien war ziemlich lustig. Damals hatten wir in der Nacht zwischen den zwei Konferenztagen ein Twitter-basiertes Rätselspiel (twizzer) geschrieben.

Falls jemand auch da hinwill, wir hätten evtl. noch Plätze im Auto frei.

RSpec 1.1 with StoryRunner coming?

Wednesday, December 12th, 2007 by Alexander Lang

The latest update from the rspec trunk changed the version.rb file indicating a 1.1 Release Candidate 1 version. Will there finally be a stable RSpec version that has StoryRunner? That’d be a great present for christmas.

Random links: smalltalky ruby & quietbacktrace

Tuesday, December 4th, 2007 by Alexander Lang

Patt Maddoxx recently blogged about a ruby hack to avoid the dreaded nil-if, e.g. if user.comments.first; user.comments.first.title;. instead you can now do: user.comments.first.if_not_nil?{|c| c.title}.
http://evang.eli.st/blog/2007/11/22/smalltalky

dan croak has written a precious little ruby gem that filters the noise from you exception backtraces:
http://giantrobots.thoughtbot.com/2007/12/3/shhh-your-test-unit-backtraces-are-too-noisy

Euruko 2007 Review

Monday, December 3rd, 2007 by Thilo Utke
euruko 2007

Last weekend (10. to 11. November) we were at the Euruko, the European Ruby Conference in Vienna. The conference wasn’t nearly as big as the Railsconf Europe, but the ad hoc character adapted very well to demands of the attendees and the topics were more academic. Here is a round up of the presentations I attended.

The Keynote was about the future of ruby with a look back to its beginnings by Hal Fulton. About the upcoming ruby 1.9 he said, that it wouldn’t change that much, but will gain performance by having its own virtual machine. Another aspect of his talk was the shift to enterprise use.

The following talk was about the Database Library Dbrb, it is basically a wrapper for ruby dbi to make it easier to work with it. Interesting if you have to do data crunching closer to the relational domain.

David Anderson shows a structured wiki, where you can build simple Applications with forms and so on.

Ramine Darabiha, Sven C. Köhler show their Javascript based content distribution/mashup system MySit.es which is still under heavy development.

After the lunch break Christian Neukirchen showed Rack, a simple and modular web server interface specification. It basically wraps the status, headers, and body in a array. Following the rack specification you can add middleware between your server and the web framework, e.g. log file generation or URL rewriting.

An alternative to watir, a in browser testing framework, was shown by Kingsley Hendrickse, the Ruby IE Scripting System (RIESS) and AutoGUI.

The powerfull, but hard to learn, web site scraping framework scRUBYt was introduced by Peter Szinek.

The last talk of that day was about the use of Domain Specific Languages and how easy it is to build one, held by Martin Grund.

In the evening we had an excellent dinner in the ‘Universitätsbräu’. My personal dish recommendation ‘Schöpfsteak’.

We took the opportunity and input from the conference to try out some new stuff in a late night coding session, although I had had just 4 hours of sleep the night before. But alex will write some more about our twitter mashup twizzer.

On Sunday we missed the first talks. So i can’t tell you anything about it ;)

The first I joined again was from Tim Becker, who showed DTrace. DTrace is an integrated tracing framework for debugging applications or the OS itself. It is integrated into Solaris and the latest Mac OS 10.5 ‘Leopard’.

What Trees are good for, was explained by Paul Battley. For example they are good for faster best match search using the Levenshtein distance. But I have to admit, I didn’t followed that talk very well.

Then Stephan Kämper talked on Quality in code, and shows some exaple of good and bad code.

Hal Fulton filled the little gap before the lunch break with his proposal for an in operator in Ruby.

After the lunch it got even more academic with Ragel, a state machine compiler, presented by Ry Dahl

Then we showed our results from the coding session.

The last presentation of the Euruko was held by Sasch Schlegel about the ebXML Messaging System called Hefeweizen. I liked the MAMAs and PAPAs analogy ;)

Before we caught our flight home, we had another dinner at the ‘Universitätsbräu’.

I enjoyed the Euruko very much, I will try to attend next year again. Maybe in Prague then.

Implementation Patterns emerging

Monday, December 3rd, 2007 by Alexander Lang

I recently read Kent Beck’s new book Implementation Patterns - it was a nice read and I guess it somehow strengthened my senses towards patterns a bit. Unfortunately it is written with Java in mind, and as we all know Patterns are language specific. The following can’t really be applied to Java as far as i know (having stopped writing in Java with 1.5).
So I discovered a kind of implementation pattern I had used a few times in the last weeks. Maybe everyone has already written about it but I want to stress that I discovered it myself :) Here it is:

The Selector Pattern

When to use it: When you have a complicated if-elseif-elsif-else or switch clause and want to replace it with something more elegant.

When not to use it: It works well for limited complexity. I things get more complex you may want to use class inheritance instead.

What it does: Put the each condition and the according logic into a hash. Then iterate through the conditions to find a match and execute its logic.

Example

Suppose you have a class Video that represents a video on youtube or some other hosting provider. Its purpose is to render the neccessary HTML tags to embed it into a document. The generated HTML differs depending on the hosting provider, e.g. youtube.com or vimeo.com. The code could be expressed like this:

Using the selector pattern it might look like this:

With only 2 providers this doesn’t make too much sense but with something like 5 your elsifs start to get really ugly and the selector pattern offers a more ligtweight way to replace these than creating an entire hierarchy of subclasses for every case.

Using and Testing ActiveRecord/Rails Observers

Saturday, October 27th, 2007 by Alexander Lang
social feed

We recently introduced a new feature in autoki called the social feed. It’s basically a yellow box displaying any events on the platform relevant to the current user, like a friend has posted a new photo, or a new interesting car was uploaded. The data model behind this is pretty straightforward, we have a FeedEvent class and all kinds of subclasses, e.g. a MessageReceivedEvent. Each event belongs to a user and an event source, in this example the user would be the user who received the message and the event source would be the message itself. For each user, we simply display all the events that belong to him or her.

Now the question was this: How do we create these events? The most straightforward way would probably have been to create them in the models, so the Message model would have an after_create callback that created the event. What we didn’t like about this solution was that we would put a whole bunch of logic into the models that didn’t really belong there. Why would a Message care if there was some kind of event feed? Plus these events would be all around in our unit tests and make the bloated and probably sloooow (again). So we wanted to use the observer pattern to remove the creation of the event from the models.

(more…)

mocha Präsentation

Thursday, September 6th, 2007 by Thilo Utke

Hier wie versprochen die Slides meiner Presentation zum Thema mocha bei der Ruby User Group Berlin.

Links:

Mocha
Floehopper (Blog des Mocha Entwicklers)
Presentation about Ruby Mocks
TestingRails Blog (gelöscht :()
Use stubs and mocks to convey intent
Ruby: Mocks and Stubs using Mocha

Kleinere Thumbnails mit strip

Thursday, September 6th, 2007 by Thilo Utke

Open Source ist wirklich eine tolle Sache, jeder kann den Code für seine Zwecke anpassen. Das haben wir auch schon ein paar mal gemacht, hier kommt noch einen schönes Beispiel welches für Open Source spricht.

Wir haben viele kleine thumbnails auf der Startseite von autoki, die haben wir genauso wie alle anderen Formate mit file_column generiert. file_column ist ein praktisches Plugin das eine Schnittstelle über RMagick zu ImageMagick bildet, um einfach verschiedene Formate von Bildern für ein Model zu generieren. Vor Kurzen mussten wir feststellen, dass die autoki Startseite ungewöhnlich viel Bandbreite braucht. Beim Blick auf ein einzelnes Thumbnail zeigte sich, das bereits ein kleines 53×53 Pixel Jpeg 48KB gross ist.
(more…)

Mnemonic for Duck Typing.

Sunday, August 26th, 2007 by Thilo Utke

I’m currently read the Ruby Cookbook and found a good explanation for duck typing. You know, the concept to treat objects according to their methods rather their classes/modules. It might be well known to you, but i like to share it anyway.

Duck Typing means:

“… if an object quaks like a duck, just go ahead and treat it like a duck”