Archive for the 'Ruby' Category

Mon
2
Oct '06
Profiling Rails Unittests
by Frank Spychalski filed under Rails, Ruby

Thanks to a hint by Chris Mear on the Ruby on Rails Mailinglist I had an idea how to add profiling my unittests. It’s a simple 3 step process and adds just 5 lines of code to your unittests:

Step 1:

require 'profiler'

Step 2:

 def setup
  # ...
  # your normal setup code
  # ...
  Profiler__::start_profile
 end

Step 2:

 def teardown
  Profiler__::stop_profile
  f=File::new("#{RAILS_ROOT}/log/profiler.#{name() + ' ' +
              Time.now.strftime('%Y-%m-%d %H:%M')}.log", 'w')
  Profiler__::print_profile(f)
  # ...
  # your normal teardown code
  # ...
 end

As you probably guessed from the code, this will log the profiling results into a file for each test. But beware: this is VERY SLOW! The tests I was profiling took 9s without profiling and 1267s with profiling… But slow profiling still beats no profiling :-)

If you are looking for memory profiling, there is a nice article by Scott Laird on Memory leak profiling with Rails.


Mon
7
Aug '06
Playing on the CodeGolf Range
by Frank Spychalski filed under Computer, Fun, Ruby, articles

picture by bigpru

I stumbled over this funny site called CodeGolf.com and tried my luck on the first problem (actually it’s the sixth, but it was the last and therefore appeared first on their page – confused?) Writing a Brainfuck Interpreter:

The brainfuck language uses a simple model of a computer consisting of an array of memory cells, a movable pointer into the array, an output stream, an input stream and the program itself. The program is formed from a sequence of the below commands :

  • > – Increment the pointer to point to the next cell to the right.
  • < – Decrement the pointer to point to the next cell to the left.
  • + – Increment the byte pointed to by the pointer.
  • - – Decrement the byte pointed to by the pointer.
  • [ - Jump forward to the command after the corresponding ] if the byte at the pointer is zero.
  • ] – Jump back to the command after the corresponding [ if the byte at the pointer is non-zero.
  • . – Output the value of the byte at the pointer.
  • , – Accept one byte of input, storing its value in the byte at the pointer.

It didn’t take me very long to write a running interpreter. My first version was more than a thousand characters. Even after renaming the variables and stripping all the whitespaces I still needed around 700 characters, which is huge compared to the best Ruby solution with only 142 characters. Read the rest of this entry »


Mon
31
Jul '06
Planning a Ruby course – request for comments
by Frank Spychalski filed under Ruby

Later this year I am going to hold a beginners course for Ruby at the VHS in Karlsruhe. Yesterday I started thinking about the topics I want to cover. The participants will have some programming experience which means I don’t have to explain the very basics. The course runs for two days with six hours each day, so I will have 12 hours to teach them Ruby. From the tutorials I read, I liked Mr. Neighborly’s tutorial best and I will use a similar structure. Read the rest of this entry »


This is the fourth part of my Road to Ruby enlightenment. It started a long time ago with tutorials and first steps. Read the rest of this entry »


Sun
18
Jun '06
Java 6 (aka Mustang) goes Ruby
by Frank Spychalski filed under Computer, Java, Ruby

Some time ago Martin Fowler wrote about Humane Interfaces which led to an lively debate. This is really old stuff, but yesterday I read about the upcoming Java 6 aka Mustang and one of the changes was adding the isEmpty() method to String.

So it seems like Java is slowly getting more humane :-)


Tue
16
May '06
Road to Ruby enlightenment – red and gray
by Frank Spychalski filed under Ruby, articles

This is the third part of my Road to Ruby enlightenment. It started with tutorials and first steps. Read the rest of this entry »


This is the second leg on the Road to Ruby enlightenment. It started with tutorials and first steps. Read the rest of this entry »


This is not a Ruby tutorial. Read the rest of this entry »


Tue
11
Apr '06
Advanced articles on Ruby?
by Frank Spychalski filed under Ruby

I’m going on vacation and to keep me busy I’m looking for some advanced Ruby related articles. So far I found The adventures of scaling and the first few chapters of the Ruby Hacking Guide. After the number of comments I got for my last posts, I hope someone is reading this one, too. Do you have any pointers?


Tue
4
Apr '06
Rubybashing: Why use implicit return?
by Frank Spychalski filed under Rants, Ruby

I like Ruby, I really do. But there is one thing I just don’t get. I seems to be good Ruby style to use as much implicit returns as possible. Why? Read the rest of this entry »


Bad Behavior has blocked 262 access attempts in the last 7 days.