amazing development » Ruby http://amazing-development.com ruby, java and the rest Fri, 29 Nov 2013 18:57:08 +0000 en-US hourly 1 http://wordpress.org/?v=3.4.2 JRuby on appengine with Ubuntu http://amazing-development.com/archives/2010/01/06/jruby-on-appengine-with-ubuntu/ http://amazing-development.com/archives/2010/01/06/jruby-on-appengine-with-ubuntu/#comments Wed, 06 Jan 2010 11:09:20 +0000 Frank Spychalski http://amazing-development.com/?p=426 Overall the instructions on code.google.com are really good, so this is just a dump to remind me of the Ubuntu specific stuff I did on a pristine Ubuntu installation…


sudo apt-get install sun-java6-jdk
sudo apt-get install ruby-full rubygems

This installs only rubygems 1.3.1 but appengine needs 1.3.5.

ERROR: Error installing google-appengine:
bundler requires RubyGems version >= 1.3.5


sudo gem install rubygems-update
sudo /var/lib/gems/1.8/bin/update_rubygems
sudo gem install google-appengine

Et voilà! Ten minutes later I have a running hello world in the cloud ;-)

]]>
http://amazing-development.com/archives/2010/01/06/jruby-on-appengine-with-ubuntu/feed/ 0
Android scripting environment supports JRuby http://amazing-development.com/archives/2009/08/04/android-scripting-environment-supports-jruby/ http://amazing-development.com/archives/2009/08/04/android-scripting-environment-supports-jruby/#comments Tue, 04 Aug 2009 06:21:19 +0000 Frank Spychalski http://amazing-development.com/?p=396 Quite some time has passed since the last time I wrote something on this blog, mostly because I did little non-work related worth mentioning.

But last week I helped Damon to finally support JRuby on his Android Scripting Environment (ASE).

  • Downloaded JRuby sources (jruby-1.2.0RC1) from http://www.jruby.org/download.
  • Patched the build.xml to not include doc/index.html from dynalang.jar otherwise dx will complain about an HTML page in the ruby-complete.jar.

    $ diff -r jruby-1.2.0RC1 jruby-1.2.0RC1.patched/
    Only in jruby-1.2.0RC1.patched/: build
    diff -r jruby-1.2.0RC1/build.xml jruby-1.2.0RC1.patched/build.xml
    42c42
    <
    ---
    >
    238c238,240
    <         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar"/>
    ---
    >         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar">
    >           <exclude name="**/doc/index.html"/>
    >         </zipfileset>
    268c270,272
    <         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar"/>
    ---
    >         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar">
    >           <exclude name="**/doc/index.html"/>
    >         </zipfileset>
    387c391,393
    <         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar"/>
    ---
    >         <zipfileset src="${build.lib.dir}/dynalang-0.3.jar">
    >           <exclude name="**/doc/index.html"/>
    >         </zipfileset>
  • Downloaded the JSON sources from http://rubyforge.org/frs/?group_id=953 and put them in lib/ruby/1.8/json/
  • Copied android.rb to lib/ruby/1.8/.
  • Built jar-complete (ant jar-complete) and added jruby-complete.jar to eclipse project.
  • Connected the bits and pieces in com.google.ase.interpreter.jruby

    But beware! The new ASE apk is HUGE (4.6M) and JRuby is fairly slow. But it works ;-)


]]>
http://amazing-development.com/archives/2009/08/04/android-scripting-environment-supports-jruby/feed/ 7
Ruby demotivator http://amazing-development.com/archives/2008/04/06/ruby-demotivator/ http://amazing-development.com/archives/2008/04/06/ruby-demotivator/#comments Sun, 06 Apr 2008 10:02:49 +0000 Frank Spychalski http://amazing-development.com/?p=316 I found the DIY page for demotivators and had to create one for Ruby. Enjoy!

]]>
http://amazing-development.com/archives/2008/04/06/ruby-demotivator/feed/ 0
EURUKO 2008 Day 2 http://amazing-development.com/archives/2008/03/30/euruko-2008-day-2/ http://amazing-development.com/archives/2008/03/30/euruko-2008-day-2/#comments Sun, 30 Mar 2008 08:42:14 +0000 Frank Spychalski http://amazing-development.com/archives/2008/03/30/euruko-2008-day2/ Second day has started. Today it starts with a few talks on testing…

George Malamidis — „Synthesized Testing“

Already 15min behind schedule, but so far interesting.

This has 4 lines of code. It is already a big ruby function.

Vassilis Rizopoulos — „rutema: One test tool to rule them all“

I’m thinking on how to write in a polite way “This talk was boring”. It was. And the tool uses XML :-( Hey, this is a Ruby conference- you should use YAML or even better a cool Ruby DSL.

Tomasz Stachewicz — „Sharing the load“

Sounded interesting but there was a question after the talk which suggested that the guys reinvented the wheel and that BackgroundDrb is a better solution for what he has done.

Petr Krontorád — „Building Rails Playground – using Ruby’s dynamic nature“

Mumble, mumble, small text, cannot read the slides, mumble… Sorry I don’t have a clue what this talk is about.

Tim Becker — „Lessons Learned Writing Native Extensions“

Type-along tutorial on how to write C extension for Ruby. Very interesting, this could actually make me write C code again… He has started talking on cats and tigers and it seems like he wants to teach us how arrays work in C. Booooooooring. Finally he is done with this and is back on the interesting topics like conversion of data types. Overall a really interesting talk. By far the best one today so far. Tim’s post with code samples and links.

Matt Ford — „Aspect Oriented Programming in Ruby“

It’s his birthday. Happy birthday Matt! He talks about Aquarium a neat aspect oriented programming solution for Ruby. Very nice. I have to play around with this when I’m back home.

Dushan Wegner — „Philosophy & Programming“

This first lightning talk. “Imagine I’m holding a beer and put out this ideas”. “Programmers are better philosophers”. A very cool talk about the similarities of programming and practicing philosophy.

Marcin Raczkowski — „Distributed programming with ruby“

Hard to understand but interesting. Sadly it is impossible to read his code when he is showing examples in the editor.

sorry missed name and title Akira Tanaka – „IO.copy_stream“

Interesting talk about IO in Ruby. Great final “status” slide:

Accepted by Matz yesterday @La fabrica
Submitted today to Ruby 1.9

Wow!

Gregor … — „Context-oriented programming for Ruby“

Took a long time to get to the point. Which part of lightning talk did you not understand.

Florian Gilcher — „Patterns (yet another) pattern matching library“

Interesting talk. Can be found at patterns.rubyforge.org.

Raimonds Simanovskis — „Using Ruby with Oracle“

Good quick talk. I never had to work with Oracle so I never had the problems he was talking about.

Daniel Liszka — „One RubyStack to Rule them All“

Strong accent, to much text on the slides. But sounds like a neat idea… www.bitnami.org/stack/rubystack

Ry Dahl — „Ebb Web Server“

Yet another Ruby web server, obviously it’s faster than all the others because what would be the point otherwise. ebb.rubyforge.org

Wouter de Bie — „Capistrano, Webistrano“

The final lightning talk. I’m hungry :-) off to find some food…

Dr Nic — Demo

So it wasn’t the last talk. They squeezed in a short demo on how to use his gem generator. Very cool! I have to use this to play around with native C extensions.

Final announcement

It seems like next year’s EURUKO will be in Madrid. Great! Never been there. See you next year! It’s not decided yet. Krakow and Warsaw are possible sites, too. Hm, I’m still for Madrid :-)

Sumary

I think I should have slept in today like Todd and would not have missed a bit. Here are some pictures from EURUKO 2008 on Flickr and even one with me. EURUKO was great. A big “thank you!” to all the people who have organized it. I’m sure I will be back next year, no matter where.

]]>
http://amazing-development.com/archives/2008/03/30/euruko-2008-day-2/feed/ 5
EURUKO 2008 Day 1 http://amazing-development.com/archives/2008/03/29/euruko-2008-day1/ http://amazing-development.com/archives/2008/03/29/euruko-2008-day1/#comments Sat, 29 Mar 2008 09:15:30 +0000 Frank Spychalski http://amazing-development.com/archives/2008/03/29/euruko-2008/

The first day of EURUKO 2008 is over.

Yukihiro „Matz“ Matsumoto — „Keynote“

Matz talked about the future of Ruby. It was very interesting. He talked a little bit about the upcoming features (I will link to the slides when they become available) and about the design decisions behind Ruby. For me the most important quote was:

I designed Ruby not to work best but so that people can perform best

Koichi Sasada — „Ruby meets VM“

Koichi explained some details of YARV but some points were lost because a few of his slides were in Japanese.

Favorite quote:

(on his “No Ruby/No Life shirt”) for me it’s No Ruby / No Job

Charles Nutter and Thomas Enebo — „JRuby: Ready For Action!“

Made me download JRuby during the talk :-)

David A. Black — „Per-Object Behavior in Ruby“

I have to reread the slides, because I fell asleep (not due to the talk but to the fact that we are in Prague and had a few beer yesterday)

Nic Williams — „Meta-Meta-Programming with Ruby“

Memorable talk, very funny, great final slide (see @16:35)

Lightning talks session

Two talks on an agile white board and on a Ruby to PHP compiler.

VC with DHH

a little boring, bad sound quality and even worse video

]]>
http://amazing-development.com/archives/2008/03/29/euruko-2008-day1/feed/ 1
EURUKO 2008 — European Ruby Conference http://amazing-development.com/archives/2008/02/26/euruko-2008-%e2%80%94-european-ruby-conference/ http://amazing-development.com/archives/2008/02/26/euruko-2008-%e2%80%94-european-ruby-conference/#comments Tue, 26 Feb 2008 20:21:02 +0000 Frank Spychalski http://amazing-development.com/archives/2008/02/26/euruko-2008-%e2%80%94-european-ruby-conference/ I just found out about EURUKO 2008. It will take plaze in Prague, Czech Republic, on March 29th to 30th. From what I’ve heard are EURUKOs fun events and I would like to go this year if I can find the time especially because of this announcement:

19. 02. 2008 · Matz is coming to EURUKO!
We are very happy to announce that Matz (most probably accompanied by Koichi) is coming to EURUKO! There are currently more than 100 people registered to attend, so thank you all! We will update the website in next couple of days with more details on program, information about sponsors and other stuff.

It has been some time since I used Ruby but it is still my favorite language by far.

Update:

I just registered for EURUKO :-) I will probably go by car so if someone from the Munich area needs a ride, just leave a comment… And a bonus feature: I found this Tech Talk of Matz talking about Ruby 1.9 today…

]]>
http://amazing-development.com/archives/2008/02/26/euruko-2008-%e2%80%94-european-ruby-conference/feed/ 0
JRuby on Android http://amazing-development.com/archives/2007/12/14/jruby-on-android/ http://amazing-development.com/archives/2007/12/14/jruby-on-android/#comments Fri, 14 Dec 2007 03:43:27 +0000 Frank Spychalski http://amazing-development.com/archives/2007/12/14/jruby-on-android/ a red robotToday I tried to run JRuby on Android. I failed. This article is more like a lab report so expect more boring details…

At first I tried the easiest way and added the JRuby jar to my android project. This would have been way to easy and as I expected it did not work.

Then I copied all the JRuby sources into my android project and eclipse gave me more than 100 errors. I had to remove org.jruby.javasupport.bsf.BSFExample and the whole org.jruby.demo package because of dependencies to awt and swing. Now only a single error message was left with a dependency on some class I can’t remember in java.beans. So I downloaded the Java sources and copied the class into my project which gave me a few new dependencies. So I copied the whole java.beans package into the project and removed all dependencies to awt and swing from the code. Now I needed to add only 2 more classed com.sun.beans.ObjectHandler and sun.awt.EventListenerAggregate for eclipse to stop complaining.

a red robotAt this point I encountered my first bug in Android: dx(the compiler for Dalvik) complained about the bsf.jar file which came with JRuby[1]. Fortunately I could work on with the 2.4.0 version of bsf.

At this point eclipse stopped complaining and dx was able to create Dalvik byte code for my test application and package the result.

But when I started the result on the emulator all I got was an exception… This is where I will stop for today and continue whenever I find some time. If someone out there has already successfully used JRuby on Android please leave me a comment on how you managed to do it.

[1] the bug was fixed less than 3h after I reported it. Kudos to the Dalvik team!

]]>
http://amazing-development.com/archives/2007/12/14/jruby-on-android/feed/ 5
Tab-completion and syntax-highlighting for irb http://amazing-development.com/archives/2006/12/31/tab-completion-and-syntax-highlighting-for-irb/ http://amazing-development.com/archives/2006/12/31/tab-completion-and-syntax-highlighting-for-irb/#comments Sun, 31 Dec 2006 11:41:15 +0000 Frank Spychalski http://amazing-development.com/archives/2006/12/31/tab-completion-and-syntax-highlighting-for-irb/ wirble shell example on dark background
wirble shell example on light background

Please forgive me if I state the obvious, but I just found out about this great gem called Wirble. Wirble adds tab-completion and syntax-highlighting to irb.

Installation is really simple, just install the gem (gem install wirble) and add this to your .irbrc:

require 'rubygems'
require 'wirble'

Wirble.init
Wirble.colorize

For a console with a dark background everything looks pretty good but I prefer a light background where yellow is not easy to read. Thanks to the really helpful README the solution was easy to find. I had to add a few more lines to my .irbrc to change some settings from yellow and white to something readable in my console.

require 'rubygems'
require 'wirble'

Wirble.init
Wirble.colorize

colors = Wirble::Colorize.colors.merge({
  :object_class => :purple,
  :symbol => :purple,
  :symbol_prefix => :purple
})
Wirble::Colorize.colors = colors

]]>
http://amazing-development.com/archives/2006/12/31/tab-completion-and-syntax-highlighting-for-irb/feed/ 3
Magic Ruby Hacker mug http://amazing-development.com/archives/2006/12/12/magic-ruby-hacker-mug/ http://amazing-development.com/archives/2006/12/12/magic-ruby-hacker-mug/#comments Tue, 12 Dec 2006 21:19:08 +0000 Frank Spychalski http://amazing-development.com/archives/2006/12/12/magic-ruby-hacker-mug/ ruby hacker logo in courier

There is a CafePress shop for RubyHacker stuff with a few nice thingies. But I wanted something else :-)

magic mug

A shop (fotokasten.de) sells all-black mugs which only reveal the image when something hot is inside. Therefore I needed my own RubyHacker image and couldn’t find one online. To save everybody else the work, here’s my result.

I will post images of the mug when I have it :-)

Update:
I made a mistake and put the wrong image online. Fotokasten does not accept gif (which is pretty lame but I cannot change it). Changed the image to a jpg.

]]>
http://amazing-development.com/archives/2006/12/12/magic-ruby-hacker-mug/feed/ 0
Ruby search engine http://amazing-development.com/archives/2006/10/24/my-own-ruby-search-engine/ http://amazing-development.com/archives/2006/10/24/my-own-ruby-search-engine/#comments Tue, 24 Oct 2006 12:31:10 +0000 Frank Spychalski http://amazing-development.com/archives/2006/10/24/my-own-ruby-search-engine/ When I read that Google offers customizable search engines, I spent a few minutes to create one for my usual ruby searches. It can be found here. Right now, it doesn’t look very nice and I added only about a dozen sites, but I will add more and fine-tune the searches in the next few days. If anybody else wants to contribute, be my guest…

Update:
Google provides a bookmarklet called Google Marker, which helps adding new sites. This morning I added about 20 new sites and tweaked the searches.

Update:
This morning I added a few more pages and changed the default behavior from “Search the entire web but emphasize included sites.” to “Search only included sites.”.

Update:
3 contributors have signed up and I added a lot of new sites. Go visit Ruby & Rails Search and test it.

]]>
http://amazing-development.com/archives/2006/10/24/my-own-ruby-search-engine/feed/ 2
Profiling Rails Unittests http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/ http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/#comments Mon, 02 Oct 2006 15:38:40 +0000 Frank Spychalski http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/ 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.

]]>
http://amazing-development.com/archives/2006/10/02/profiling-rails-unittests/feed/ 0
Playing on the CodeGolf Range http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/ http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/#comments Mon, 07 Aug 2006 19:51:14 +0000 Frank Spychalski http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/ 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.

Warning! Spoilers ahead - you might want to stop reading if you want to solve the problem, too

Brainfuck Interpreter Version 1 - a real interpreter

This was my very first idea. The algorithm is pretty obvious and nothing really fancy was done here. Two optimizations:

  • aggregated the + and - operation and < and > into one when each to save space
  • iterate over the input program to get the target addresses for the jump operations

But this code was still too slow. It passed the first 5 tests, but failed the rot13 performance test.

# Version 1 after a lot of rewrites

data = Array.new(30000,0)
datapointer = 0
codepointer = 0

(code,input) = STDIN.read.chomp.split '!'

# build a jump table to quickly access target address to jump to
stack = []
jmptbl = {}
(0..(code.size-1)).each {|i|
  case code[i]
    when 91: stack.push i
    when 93: m = stack.pop; jmptbl[i] = m; jmptbl[m] = i  
  end
}

while codepointer < code.size do
  x = code[codepointer]
  case x
# < >
    when 60, 62: datapointer = datapointer + x - 61 
# + - 
    when 43, 45: data[datapointer] = (data[datapointer] - x + 44) % 256
# [
    when 91: codepointer = (data[datapointer] == 0 ? jmptbl[codepointer] : codepointer)  
# ]             
    when 93: codepointer = (data[datapointer] != 0 ? jmptbl[codepointer] : codepointer)
# .
    when 46: print "#{data[datapointer].chr}" 
# ,    
    when 44: data[datapointer] = input.slice!(0)
             exit if data[datapointer].nil?   
  end
  codepointer = codepointer + 1  
end
# Version 1 obfuscated 
# 389 characters without this comment
d=Array.new(30000,0)
a=0
b=0
(c,k)=STDIN.read.chomp.split'!'
s=[]
j={}
(0..(c.size-1)).each{|i|
case c[i]
when 91:s.push i
when 93:m=s.pop;j[i]=m;j[m]=i  
end
}
while b<c.size do
x=c[b]
case x
when 60,62:a=a+x-61 
when 43,45:d[a]=(d[a]-x+44)%256  
when 91:b=(d[a]==0?j[b]:b) 
when 93:b=(d[a]!=0?j[b]:b)
when 46:print"#{d[a].chr}"
when 44:d[a]=k.slice!(0)
exit if d[a].nil?  
end
b=b+1  
end

Brainfuck Interpreter Version 2 - "optimize - don't do it"

This code contains many useless optimizations :-)

  • store the target address inside the program as the address for ] or address plus codesize for [
  • store + and - as -255 and -257, so I can simply add the command to the data

But these optimizations didn't provide any significant speedup, the code was only about 10 percent faster on my machine which was still too slow to pass the performance test. And the program was even larger than my original version with 533 characters. I could perhaps squeeze out a few characters with a complicated formula for the first 6 lines of the case statement, but I didn't try this because this version was too slow anyway.

# version 2 - forget it, it sucks
data = Array.new(30000,0)
codepointer = 0
datapointer = 0

(code,input) = STDIN.read.chomp.split '!'

codesize = code.size
stack = []
opt = []
(0..(codesize-1)).each {|i|
  case code[i]
    when 60: opt << -3
    when 62: opt << -1
    when 43: opt << -255 
    when 45: opt << -257 
    when 44: opt << -5 
    when 46: opt << -6     
    when 91: stack.push opt.size; opt << 0 # just a placeholder
    when 93: m = stack.pop; opt[m] = opt.size + codesize; opt << m  
  end
}
while codepointer < opt.size do
  x = opt[codepointer]
  if x < -200
    data[datapointer] = (data[datapointer] + x) % 256
  elsif x < -3
    if x == -5
      data[datapointer] = input.slice!(0)
      exit if data[datapointer].nil?
    else
      print "#{data[datapointer].chr}"
    end   
  elsif x < 0
    datapointer = datapointer + x + 2  
  else 
    if x < codesize
      codepointer = (data[datapointer] != 0 ? x : codepointer)    
    else 
      codepointer = (data[datapointer] == 0 ? x % codesize : codepointer)
    end
  end
  codepointer = codepointer + 1  
end

Brainfuck Interpreter Version 3 - Brainfuck to Ruby

As I realized I wasn't going to pass the performance test with my other ideas I knew I had to generate Ruby code. The tricky part was how to simulate the commands "[" and "]". I started with the "Hello World!" Brainfuck program and rewrote it step by step in Ruby until I had an idea on how to replace every character of the input language with a chunk of Ruby code.

picture by digitalsextant

My translation table:
[ if currentCell != 0
begin
] end while currentCell != 0
end
< plus -1
> plus 1
+ inc 1
- inc -1
. out
, read

The definitions for the methods are shown below. The whole program was slightly larger than my version 1 but it is about 3 times faster, which was fast enough to pass the performance test.

# Version 3
def currentCell
  $data[$datapointer] || 0
end
def inc i
  $datapointer = $datapointer + i
end
def plus i 
  $data[$datapointer] = currentCell + i) % 256
end
def out
  print "#{currentCell.chr}"
end
def read
  $data[$datapointer] = $input.slice!(0)
  exit if !$data[$datapointer]
end
def append s
  $program << s << "
" 
end

$program = ''
$data = []
$datapointer = 0

($code,$input) = STDIN.read.chomp.split '!'

(0..($code.size-1)).each {|i|
  tmp = $code[i]
  case tmp
    when 60,62: append "inc #{tmp-61}"
    when 43,45: append "plus #{44-tmp}"
    when 91: append "if currentCell != 0
begin"
    when 93: append"end while currentCell != 0
end"
    when 46: append "out"
    when 44: append "read"
  end
}
eval $program 
# Version 3 obfuscated
# 401 characters without this comment
def x
$d[$a]||0
end
def y i
$a=$a+i
end
def v i 
$d[$a]=(x+i)%256
end
def t
print"#{x.chr}"
end
def u
$d[$a]=$k.slice!(0)
exit if !$d[$a]
end
def r s
$p<<s<<"
"
end
$p=''
$d=[]
$a=0
($c,$k)=STDIN.read.chomp.split'!'
(0..($c.size-1)).each{|i|
q=$c[i]
case q
when 60,62:r"y #{q-61}"
when 43,45:r"v #{44-q}"
when 91:r"if x!=0
begin"
when 93:r"end while x!=0
end"
when 46:r"t"
when 44:r"u"
end
}
eval $p

What's next?

I had a lot of fun writing these different versions. But now I'm stuck. I don't have the slightest clue on how to get to an even shorter piece of code. I already tried to add a method which generates the methods currentCell, inc, etc. but the overhead of one added method was more than what I gained by removing def and end.
I'm still thinking about other possible techniques to move towards the 142 byte by carldr. I believe there is a trick that uses special knowledge of the Brainfuck language I just don't have. If anybody has some generic hints on how to write shorter Ruby code, please leave a note :-)

]]>
http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/feed/ 6
Planning a Ruby course – request for comments http://amazing-development.com/archives/2006/07/31/planning-a-ruby-course-request-for-comments/ http://amazing-development.com/archives/2006/07/31/planning-a-ruby-course-request-for-comments/#comments Mon, 31 Jul 2006 09:12:35 +0000 Frank Spychalski http://amazing-development.com/archives/2006/07/31/planning-a-ruby-course-request-for-comments/ 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.

Here is a very rough draft:

Day 1

  • Hello & Intro (30min)
  • playing with Variables, Strings and Numbers in irb (30min)
  • Array, Hash, Range in irb (30min)
  • 1st script with puts, gets, if, then (60min)
  • Blocks, Methods (60min)
  • Classes and Instances (60min)

Day 2

  • Flow Controll (60min)
  • Exceptions (30min)
  • Closures (60min) at least ;-)
  • The Ruby Way (60min)

Did I forget something essential? I hope not. I’m still looking for a few simple and short examples which show the differences and advantages of Ruby. At first I thought I would use something from the Rubyquiz but I think these excercises take too much time. At the end of the second day I would like to write one “larger” program, so far I like the idea from PostHelloWorld to parse text and create a histogramm for the words found, like the one described in this tutorial.

]]>
http://amazing-development.com/archives/2006/07/31/planning-a-ruby-course-request-for-comments/feed/ 4
Road to Ruby enlightenment – lambda, proc etc. http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/ http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/#comments Sun, 02 Jul 2006 12:39:37 +0000 Frank Spychalski http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/ This is the fourth part of my Road to Ruby enlightenment. It started a long time ago with tutorials and first steps.

Road To Ruby Enlightenment
1. tutorials and first steps
2. talk, quiz and cookbook
3. red and gray
4. lambda, proc etc.

Blocks and closures are one of the reasons why you can do magic in Ruby. Some time ago I read Eli’s Understanding Ruby blocks, Procs and methods which does a great job of explainig the whole topic. As long as it doesn’t involve some high-level ruby magic (like Why’s A Block Costume) I felt like I understood most of the code using closure-like constructs.

When I used closures in my own code, every once in a while something would not work the way I expected it to. I always found a workaround and never spend much time worrying about these oddities.

This morning (via Ruby Inside) I found closures-in-ruby.rb by Paul Cantrell. Seems like he had the same problems but instead of ignoring them he played around and documented the things he found out. The article highlights some suprises and differences between the 7 ways of creating closure-like thingies in ruby. Highly recommended reading!

]]>
http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/feed/ 0
Java 6 (aka Mustang) goes Ruby http://amazing-development.com/archives/2006/06/18/java-6-aka-mustang-goes-ruby/ http://amazing-development.com/archives/2006/06/18/java-6-aka-mustang-goes-ruby/#comments Sun, 18 Jun 2006 18:31:16 +0000 Frank Spychalski http://amazing-development.com/archives/2006/06/18/java-6-aka-mustang-goes-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 :-)

]]>
http://amazing-development.com/archives/2006/06/18/java-6-aka-mustang-goes-ruby/feed/ 0
Road to Ruby enlightenment – red and gray http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/ http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/#comments Tue, 16 May 2006 07:57:29 +0000 Frank Spychalski http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/ This is the third part of my Road to Ruby enlightenment. It started with tutorials and first steps.

Road To Ruby Enlightenment
1. tutorials and first steps
2. talk, quiz and cookbook
3. red and gray
4. lambda, proc etc.

RedHanded

RedHanded is Why’s (from Why’s (Poignant) Guide to Ruby) blog. I don’t really know why I didn’t check out his blog earlier when I read WPGtR but I didn’t.

But I think this was a good thing, because I already knew a little bit about Ruby when I stumbled over his blog. This made reading his dazzling display of ruby magic more fun, like watching a stage magician with a slight chance of understanding and appreciating his tricks.

Go and check out bits and inspect. My all time favorint post is Camping Microframework, the code is cryptic and I cannot say I understand it but the whole post is hilarious (here is the real docu for Camping, a <4kb webframework).

Shades of Gray

In another post on this blog I asked for advanced articles on ruby and Pat pointed me to Shades of Gray. I already knew the author James Edward Gray II as the organizer of the Ruby Quiz. Shades of Gray contains exactly the kind of articles I was looking for all the time. The only sad thing is that it contains only a handful of these articles. His Higher Order Ruby posts provide Ruby translations of the example code from the book Higher Order Perl, his Ruby tutorials are among the best I’ve ever read and his other posts are worth reading, too.

If you read only a single sentence about good ruby style, it should be this one from Code as a Data Type:

In my experience, you know you’re doing Ruby right when you are dropping code and gaining functionality

This is true for almost any language, but in Ruby it is especially elegant to do. I guess this is the reason why I like programming in Ruby, it gives you the ability to write very compact but still readable code.

I’m getting pretty close to the present, but I hope I will find enough content for another post in this series so check again later…

BTW, if you have recommendations with other sites/articles/books on good ruby style, please let me know.

]]>
http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/feed/ 2