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
But last week I helped Damon to finally support JRuby on his Android Scripting Environment (ASE).
$ 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>
But beware! The new ASE apk is HUGE (4.6M) and JRuby is fairly slow. But it works
Already 15min behind schedule, but so far interesting.
This has 4 lines of code. It is already a big ruby function.
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.
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.
Mumble, mumble, small text, cannot read the slides, mumble… Sorry I don’t have a clue what this talk is about.
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.
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.
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.
Hard to understand but interesting. Sadly it is impossible to read his code when he is showing examples in the editor.
Interesting talk about IO in Ruby. Great final “status” slide:
Accepted by Matz yesterday @La fabrica
Submitted today to Ruby 1.9
Wow!
Took a long time to get to the point. Which part of lightning talk did you not understand.
Interesting talk. Can be found at patterns.rubyforge.org.
Good quick talk. I never had to work with Oracle so I never had the problems he was talking about.
Strong accent, to much text on the slides. But sounds like a neat idea… www.bitnami.org/stack/rubystack
Yet another Ruby web server, obviously it’s faster than all the others because what would be the point otherwise. ebb.rubyforge.org
The final lightning talk. I’m hungry off to find some food…
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.
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
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.
]]>The first day of EURUKO 2008 is over.
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 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
Made me download JRuby during the talk
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)
Memorable talk, very funny, great final slide (see @16:35)
Two talks on an agile white board and on a Ruby to PHP compiler.
a little boring, bad sound quality and even worse video
]]>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…
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.
At 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!
]]>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
There is a CafePress shop for RubyHacker stuff with a few nice thingies. But I wanted something else
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.
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.
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.
]]>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.
This was my very first idea. The algorithm is pretty obvious and nothing really fancy was done here. Two optimizations:
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
This code contains many useless optimizations
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
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.
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
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
Here is a very rough draft:
Day 1
Day 2
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.
]]>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!
]]>So it seems like Java is slowly getting more humane
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.
]]>