Posted by stephan on 28. July 2009
While working on some tree structure a couple of unit tests failed, when creating some form of summary of said tree structure. First of all here’s a condensed form of the code:
require 'sequel'
DB = Sequel.sqlite
DB.create_table :items do
primary_key :id
String :name
String :foo, :default => 'NOT SET'
Integer :item_id
end
class Item < Sequel::Model
one_to_many :items
def summary
if items.empty?
return [ { self.name => self.foo } ]
else
items.inject( [] ){ | r, sub_res | r << sub_res.summary }
end
end
end
r1 = Item.create :name => 'R1'
r2 = Item.create :name => 'R2'
r1.add_item r2
r2.foo = 'Ding'
#r2.save
[ r1, r2 ].each{ |i|
puts "Item : #{ i.id }"
puts "Direct Foo: #{ i.foo.inspect }"
puts "Summary : #{ i.summary.inspect }"
puts
}
Notice, that I’ve commented out saving r2. The output is:
Item : 1
Direct Foo: "NOT SET"
Summary : [[{"R2"=>"NOT SET"}]]
Item : 2
Direct Foo: "Ding"
Summary : [{"R2"=>"Ding"}]
What I didn’t expect – and why the unit tests failed – is the ‘NOT SET’ in the r1 summary.
One way to end up with what I originally expected is to save r2. Another way is to set r2.foo before adding r1 to r1:
r2.foo = 'Ding'
r1.add_item r2
How ever I’m still not sure whether this is intended behaviour and why it should behave like this. (If it is, I’d like to know why.)
What do you think?
Posted in Ruby, testing | Tagged: Ruby, Sequel, tree | Leave a Comment »
Posted by stephan on 18. July 2009
The term “Software Engineering” is coming to age: It was coined slightly more than 40 years ago in Garmisch-Partenkirchen, Germany. Tom DeMarco wrote a very interesting article about his opinion about the topic, which is available online at the IEEE Software magazine: “Software Engineering: An Idea Whose Time Has Come and Gone?” Let me cite just this part:
This leads us to the odd conclusion that strict control is something that matters a lot on relatively useless projects and much less on useful projects. It suggests that the more you focus on control, the more likely you’re working on a project that’s striving to deliver something of relatively minor value.
I strongly recommend to read the whole article.
Posted in Programming, Software | Tagged: Control, Software Engineering, Value | Leave a Comment »
Posted by stephan on 12. June 2009
As described over at “Mac OS X (Tiger and Leopard) Configuration Tips” you can configure Finder to display the full path to the currently displayed folder by using this (in a terminal of your choice):
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
Change back to the default (of the default) using ‘NO’ instead of ‘YES’. Apparently this works in Leopard (or later) only.
Posted in Mac | Tagged: Finder, full path | Leave a Comment »
Posted by stephan on 26. May 2009
Ever needed to remove a file or directory from a git repository? I had to: After pushing a change that included a rather large file to a remote repository, the repository couldn’t be cloned anymore (due to a memory limitation). The support is working on the issue, but being able to clone the repository seems more important to me than having the slides for a presentation (of the past) in this particular repository.
So here’s how: David Underhill has already done – and described – it: “Git: Forever Remove Files Or Folders From History”
Worked for me as well.
Posted in Programming, Software | Leave a Comment »
Posted by stephan on 25. May 2009
Since its 0.9.2 release on 18th of May 2009, Sinatra doesn’t automatically reload files anymore – not even in development mode.
To achieve this use ’shotgun’
sudo gem install shotgun
and then start the server using:
shotgun <your_applicationname>.rb
The effect is essentially the same (apart from avoiding the issues the ‘traditional’ way of reloading apparently had – which is why it was removed).
Thanks for pointing this out in this thread @ rubyforen.de.
Posted in Programming, Ruby | 1 Comment »
Posted by stephan on 18. May 2009
Posted in Ruby | Tagged: readline, Ruby, Windows | Leave a Comment »
Posted by stephan on 12. May 2009
These two days with Ruby enthusiasts form all over the world not just Europe was great. Nicely located at citilab, with very good public transportation to the city centre of Barcelona, there was enough space inside as well as out side the building to talk to the other attendees, just relax in the sun or work with the notebook. Two wi-fi networks inside and outside the building could deal well with all the notebooks and mobile phones connected to it. This worked very good indeed.
The presentations I liked most where the ones introducing really exciting and new stuff. First and foremost there’s Rhodes, which enables the creation of native mobile applications with Ruby and HTML. And of course Matz’ keynote was very entertaining as well. More really new stuff was about Adhearsion a way to build voice enabled application with Ruby (and Rails). Then some of the presentations were a really good show. Most notably Javier’s talk about gosu, a framework for games and Pablo’s presentation about Archaeopteryx which was probably the loudest presentation I’ve ever heard.
The only thing that was a tad bit disturbing for me was that I didn’t have one of the mobile microphones available and was kind of stuck behind the table as well as the phones themselves, as they seemed to go silent now and then. Aslak dealt with this best I think, repeatedly saying “Hello?” directly into the microphone whenever it went silent.
I think this year was the first time Twitter was heavily used during Euruko, reusing a bot made for Scotland on Rails. and this helped enhancing the communication and connecting people even more than in previous years. A special “Thank you” to all for the other attendees who gave me direct feedback about the presentation as well as the corresponding discussion about it, including but not limited to: Andrew Miller, Tim Becker, Mike Just, Dave Frey. Thanks a lot, indeed.
More summaries are available from Javier and Tomasz.
Next year Euruko will take place in Krakow, Poland and I’m already looking forward to going there.
Posted in EURUKO, Programming, Ruby | Tagged: Adhearsion, Barcelona, citilab, EURUKO, gosu, Ruby | Leave a Comment »
Posted by stephan on 28. March 2009
While still in the process switch ing from Subversion to Git, here are a few helpful links I found:
Once up and running there’s of course github, gitcentral and gitorious. For hosting open source projects currently github seems to be the choice, but in case you prefer not to share stuff (just yet) gitcentral offers free (as in no money) hosting of private projects using free (as in open source) software.
Posted in Mac, Software, Work Environment | Tagged: Git, gitcentral | Leave a Comment »
Posted by stephan on 9. March 2009
Over at euruko.org the registration is now open. The conference is on the 9. & 10. of May 2009 in Barcelona, Spain. It seems they collected quite a few exciting talks – and mine.
Really looking forward to going there.
Posted in EURUKO, Ruby | Tagged: Barcelona, Euruko 2009, Ruby, Spain | Leave a Comment »
Posted by stephan on 2. March 2009
It has been noted at other places: The tabs in Safari 4 appear in the very top of the window, where you’d display page information and could CMD-click to see the browsing history. And you could easily move the window with a click ‘n drag. That space is now (mostly) occupied by the tabs. To go back to what it used to be previously just do this (at your own risk):
defaults write com.apple.Safari DebugSafari4TabBarIsOnTop -bool NO
There you are, the tab are back just above the content (where I think they belong anyway).
Posted in Mac, Work Environment | Leave a Comment »
Posted by stephan on 1. March 2009
I just found this Rails plugin: acts_as_textile – on GitHub.
Given that I do use Textile every now & then it’s very likely going to be pretty helpful. Thanks for sharing.
Posted in Ruby on Rails | Tagged: Rails, Textile | Leave a Comment »
Posted by stephan on 31. January 2009
During Euruko 2008 the top case of my MacBook broke a little bit. At the right hand side of the front a ’splint’ of the case came (partially) off. This was not a big issue since it was easily fixed with some sellotape. Strangely enough other MacBooks had the same piece of tape at nearly the same place.
And the day before yesterday it happened again (this time at the edge of the right side), giving me a good reason to go to the recently opened Apple Store in Munich. The first impression: Nice people there – friendly, helpful and tech-savvy.
The first good news: They would repair it free of charge even though the MacBook was out of warranty. The second good news was that I got it back today already. That was a quick and complete repair since the entire top case was replaced, including the keyboard & mouse pad.
I wasn’t too happy when the case broke, but the service in the store was really very very good.
Posted in MacBook, support | 2 Comments »
Posted by stephan on 31. January 2009
Posted in Programming, Ruby | 1 Comment »
Posted by stephan on 12. November 2008
Posted in Ruby, Ruby on Rails | Tagged: München, Munich, Rails, Ruby | Leave a Comment »
Posted by stephan on 10. October 2008
While reading about the DRY principle (for “Don’t repeat yourself”) and the evil of copy-and-paste coding (again), I started thinking what to do instead. Actually, what to do is more or less obvious: Put the code into a place where its accessible to be reused — a method, may be in a new or existing module or class.
So, whenever I feel the ‘need’ to copy code, I now think about cutting it, creating a new method and calling that. Apart form avoiding duplication, the code is now testable immediately by calling the method (instead of getting the surrounding code exercised). And the methods using the code gets shorter.
In the end, it boils down to pasting code being perfectly OK, it’s the copying that causes the trouble.
Posted in Programming, method call, testing | Tagged: Coding, Testability | Leave a Comment »
Posted by stephan on 21. September 2008
I regularly fire up the same applications: TextMate, a browser or two, mail programs, iTunes, a shell, irb and others. Now, while Quicksilver is excellent for firing up applications (and a lot of other things), I’d still be busy typing and/or mouse-pointing and clicking. And doing that is boring, cumbersome and not what I like to do anyway. I shouldn’t (have to) do it. And, in fact, I don’t. A little bit of Ruby code will do it:
#!/usr/bin/ruby
%w( <full_application_paths_go_here> ).each{ | app | system "open #{app} &" }
Replace <full_application_paths_go_here> with a list of space-delimited full application paths, save it into a file (in ~/bin presumably), make it executable and there you go. Actually, the language doesn’t matter at all here. The only thing that does matter is to fire up the applications.
Starting all most used applications is now just a few key strokes away. There’s certainly a very similar way to do this on other *nix OSes and Windows.
Posted in Mac, Programming, Ruby, Work Environment | Tagged: Efficiency, Productivity | Leave a Comment »