Archive for the ‘Ruby’ Category

DB Content Rails Plugin

Thursday, April 17th, 2008

The DB Content Rails plugin adds tasks to save and restore database content.

Usage

[code]

– dump the development database to db/archive/development-content.sql.gz
rake db:content:dump – load the dumped database, and apply any necessary migrations
$ rake db:content:load – dump the production database to db/archive/production-content.sql.gz
$ RAILS_ENV=production rake db:content:dump – save the development database to db/archive/{timestamp}.sql.gz
$ rake db:content:save – save the (compressed) database to my-data.sql.gz
$ rake db:content:save FILE=my-data.sql.gz
Read the rest of this entry »

JCON: Ruby Gem for JSON type conformance

Thursday, April 17th, 2008

JCON (the JavaScript Conformance gem) tests JSON values against ECMAScript 4.0-style type definitions
(PDF) such as string?, (int, boolean), or [string, (int, boolean), {x:double, y:double}?].

Usage

[code language=”ruby”]
type = JCON::parse ”[string, int]”
type.contains?([‘a’, 1]) # => true
type.contains?([‘a’, ‘b’]) # => false
type.contains?([‘a’, 1, 2]) # => true
[/code]

JCON also defines an RSpec matcher, conforms_to_js:


Read the rest of this entry »

JavaScript Fu Rails Plugin

Monday, April 14th, 2008

JavaScript Fu extends Rails with a few facilities to better integrate JavaScript into Rails development:

1. The notes and statistics rake tasks compass JavaScript files in the public/javascript directory:

[code language=”bash”]
$ rake notes
public/javascripts/controls.js:

* [782] [TODO] improve sanity check
[/code]

[code language=”bash”]
$ rake stats

| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
[...]

| JavaScript | 7287 | 6322 | 0 | 0 | 0 | 0 |
[...]
[/code]

2. The call_js RSpec matcher asserts that a string or response contains a script tag, that contains JavaScript that calls the named function or method:


Read the rest of this entry »

FizzBuzz Station

Thursday, February 28th, 2008

Uh oh! I overthought fizzbuzz:


Read the rest of this entry »

reWork: an online workbench for regular expressions

Thursday, February 23rd, 2006

reAnimator got me interested in writing something that would let you use regular expressions. That something is reWork. This web page has a couple of fields where you can type in a regular expression and a string to match it against, and see the results update as you type. It also displays the code to perform the match in some of the languages (JavaScript, PHP, Python, and Ruby) that I use with regular expressions.

reWork limited to the features of the JavaScript regex engine. In particular, it’s missing dotall (/.../s), because JavaScript is. I actually figured out a hack to implement dotall anyway, but this will have to wait for another day.


Read the rest of this entry »

OpenLaszlo Ruby library

Thursday, January 5th, 2006

openlaszlo.rb is a Ruby library for compiling OpenLaszlo programs. I use it to build this, this, and the toolbar here. This article describes how to use it with Rake.

Update: This is now available as a gem.


Read the rest of this entry »

Ruby and Laszlo

Tuesday, March 8th, 2005

I first heard of Ruby at the second Lightweight Languages Workshop 2, where Matz and I were both speakers. This was first public disclosure of the then-proprietary Laszlo platform language. I’m afraid I was more worried about preparing my talk then listening to Matz at the time!

Since then, a number of different people have expressed interest in both Laszlo and Ruby. I figured I had finally better take a look at it.


Read the rest of this entry »