Articles

Encapsulation in JavaScript

JavaScript does not allow you to define a method as public or private. This is a limitation users need to get around to, because in real life you don’t want to expose all methods as public method.

Here is a simple implementation of the case where you want to verify input code.

How to run Selenium RC with Ruby codes

1. Download seleniumRC from –> http://bit.ly/j_sel_rc

2. Unzip the file

3. commans prompt>java -version  –> Version should grater than 1.6.0_5

4. command prompt go to –> C:\selenium-remote-control-1.0.1\selenium-server-1.0.1>java -jar  selenium-server.jar

Now Selenium runs on 4444 port.

5. cmd prompt>gem install selenium-client

6. Open new command prompt and goto ruby program path.In Ex, c:\test>ruby code.rb

7.  code.rb

require “selenium”
require “test/unit”

Double Shot #559

I’m putting in way too many late nights these days.

My Tools of the Trade – 2009

I originally posted this list in mid-2008, and it seems about time for an update. So, here are the tools I tap most often these days in building web sites and doing my other work:

Hardware

For the most part, I haven’t upgraded hardware in the past year. The desktop box is starting to feel its age, and I’d like to treat myself to an upgrade, but I can’t quite justify the cost yet.

Open File Fast updated for JEdit 4.3pre17

This is update for all you JEdit users who updated your beloved JEdit to 4.3pre17, did plugins update and found that OFF is not working anymore.

Newest JEdit offers update of ProjectViewer plugin to version 2.9.1 which is quite not compatible with 2.7.x line. There were some changes in the PV API which broke OFF. I’ve updated OFF to work with new ProjectViewer and now you can use it again. This is only compatibility relase, no new features.

Bloopsaphone on Shoes!

What I’ve Earned and Learned From Writing A Popular(ish) Ruby Book

begruby-edition-2-cover.gif A few days ago I received the latest in a long line of royalty statements for my book, Beginning Ruby (as published by Apress). Long time readers might recall that Ruby Inside was started principally to promote the book, but turned into so much more that the book took a back seat.

Attempted peace

I’ve been toying around with the idea for a small website lately, but never actually got around to do it. In an attempt to clear out my personal to do list I finally motivated myself to start yesterday, and I have to say the following combination of tools is not only insanely efficient, but also really fun to work with:

Switching to Gemcutter

So GitHub dropped gem support. No problem – Gemcutter, the drop-in replacement, is simple to use. (And now my gems get canonical names!) I’ve pushed my Rails gems (ActiveUrl, Subdomain Routes and Paged Scopes) to the new host, and updated the README installation instructions.

Ruby Metaprogramming New Batch Announced

Simple Mustache JSON Serialization | Rails Fire

Simple Mustache JSON Serialization

If you’ve taken a look at Mustache, the “stupid in a good way” templating engine, you might know that there are also Javascript Mustache renderers such as Mustache.js. Today we’ve released a small library called mustache_json that allows you to compile your Mustache view objects into JSON, allowing them to be interpreted by Javascript Mustache rendering engines.

What this means for your project is that you will finally have a identical client-side and server-side rendering interface, opening wide the opportunities for pushing more of the rendering work onto the client-side, a boon for many real-time and heavy-interaction applications.

To install mustache_json, just get the gem from Gemcutter:

gem install mustache_json

To use it, simply require 'mustache_json' and all of your Mustache objects will automatically be given a #to_json method. For instance:

require 'mustache_json'

class Person < Mustache
  def initialize(first_name, last_name)
    context[:first_name], context[:last_name] = first_name, last_name
  end

  def initials
    "#{context[:first_name][0..0]}.#{context[:last_name][0..0]}." 
  end

  def listing
    "#{context[:last_name]}, #{context[:first_name]}" 
  end
end

bob = Person.new('Bob', 'Bobson')
bob.to_json

This will render into a JSON object that looks like this:

{"last_name":"Bobson","initials":"B.B.","listing":"Bobson, Bob","first_name":"Bob"}

Mustache JSON gives you access to all of the public instance methods you declare in your Mustache as well as any context you have set. It is essentially a fully compiled version of the Mustache view, providing everything another renderer needs to create the actual markup. The JSON back-end for this library is swappable, meaning you can use the JSON gem, JSON pure, ActiveSupport, or Yajl by default (and any other class with an encode method if you’ve got a different library).

Documentation is available on RDoc.info and the source is available on GitHub. Stay tuned for posts in the future about utilizing this library to actually perform identical rendering in Ruby and Javascript.