2007-04-15 @ 16:41

Converting JavaScript to Ruby with RKelly

I’ve been working on a yet-to-be-released project called RKelly, which will parse JavaScript and return a parse tree suitable for passing to Ruby2Ruby. Ruby2Ruby will then give you back ruby code that you can eval.

I thought I would share a few examples of what I have working so far, and also write a bit about where I want to go.

I have most simple looping working. For example, a for loop:

1
2
3
4
5
6
7
8
9
require 'rkelly'
require 'ruby2ruby'

rkelly = RKelly.new
puts RubyToRuby.new().process(rkelly.process(DATA.read))
__END__
for(var i = 0; i < 10; i++) {
  alert('hello world');
}

Will produce:

1
2
3
4
5
6
7
8
begin
  i = 0
  while (i < 10) do
    alert("hello world")
    [i, i = (i + 1)].first
  end

end

You can even calculate the Fibonacci sequence:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require 'rkelly'
require 'ruby2ruby'

rkelly = RKelly.new
puts RubyToRuby.new().process(rkelly.process(DATA.read))
__END__
function fib(n) {
  var s = 0;
  if(n == 0) return(s);
  if(n == 1) {
    s += 1;
    return(s);
  } else {
    return(fib(n - 1) + fib(n - 2));
  }
}

Which produces:

1
2
3
4
5
6
7
8
9
10
def fib(n)
  s = 0
  return s if (n == 0)
  if (n == 1) then
    s = (s + 1)
    return s
  else
    return (fib((n - 1)) + fib((n - 2)))
  end
end

Why am I torturing myself like this? I want to add JavaScript support to Mechanize, and I think I can do that with RKelly. So far I have been able to use RKelly for simple DOM manipulation with a slightly modified copy of Mechanize. If you would like to see that in action, just find me at one of the Seattle Ruby Brigade meetings.

I’ve also added some simple object support, which you can see after the jump.

read more »

2007-04-15 @ 16:18

mechanize version 0.6.8 has been released!

The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.

Changes:

= Mechanize CHANGELOG

== 0.6.8

  • Keep alive can be shut off now with WWW::Mechanize#keep_alive
  • Conditional requests can be shut off with WWW::Mechanize#conditional_requests
  • Monkey patched Net::HTTP#keep_alive?
  • [#9877] Moved last request time. Thanks Max Stepanov
  • Added WWW::Mechanize::File#save
  • Defaulting file name to URI or Content-Disposition
  • Updating compatability with hpricot
  • Added more unit tests
read more »

2007-04-15 @ 16:11

SakuraCon 2007

Hey everyone. I totally went to Sakura Con. Stacy and I went to see Blades of Glory downtown, and as we were walking by the convention center, we saw a whole bunch of people dressed up in costume. After the movie we went in to the convention center to check out the happenings. Upon arrival, I instantly felt uncomfortable because I was not dressed up! Everyone else was wearing costumes, and I stuck out. We decided to come back the next day and dress up. So Pam dressed as a squid, I dressed as a pork chop, Stacy dressed as a cupcake, and my sister dressed as a marching band person.

EatingIMG_0029.JPG

When we arrived the next day, it was like we were rock stars! I’ve never had so many people take pictures of me. It was a ton of fun, and I can’t wait to go again next year!

read more »

2007-04-24 @ 19:04

drawr version 1.0.0 has been released!

The author was too lazy to write a description

Changes:

== 1.0.0 / 2007-04-09

  • 1 major enhancement
    • Birthday!
read more »

2007-04-30 @ 19:49

Happy Birthday Courtney!

I went to Courtney’s birthday party the other night, and it was awesome. It was prom themed, and I rented a tux!

Check it: IMG_0136.JPGIMG_0086.JPGIMG_0076.JPG

Before the Prom, we went to Peicora and ate some awesome pizza. I guess the only difference between this and my last prom is that I didn’t drink this time. Maybe a few other things too…. Here are a couple photos that I enjoy:

IMG_0048.JPGIMG_0097.JPG

read more »