Activate your free membership today | Log-in

Monday, June 9th, 2008

Johnson: Wrapping JavaScript in a loving Ruby embrace, and ARAX

Category: JavaScript, Ruby

John Resig pointed us to Johnson, a project that "wraps JavaScript in a loving Ruby embrace."

It seems to give you a JavaScript interpreter that you can pass a context into to. The simple examples are:

RUBY:
    require "johnson"
     
    Johnson.evaluate("4 + 4") # => 8
    Johnson.evaluate("4 + foo", :foo => 4) # => 8

John saw the following code that gives you __FILE__ as a global that stores the file name a la Perl:

JAVASCRIPT:
  1.  
  2. (function(){
  3.   this.__defineGetter__("__FILE__", function() {
  4.     return (new Error).stack.split("\n")[2].split("@")[1].split(":").slice(0,-1).join(":");
  5.   });
  6. })();
  7.  

I am curious to see the itch that they guys are scratching here.

Of course, Silverlight is giving us ARAX according to John Lam. Darryl Taft reported on the news, and I quickly told him that JRuby has given us Ruby in the browser for quite some time. The latest Java plugin supports JNLP, and JRuby build a JNLP distribution for you if you want it. Silverlight is another vector for Ruby in the browser.

Ben said the following about the Silverlight version:

If this is about using Silverlight to host client-side browser scripting in Ruby, it's definitely an appealing notion, but the problem will always be about Silverlight being a Microsoft technology.

As long as Windows/Office dominates Microsoft's balance sheet, these cross-platform Microsoft plays always feel a bit like the story of the boy who upon encountering a rattlesnake picks it up after it promises not to hurt him, upon which the snake promptly bites. After the boy protests, the snake says: 'You knew what I was when you picked me up.' No matter what capabilities Silverlight may have, I think most of us in the community simply wouldn't dream of embracing architectures dependent on Microsoft's goodwill to support other OS vendors.

Posted by Dion Almaer at 6:05 am
3 Comments

+++--
3.6 rating from 18 votes

Wednesday, May 21st, 2008

classy_inputs: Rails plugin to add autoclass names

Category: CSS, Ruby

We all want to use input[type=text] but browser support doesn't seem to quite be there (IE 6?).

This lead James Coglan down the path of creating a teeny Rails plugin, classy_inputs:

Good lord do I ever hate input tags. (YUI hates them too, but I’ll leave that story for another time). All the different types should really have been different tag names, and they are a total pain to use with CSS. As such, I used to end up doing tedious stuff like adding a :class option to every form element when writing Rails templates. A while back, I tried to patch Rails to get it to do this automatically, but its test suite totally baffled me at the time by applying the classes in some places but not others.

So, a quick plugin to stave off RSI:

script/plugin install
http://svn.jcoglan.com/classyinputs/trunk/classy_inputs

With that installed, any input tag created using a Rails view method will gain a class name matching its type attribute. Maybe I’ll have another stab at patching Rails, but I’m not promising anything.

Posted by Dion Almaer at 9:50 am
6 Comments

++---
2.4 rating from 9 votes

Thursday, March 27th, 2008

HotRuby: Run Ruby on a JavaScript interpreter?

Category: JavaScript, Library, Ruby, Showcase

This is from the "wow, really?" department. HotRuby is an implementation of Ruby in JavaScript!

The way it works is that a HotRuby "VM" takes the resulting output from YARV and can grok it via JSON:

RUBY:
    VM::InstructionSequence.compile(cgi['src'], "src", 1, OutputCompileOption).to_a.to_json

Thus, you can embed Ruby by doing something like this:

HTML:
  1.  
  2.         <script type="text/ruby">
  3. class Pi
  4.         def initialize
  5.                 @a = 355.0
  6.         end
  7.        
  8.         def calc
  9.                 b = 113.0
  10.                 return @a / b
  11.         end
  12.        
  13.         PI = 'PI is about'
  14. end
  15.        
  16. puts Pi::PI
  17. puts Pi.new.calc
  18.         </script>
  19.  
  20. <body onload="prettyPrint(); new HotRuby().runFromScriptTag('/compileRuby.cgi')">
  21.  

Since you can run on any JavaScript interpreter or VM, they also support Flash.

For example, check out this Box2D example written in Ruby, running in Flash:

HotRuby Example

Posted by Dion Almaer at 8:01 am
3 Comments

+++--
3.5 rating from 27 votes

Wednesday, March 5th, 2008

Dynamic Silverlight Launched: Ruby and more in the browser

Category: Microsoft, Ruby

John Lam has posted about a new release, DSL: Dynamic Silverlight. I can't believe that Microsoft is going to take the DSL TLA ;)

Our team is happy to announce Dynamic Silverlight (DSL), which integrates our DLR dynamic languages with Silverlight. It requires Silverlight 2, which includes the cross-platform CLR and a set of libraries for rich graphics, media and web programming. It is packaged as a Silverlight extension, which means that it is downloaded in addition to Silverlight on an as-needed basis.

DSL has a runtime and an SDK component. The runtime consists of two assemblies: Microsoft.Scripting.dll, and Microsoft.Scripting.Silverlight.dll. You'll also need the language assemblies, which are IronRuby.dll and IronRuby.Libraries.dll for Ruby and IronPython.dll and IronPython.Modules.dll for Python. The runtime component is a small additional download. Today, the IronRuby Silverlight runtime is just a 712KB download, which takes less than 5 seconds to download over modern broadband.

Now you can get Ruby in your browser:

John also talked about Chiron, a mini Web server that lets you develop against a local file system with ease. We will find out more, and get access to the bits, on Friday when John gives his MIX talk.

Posted by Dion Almaer at 10:43 am
2 Comments

+++--
3.5 rating from 21 votes

Thursday, February 14th, 2008

Nextpoint: Taking Ajax to Court

Category: Prototype, Ruby, Scriptaculous, Showcase

I used to work in the healthcare sector, and was always amazed to see the amount of paperwork that was required. Literally paper work that is. The industry was full of drawers overflowing with paper.

I imagine that the legal profession has its fair share of this too, but one company Nextpoint, is trying to change that.

I had the opportunity to sit down with some members of the Nextpoint Lab, including Jim Halberg the Ajaxian, to get a tour and discuss their latest products. Below are a few questions about the Ajax implementation, and we finish up with a video showcasing the work.

What are the Nextpoint tools?

Nextpoint's flagship software product (marketing site, brochure), brings web 2.0 to the world of litigation software. We provide a powerful and easy to use way to manage the mountain of electronic information associated with any case.

What are some of the cool Ajax features?

The site has many small ajaxy features. Things like status bars for uploads or bulk operations, submitting small bits of data that shouldn't require traditional round-trips, or updating a small piece of the page with some results. The stuff we think Ajaxian readers would be more interested in mainly revolves around our work with images.

A real pain source for many years in trial litigation has been stamping documents. When you decide you want to use a document in court it must be stamped (i.e. "Defense Exhibit 1") and then communicated to the opposing team of lawyers. With most products today this means, locating the document in the management software; exporting it; printing it; physically stamping it; scanning it back in locally; uploading it back into the management software; and finally transmitting that electronic copy... it's not hard to see how this could get annoying after the 100th time you've had to do it this week. Nextpoint provides the ability to electronically add a customized stamp - these can be resized or repositioned as desired and because we're doing things electronically it's much easier to do things like "stamp these thousand documents as 'Defense Exhibits'". Believe it or not - the server normally can get this task done a bit quicker than a guy with a rubber stamp in his hand. When the machine is done stamping - they're already electronic copies - you're ready to go.

Our flashiest use of Ajax is in our presentation tool, "Theater". Many of our clients are using this tool to prepare document treatments before a trial, so that they're ready to call up at a moments notice in a pre-formatted state. It also may be used live in a courtroom to direct listeners attention to important points in a way that visually impresses. We'll show this off in the demo video we're going to provide.

What tools are used to create theater?

Theater is mostly a custom javascript application, using prototype and scriptaculous to simplify the Ajax communication and animation. The images are served from a Merb-based server, which uses the GD libraries to do scaling, rotating, cropping, and setting transparency on the fly. The transparency is especially important, so that HTML elements can be used as highlights behind the main image content, keeping the user interface very responsive.

What were the biggest challenges getting all of this Ajax stuff to work?

Even when using Ajax to keep the traffic between client and server light, the latency and server processing time can become quite apparent. Theater employs a few neat tricks to keep the application feeling responsive. The annotations on documents (mentioned above) are done with HTML elements, preventing the wait of a roundtrip to the server to get a new image. When loading new documents, a pre-generated medium-resolution image is loaded first, and then replaced with an exact-fit image once it's ready, which usually takes less than a second. Similarly, when creating callouts of an image section, the main document image is resized and cropped in a DIV in the browser as a low-resolution preview until the high-resolution version is available. The same thing happens when callouts get resized to make room on-screen for more callouts. Users feel more like they're working with an application when they can continue to work with the preview versions instead of waiting after each click.

Allowing users to resize and reposition a "stamp" on top of an image presented some challenges but most of the trouble in that interface emerged from making sure that the final position the user set with css/js was properly translated into coordinates that could be used for the actual image manipulation on the backend. Allowing a variety of stamp formats, variable amounts of text, and translating between entirely different measurement systems for fonts on the server vs. the browsers complicated things, as well as the oft-demanded rounded corners to make the stamps look "more natural".

Originally Theater was based around a tiled-image concept, like Google Maps. The images were pre-cropped into tiles at a few different "zoom" levels, and then further zoom levels were simulated by resizing in the browser. Unfortunately, storing 200+ images for each page of each document quickly became unmanageable. In addition, many browsers use a pretty low-quality algorithm for resizing images, leaving the in-between levels looking "chunky" or "distorted." Using the GD library, and a streamlined application server that doesn't load the entire Rails application, we were able to overcome this issue by generating images on the fly. That reduced the number of requests made to the server and creates pristine images of just the right size.

Demo

Below is a demo of the product. For a high quality version go here.

UPDATE: A new video showing the data stamping technique has been added. There is a normal version, and a high res one (must be a vimeo member for high res).

Posted by Dion Almaer at 9:01 am
6 Comments

++++-
4 rating from 40 votes

Sunday, February 10th, 2008

Heroku: Web based Rails Hosting

Category: Prototype, Rails, Ruby, Showcase

Heroku is a new YCombinator startup that joins the growing number of "use your browser to build your apps" type of applications.

You can create new Rails applications, and they are magically hosted up in the cloud. You can import your own Rails application, or you can use the inline editor and tools to built the application directly in the browser.

Heroku itself is a Rails application. I wonder if they now self hosting :)

Being able to quickly build an application and have it running live is great (using Amazon EC2), and this is just the beginning. They already tie into the usual tools like Rake, but there is room to go further and have nice DB utilities, cloning of functionality, and much more.

The editor itself could use a bunch of work too. I can never see where the cursor is, let alone have all of the Textmate / Aptana / IntelliJ goodness.

Heroku

Posted by Dion Almaer at 9:28 am
6 Comments

+++--
3.2 rating from 26 votes

Wednesday, January 23rd, 2008

Ext Scaffold Generator Plugin for Rails

Category: Examples, Ext, Rails, Ruby

Martin Rehfeld has released a Rails plugin that generates Ext JS scaffolds

The Ext Scaffold Generator Plugin provides a custom MIME type alias :ext_json to be able to handle requests from the Ext frontend separately. The generated controllers show how to do this.

To make data delivery to the Ext frontend easy, the plugin extends the Array and ActiveRecord::Base classes to provide a to_ext_json method. Here’s a simplified example of a potential index method in a PostsController:

RUBY:
    # GET /posts
    # GET /posts.ext_json
    def index
      respond_to do |format|
        format.html     # index.html.erb (will fire ext_json request)
        format.ext_json { render :json => Post.find(:all).to_ext_json }
      end
    end

He also has some other good articles on integrating Ext JS and Rails in general.

Posted by Dion Almaer at 6:54 am
2 Comments

+++--
3.9 rating from 24 votes

Thursday, January 10th, 2008

XSS: Flash and Rails

Category: Flash, Ruby, Security

A couple of good articles on XSS and security came out at the same time. One talks about XSS in Flash, and the other on Rails:

XSS Vulnerabilities in Common Shockwave Flash Files

Rich Cannings has written an article explaining the issue of XSS wrt Flash:

Critical vulnerabilities exist in a large number of widely used web authoring tools that automatically generate Shockwave Flash (SWF) files, such as Adobe (r) Dreamweaver (r), Adobe Acrobat (r) Connect (tm) (formerly Macromedia Breeze), InfoSoft FusionCharts, and Techsmith Camtasia. The flaws render websites that host these generated SWF files vulnerable to Cross-Site Scripting (XSS).

This problem is not limited to authoring tools. Autodemo, a popular service provider, used a vulnerable controller SWF in many of their projects.

Simple Google hacking queries reveal that hundreds of thousands of SWFs are vulnerable on the Internet, and a considerable percentage of major Internet sites are affected. We are only reporting XSS vulnerabilities that have been fixed by the vendors.

He talks through tools that cause the issue, and then solutions on how to keep yourself safe.

Is your Rails site XSS safe?

Stu Halloway of Relevance has written about SafeErb and how he got it working on a Rails 2.0 application. He kept notes as he went through the experience, allowing us to learn from his acts.

What is SafeErb?

Safe ERB lets you make sure that the string written by "<%= %>" in your rhtml template is escaped correctly. If you try to show the attributes in the ActiveRecord instance read from the database or the parameters received from the request without escaping them using "h" method, an exception will be raised. This will significantly reduce the possibility of putting cross-site scripting vulnerability into your web application.

The check is done using "tainted?" method in Object class which is a standard feature provided by Ruby - the string is "tainted" when it is read from IO. When ERB::Util#h method is called, this plugin "untaints" the string, and when "<%= %>" is called in your rhtml template, it raises an exception if the string you are trying to show is tainted.

Posted by Dion Almaer at 12:14 pm
Comment here

+++--
3.2 rating from 10 votes

Friday, January 4th, 2008

Zed Shaw interview on Rails community, enterprise, Ajax, patents, and a whole lot more

Category: Podcasts, Rails, Ruby

Rob Sanheim sat down with Zed Shaw at RailsConf and had an hour long conversation with him that covered his thoughts on the Rails community, the role of the Enterprise, the state of Ajax, JRuby and Rubinius, documentation, tests, tooling, the role of patents in software, and a whole lot of opinion.

Zed Shaw

It is very interesting to listen to this after the explosion that happened when Zed lambasted the Rails community. When you listen to this interview, you see some of the seeds of the rant, but it is a lot more toned down, and there is some good stuff in there. It is easy to blog a crazy rant.... but when you are talking to someone you get a different side of the coin. This gives you that side, from a time when he wasn't as upset as he may have been when he sat at the computer to type up his post.

Listen to the recording, or subscribe to the podcast. We will go back to more "standard" Ajax topics in the future.

Zed's Core Quotes

  • On Semantic Web: Einsteins brain on a crack whores body isn't going to happen
  • I'm waiting for someone to blind-side the entire Web stack
  • Some people hate me, but love Mongrel
  • Where is the XP for managers

And here are some of the thoughts that Zed expressed throughout the interview:

Thoughts on the Rails community, and enterprise (as big business)

  • Mixed feelings
  • Mongrel was an art project
  • Simpler software is better
  • Enterprise software is known to be complex, and survives to make money for consulting companies
  • Afraid of consulting companies getting behind it, as their interest is in selling 30 people vs. 3 people teams

What could an enterprise company sell?

  • Do enterprise stuff well such as Authentication
  • Stacks: Make it simple (no ClassLoader6)

JRuby

  • It is a huge deal
  • The only fear is that Sun will mess it up with the JCP.
  • The JRuby guys are rock stars

Rubinius

  • An open source project not controlled by anyone
  • A bunch of guys who really love Ruby
  • Massive "spec", working with the JRuby guys

State of Ajax

  • HTTP sucks
  • Needs to be a reset
  • Semantic Web: "Einsteins brain on a crack whores body isn't going to happen"
  • I'm waiting for someone to blind-side the entire Web stack
  • Ajax the technology doesn't impress me, but the new UIs that we are seeing is fantastic
  • Usability != better looking
  • "click here" actually does a really good job at having people click here!

What is going to come out with all of the work happening on top of Mongrel?

  • Swiftapply
  • Evented mongrel
  • DrProxy
  • OpenBSD clustering
  • X hits per day is meaningless. What is the peak?

Honest Open Source

  • Not all open source projects are equal
  • Make everything open and public immediately (e.g. SVN)
  • Corporate open source projects often lose their flavour
  • Outside commiters are key
  • Some people hate me, but love Mongrel
  • Documentation is poor for Rails and Ruby, Ruby doesn't have a culture for it
  • Rails core does a much better job that the Ruby community in general, and this is a reason why it took off
  • QRI command line. Way better than RI
  • If Rails core isn't using it, don't use it. Add: used_by

What tools do you use?

  • Vim
  • Use a generic tool, and pimp it
  • "I code with a thesaurus"
  • Vim is designed to be used on phone lines, and it is very safe
  • Good tools never cover your code

Testing

  • A bit of design up front
  • Design the API
  • Tests to measure how it is working
  • Quality comes from the design ahead of time

Posted by Dion Almaer at 7:55 pm
5 Comments

+++--
3 rating from 58 votes

Friday, November 30th, 2007

Placeshout: New Rails based Geo-cool site

Category: Mapping, Ruby, Showcase

Andre Lewis has a new site out there, Placeshout which offers a way to quickly call out your favourites place in various locations.

You could argue that we have other places for this... Yelp for example, or My Maps themselves. So, why Placeshout?

Sometimes, you just want a quick suggestion

When Andre and I are looking for a hole-in-the-wall Mexican restaurant or a park with a softball field, we usually just want a quick suggestion, not a lengthy review. We want to know if a place is worth visiting in 30 seconds.

Placeshout isn't about volume - it's about trying to express the positives and negatives of a destination in as few of words as possible. If people agree, that "shoutout" moves up...if they don't, the shoutout moves down and begins to disappear.

We hope Placeshout makes it easier for you to find local destinations.

There are some interesting features in this, very Web 2.0-looking, site. One that stands out is the enhanced mapping experience on top of Google Maps. As you move around, directional arrows tell you how far various other cities are away. It is kinda fun to watch:

Posted by Dion Almaer at 10:05 am
3 Comments

++---
2.9 rating from 17 votes

Saturday, May 19th, 2007

RailsConf 2007 - Day 1

Category: Conferences, Rails, Ruby

RailsConf is underway in Portland, Oregon, and day one (Friday) is in the bag. The keynote by DHH covered what to expect from Rails 2.0. Front and center was an emphasis on RESTful development, which should come as no surprise to anyone who has followed Rails lately. The big takeaway for ajax developers is that Rails will let you return javascript seamlessly for any request, right along side the same code you use for a standard HTTP requests, or XML requests, or whatever. This ultimately means more cohesive, cleaner code in your controllers, and that adding ajax is as easy as adding a format.js to serve XHR requests:

RUBY:
    class PeopleController <ApplicationController
      ...
      def create
        @person = Person.create(...)
        respond_to do |format|
          format.html { redirect_to person_url(@person) }
          format.xml  { render :status => :created, :location => person_url(@person), ... }
          format.js   {
            render :update do |js|
              ... # RJS code here to update the page with js with your created person
            end
          }
        end
      end
    end

Rails 2.0 also has some great optimizations coming for HTTP performance. If you've ever looked at the size of prototype+scriptaculous (or dojo, or yui, or...), plus your own custom scripts, PLUS the overhead of the HTTP connections for each seperate javascript file, you know that page load time can get horrendous really quick. The upcoming version will allow easy batching of your js and css, and automatic gzipp'ing when in production, using the standard javascript/stylesheet include tags:

RUBY:
    <%= javascript_include_tag :all, :cache => true %>
    <%= stylesheet_link_tag :all, :cache => true %>

One other quick win Rails 2.0 will give you is multiple hosts for assets. Browsers will only have two concurrent connections open for any single host, but an easy way around that is to use multiple subdomains that resolve to the same domain. So if you set:

RUBY:
    config.action_controller.asset_host = 'static%d.example.com'

Your rails app will randomly choose static01, static02, etc...to get more parallel connections for static assets. This assumes you use the built in img, js, and css helpers, of course.

For more full coverage of the keynote in core-Rails areas, see Nick's notes.

The other ajax-centered session for the day was on full web stack testing with Selenium Remote Control, by Alex Chaffee and Brian Takita (PDF here). The ajax testing story is still a mixed bag, with a lot of different tools and approaches and not one clear best path. Selenium RC lets you test at the function level of your JS, all the way to a functional level of forms and events, all in the language your app is written in (hence the "remote control" part). For more details see the Selenium link above or the detailed pdf for all the code.

Posted by Rob Sanheim at 5:03 pm
10 Comments

++++-
4.2 rating from 20 votes

Monday, May 14th, 2007

JS Commander: JavaScript console via proxy

Category: Library, Ruby

Shinya Kasatani has created JS Commander, an HTTP proxy server with a JavaScript console.

You run the Ruby based proxy, configure a browser to use it, and then you get access to a command prompt to play with.

There are also features such as supporting URL forwarding, allowing one browser to direct another.

Obviously, for most tasks you will want to use Firebug and co., but for working in environments such as Opera on the Wii, this is an approach.

JS Commander

Posted by Dion Almaer at 6:44 am
2 Comments

+++--
3.5 rating from 17 votes

Wednesday, March 7th, 2007

Toggl: Ajax based timetracker tool

Category: Rails, Ruby, Showcase

Alari Aho has created Toggl, an Ajax based timetracker tool written in Ruby on Rails that uses several Ajax tehniques, including pre-fetch and
asynchronous postings.

Toggl

Posted by Dion Almaer at 8:15 am
6 Comments

+++--
3.5 rating from 31 votes

Monday, February 19th, 2007

ZK Now Supports Javascript, Groovy, Ruby

Category: Framework, Java, JavaScript, Ruby

As promised, the latest release of ZK (ZK 2.3 RC) now supports more languages in zscript than just Java. It now supports Javascript, Groovy and Ruby. Futhermore, you can easily add support for a new language in half a day (maybe with some practice, no?) by extending a simple interpreter class. That's assuming, of course, that a Java-based interpreter already exists for the language.

For those of you not familiar with ZK, it is a Ajax framework that has you write your application logic on the server-side and treats the browser as a simple display server (as opposed to client-side frameworks that implement lots of application logic in the browser and treat the server more as a collection of web services). You write your application using ZUML, an XML-based markup language, assembling interface components in a way very similar to the desktop GUI component/event driven model. You tie your app logic into the markup language using zscript statements:

CODE:
  1. <window title="Fileupload Demo" border="normal">
  2.     <image id="image"/>
  3.     <button label="Upload">
  4.         <attribute name="onClick">{
  5.             Object media = Fileupload.get();
  6.             if (media instanceof org.zkoss.image.Image)
  7.                 image.setContent(media);
  8.             else if (media != null)
  9.                 Messagebox.show("Not an image: "+media, "Error",
  10.           &nbs