Archive for the ‘Computers’ Category

Using ruby2ruby for translating ruby code

Thursday, March 26th, 2009

Once upon a time, I wanted to be able to generate RPN-style code from a more common Ruby-based syntax (and DSL). Fast-forward, I have been playing today with ParseTree and ruby2ruby (Thanks Ol for the hints!); The latter provides a to_sexp method on all Proc objects (which was lacking from the former). Given that a sexp is an abstract representation of a code portion, I can then use this structure to generate a new representation (in RPN, obviously) using my own “compiler”.

A real simple example (extracted from my test suite), with just an arithmetic operation:

    assert_equal "kmh,8,*", evaluate_rpn_block {
      kmh * 8
    }

The evaluate_rpn_block method calls ruby2ruby’s to_sexp and then goes through the result tree. A more complete example of what can be done:

    assert_equal "kmh,100,GT,0,kmh,IF", evaluate_rpn_block {
      if kmh > 100 then
        0
      else
        kmh
      end
    }

From there, what is lacking would be plugging the internal available functions (and operators) and matching the names used with existing definitions.

How I Learned to Stop Worrying and Love… Hpricot

Tuesday, March 17th, 2009

When I first started to code scripts with Ruby, one of the features that I loved was the Rexml library which made parsing XML just a breeze, most likely because I was coming from a Perl/Sax background and at the time I was surrounded by Java programmers, but also because it really is that easy to use.
At home, I have this small script that takes a XML file listing books that I have, do stuff to it and outputs more XML but in a different format and with some filtering. At first, it was ok. But recently, the source XML file got a bit hairy and larger that it used to be (just 2MB, but that’s already a bit of a constraint). So I looked around a bit, and in fact there are now a few alternatives which are faster; One of them being Hpricot which is originally an HTML parser (as I already used it earlier on) but which also works well for well-formed XML. And in fact, it isn’t much harder to use (even easier at some point) and yes, it is faster. The same script (almost) is about 7 times as fast using Hpricot rather than good ol’ Rexml. Ok, I’m convinced. (more…)

Dear google reader developers…

Saturday, February 28th, 2009

Automatic translation is nice, but please, allow it on a per-post basis instead of per-feed. kthxbye. (more…)

new best gmail lab feature

Tuesday, February 3rd, 2009

Single send & archive button. Grrrrrrrrreat.

(more…)

self emacs function reminder

Saturday, January 17th, 2009

This is list-matching-lines that I’m always looking after in my feeds

google reader tags.. err… folders?

Monday, November 17th, 2008

So they renamed their tags as folders. But they still act as tags. Don’t people get confused by the “change folders” behavior?

gmail mac notifier wtf?!

Saturday, October 11th, 2008

Downloading gmail mac notifier brings a dmg file (ok) which only contains a shell script (wt?) which opens another URL to download the notifier (W-T-F-F?!). What’s wrong with you, people, seriously?

Dear Google Calendar people

Monday, October 6th, 2008

Please, follow your gmail friends and add lab features. And add the custom colors feature, kthxbye.

how do I include sparkline in a Jasper report using JRuby?

Friday, September 19th, 2008

Assuming that you have some way to get your source data, and that you already have followed instructions to do sparklines with JRuby and JFreeChart, you must first declare an image inside your report:

  <field name="Spark" class="net.sf.jasperreports.engine.JRRenderable"/>
[...]
  <image scaleImage="Clip" hAlign="Center" hyperlinkType="Reference">
    <reportElement x="200" y="0" width="150" height="30"/>
    <graphicElement/>
    <imageExpression class="net.sf.jasperreports.engine.JRRenderable"><![CDATA[$F{Spark}]]></imageExpression>
  </image>

And then, from JRuby, you must implement the JRDataSource interface (that is, a basic iterator over your data) to provide the corresponding field encapsulated in a JCommonDrawableRenderer:

class MySparkLine
  import "net.sf.jasperreports.engine.JRDataSource"
  include JRDataSource  
  def getFieldValue( field )
    case field.getName()
    when "Spark"
      return JCommonDrawableRenderer.new( chartObject )
    end
  end
end

And that’s as easy as it gets.

precision

Thursday, September 18th, 2008




Maybe I shouldn’t trust Google spreadsheet about any kind of financial number handling.

About

My name is Sebastien Tanguy. This is my weblog. I am currently a software developer, but every now and then I also talk about music, books or photography.

 

July 2010
M T W T F S S
« May    
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives