Welcome to the Hobo Blog :-)

Posted over 7 years back at The Hobo Blog

I’m so glad Wordpress didn’t turn that smiley into a cute little gif. Old Skool man!

In My Younger And More Vulnerable Years...

Posted over 7 years back at zerosum dirt(nap) - Home

Thus began the Zerosum dev blog, a place for folks who work on our code to muse about daily development happenings and such.

I’ve never been one to keep a blog, personally, but I think of this area as a useful place for us to post about things that don’t belong in our project trac wiki or elsewhere. Things you want to share with others. Things like: “Wow cool, Ian found a new way to do X that totally rocks. Spread the word” and “Rails migrations rule, check out this snippet!”, and “Saw this thing on Foo’s blog about how to do Y without needing Z. Maybe we should think about refactoring the BlahController to do that too?”

You get the idea.

Josh Schairbaum and Dan Manges - Ruby on Rails Podcast

Posted over 7 years back at Ruby on Rails Podcast

Correspondent Robert Stevenson interviews two developers from investment banking company JPMorgan Chase.

Integration Testing in Ruby on Rails — How to maintain sessions while testing in Rails

Posted over 7 years back at Ajax on Rails


Well, its a natural feel to get amazed out of every other delighted feature provided by RubyonRails and so appreciating it before actually talking about the feature in every second post. This line is for those people who have published that the worst thing about rails is that every rails programmer always just focus on the appreciation of rails and not on the framework per se. As i think the reason behind his(let say) perception is that he might not have tried rails and probably in all posts he have been through yet is that he would have got jealous out of gaining popularity of ruby on rails over jsp and asp and else, and therefore he might not be reading the whole post due to which he just remained untouched with the real appreciable features.
Anyhow, here is my post on a fantastic rails feature – Integration Testing…
RoR is the only web application framework which provides an inbuilt high level of testing. Out of the whole testing the most interesting real time testing is Integrations Testing where you can synchronize with the sessions too unlike in the Functional Testing.

Where exactly we should use Integration Testing ?
Whenever we need to test a series of functionalities which belongs to more than one controller , we should go for Integration Testing and not the Functional one.

Since the functional and unit testing are controller and model centric respectively, rails automatically creates the related functional and unit tests files. But as integrations testing is not confined in any criteria of a specific controller or model, we have to create the integrations file manually… Well, nothing is headache in rails. Its a simple pre-written script, all you need is to call that script with a name you like for whole story you wish to test in the integration test.

Here is a real example of Integration Test in Ruby on Rails

Considerations for test…
We will simply test

  • signing in
  • posting a new article
  • deleting an article with xml_http_request (ajax post request)

Create the test file by running


ruby script/generate integration_test initial_features

Make sure that now you have the file /test/integration/initial_features_test.rb. Rails automatically appends _test at the end of the file name.

For god sake Lets start the testing now :-)
Code for the file /test/integration/initial_features_test.rb


require "#{File.dirname(__FILE__)}/../test_helper"

class InitialFeaturesTest < ActionController::IntegrationTest
  fixtures :users, :articles

  def test_initial_features
     user = user_for_test
     user.try_to_signin
     user.signin
     user.post_an_article
     user.delete_an_article_with_xhr
  end

  def user_for_test
    open_session do |user|
      def user.try_to_signin
        assert_nil session[:user] # assert_session_has & _has_no have been deprecated
        get "user/signin"
        assert_response :success
        post "user/signin", :email=>"test failure string", :password=>"test failure string"
        assert_nil session[:user]
      end
      def user.signin
        assert_nil session[:user]
        user = users(:first)
        post "user/signin", :email=>user.email, :password=>user.password
        assert_not_nil session[:user]
        assert_response :redirect
        assert_redirected_to "articles/show"
        # now as the session is set once, we need not to signin again
      end
      def user.post_an_article
        get "articles/show"
        assert_response :success
        assert_template "articles/show"
        user = session[:user]
        articles_count = user.articles.length
        post_via_redirect "article/new", :title=>"Integration Tetsing in Rails", :description=>"another relishing rails feature"
        assert_template "articles/show"
        assert_equal articles_count.next, user.reload.articles.length
      end
      def user.delete_an_article_with_xhr
        user = session[:user]
        articles_count = user.articles.length
        xml_http_request "articles/delete", :id=>articles(:first).id
        assert_equal articles_count-1,user.reload.articles.length
      end
    end
  end

end

Although these are not that high level integration tests that rails can provide but its just an overview on the integration tests. I will explain them soon.

Exploring TextMate...a Ruby perspective

Posted over 7 years back at Luke Redpath - Home

Marshall Vandegrift has posted an interesting screencast showing off Emacs as a tool for Ruby/Rails development. I enjoyed the screencast, and Emacs certainly has cool features but all I could think whilst watching it was (WARNING: FLAMEBAIT ALERT!)…“urgh, its soooo ugly, how could anybody work with that all day. And TextMate does all of this and in a much nicer way…”.

It got me thinking about how I use TextMate every day and whether I really take full advantage of its built-in commands and snippets for Ruby and Rails development. I wondered how many of the features in the above Emacs screencast were already in TextMate and the answer was…most of them! This inspired write a post about some of my favorite TextMate snippets and hopefully you’ll find out about a few you didn’t know about.

Whether you are a new or seasoned TextMate user, its really worth spending some time to learn some of the more useful snippets in the bundles for the languages that you are using. I’m sure most Ruby and Rails developers are aware of the basics such as do..end completion and the various snippets for creating classes, modules and methods. What follows is an overview of some of the cooler functionality built into the Ruby/Rails bundles that you might not have come across. There is a certain amount of mental overhead in learning these snippets but if you can you will find yourself being even more productive.

But first…

If you are running a stock TextMate install, you’ll only have the default set of bundles. There is a wealth of bundles in the Macromates Subversion repository. I won’t repeat the installation instructions here, but I will mention a small tip for managing your bundles.

The Macromates repository has a lot of bundles and the chances are you will only need a small selection of them. Installing all the bundles slows down TextMate’s opening times and adds a lot of noise to the Bundles/Snippets menus. Instead of simply checking out all of the bundles into your /Library/Application Support/TextMate folder, create a folder in a Subversion repository of your own, and check the empty folder out to /Library/Application Support/TextMate. Now, add all the folders in the Macromates repository except the Bundles folder to your repository as an svn:externals entry. Next, create a Bundles folder and check this in. Finally, add all of the Bundles that you want as svn:externals entries in the Bundles folder.

If the above sounds too complicated or time-consuming, you can use my own setup as a starting point.

Syntax constructs

Note: for the rest of this article, I will put any relevant tab-triggers in square brackets.

The TextMate Ruby bundle has snippets for most of the common declarations that you are likely to use…there are definitions for classes [cla], modules [mod] and methods [def] and other common blocks such as conditional statements [if, ife, elsif], loops [until, while], exception handling [begin] and generic blocks [do].

The class and module snippets, like a lot of newer snippets, use a single tab expansion for multiple snippets, with the different options appearing as a contextual menu. This reduces the overhead of learning lots of obscure triggers and gives you a good overview of what you can do with a particular trigger. The class snippets, for example, have variations for creating standard classes, classes with inheritance, classes with a generated initialize template and more. You can even create a new Test::Unit testcase, complete with the necessary requires, Test::Unit::TestCase inheritance and a default test method with a single trigger [tc].

Finally, there are snippets for many of the common tasks performed when writing a Ruby script, such as entering the shebang line [rb], requiring files [req], generating symbol => value key/value pairs for hashes [:], lambda blocks [lam], and one of my favorites, path-from-here [patfh] which is used for getting the path relative to the current script and generates:

File.join(File.dirname(__FILE__), *%w<strong>[rel path here]</strong>)

h3. Writing classes/modules

In addition to the snippets for defining classes and modules, there are some other goodies too.

If you want to add Enumerable support to your class, you need to include the Enumerable module and define an each method. To do this in Textmate, simply create a new class then inside your class definition, use the Enumerable snippet [Enum]. This will generate something like this for you:

class Foo
  include Enumerable

  def each(&block)

  end
end

In a similar fashion, the Comparable snippet [Comp] will include the Comparable module and create a stub <=> method for you to fill in.

Defining attributes for your class is a breeze – TextMate contains snippets for attr_reader ®, attr_writer [w] and attr_accessor [rw]. You can define class methods just as easily as you define instance methods [defs], alias methods [am] and overwrite method_missing [mm]. Don’t forget the singleton class for helping out with that meta-programming goodness [sin].

Other cool snippets

There are plenty of snippets for all of your favorite iterators including each [ea], each_pair [eap], collect/map [col/map] and everybody’s favorite, inject [inj]. There are too many to mention here – there are snippets for all of the common iterators and block methods defined in Enumerable and other collection classes, as well as snippets for iterating over files.

How often do you fire up IRB just to run a simple snippet of code? I do…but why waste time loading up IRB when you can execute lines of Ruby directly in TextMate? Simply write a line of Ruby code, then run the “Execute line as Ruby” command [Ctrl + Shift + E]. The result of the expression will be inserted directly on the next line.

Finally, some personal favorites. Trying to convert all those string keys to symbols in your Rails app to make things much easier to read? TextMate makes it easy to switch between strings and symbols – simply move the cursor onto the string/symbol you want to switch and hit [Ctrl + :].

Interested to know whats going on under the hood of the library that you’ve required in your script? Put the cursor over the require line, and hit [Cmd + Shift + D]. If TextMate can find the required file, it will open it for you. How cool is that?

A final, Rails-related mention goes to the Rails migration snippets. There are only three commands you need to know: columns, tables and indexes [mcol, mtab, mind]. All of the common migration commands are supported and where possible, the snippets will generate your self.down method for you, whilst you are writing the self.up method! A particularly good example of this is “Drop and Create table” – type in the name of the table you want to drop, hit tab twice and it will populate self.down using the relevant section of your schema.rb. Clever stuff.

Writing your own bundles

Of course, the real power behind TextMate lies not only in its pretty good set of existing bundles, but the ability to write your own. Writing snippets is the easiest of the lot and I really advise you to create your own “personal” bundle to store all of the little snippets tailor-made for you. The next step up is writing commands and here is the killer feature – you can write your commands in whatever language you know best, as long as TextMate can find the interpreter (it uses a shebang line at the top of your command). A lot of the built-in commands are written in Bash, but many of the Ruby commands are written in, unsurprisingly, Ruby. Take a look at some of the built-in commands to give you an idea of what you can do.

Here are some of the bundles that I’ve written that are available for all:

* RSpec TextMate Bundle * RESTful Rails – snippets for RESTful Rails development * UJS4Rails Bundle – snippets for the UJS Rails plugin

The last two are still very much under development but the RSpec bundle is pretty comprehensive and covers all of the built-in expectations, as well as the mocking API, Rails integration and spec runners.

Feedback

Have you got any favorite snippets that you want to share with the world? Let me know. You can use the comments below, although I advise for anything but short snippets that you pastie them and post the link.

Vox Populi

Posted over 7 years back at Ryan Tomayko's Writings

The following is the full text of a paper by Sir Francis Galton first published in the March 7, 1907 issue of the scientific journal, NATURE. The piece is referenced in the February 18, 2005 episode of WNYC's most excellent RadioLab program. A scan of the paper on its original facsimile is available as PDF. It seemed a shame that what is possibly the first solid explanation for why Google's ranking algorithm is so capable should be hidden from it.

In these democratic days, any investigation into the trustworthiness and peculiarities of popular judgments is of interest. The material about to be discussed refers to a small matter, but is much to the point.

A weight-judging competition was carried on at the annual show of the West of England Fat Stock and Poultry Exhibition recently held at Plymouth (England). A fat ox having been selected, competitors bought stamped and numbered cards, for 6d. each, on which to inscribe their respective names, addresses, and estimates of what the ox would weigh after it had been slaughtered and “dressed.” Those who guessed most successfully received prizes. About 800 tickets were issued, which were kindly lent me for examination after they had fulfilled their immediate purpose. These afforded excellent material. The judgements were [unbiassed] by passion and uninfluenced by oratory and the like. The sixpenny fee deterred practical joking, and the hope of a prize and the joy of competition prompted each competitor to do his best. The competitors included butchers and farmers, some of whom were highly expert in judging the weight of cattle; others were probably guided by such information as they might pick up, and by their own fancies. The average competitor was probably as well fitted for making a just estimate of the dressed weight of the ox, as an average voter is of judging the merits of most political issues on which he votes, and the variety among the voters to judge justly was probably much the same in either case.

After weeding thirteen cards out of the collection, as being defective or illegible, there remained 787 for discussion. I arrayed them in order of magnitudes of the estimates, and converted the cwt., quarters, and lbs. in which they were made, into lbs., under which form they will be treated.

Distribution of the estimates of the dressed weight of a particular living ox, made by 787 different persons.

Degrees of the length of Array 0°-100° Estimates in lbs. Centiles Excess of Observed over Normal
Observed Deviates from 1207 lbs. Normal p.e. = 37
5 1074 -133 -90 +43
10 1109 -98 -70 +28
15 1126 -81 -57 +24
20 1148 -59 -46 +13
q1 25 1162 -45 -37 +8
30 1174 -33 -29 +4
35 1181 -26 -21 +5
40 1188 -19 -14 +5
45 1197 -10 -7 +3
m 50 1207 0 0 0
55 1214 +7 +7 0
60 1219 +12 +14 -2
65 1225 +18 +21 -3
70 1230 +23 +29 -6
q3 75 1236 +29 +37 -8
80 1243 +36 +46 -10
85 1254 +47 +57 -10
90 1267 +52 +70 -18
95 1293 +86 +90 -4

q1, q3, the first and third quartiles, stand at 25° and 75° respectively. m, the median or middlemost value, stands at 50°. The dressed weight proved to be 1198 lbs.

According to the democratic principle of “one vote one value,” the middlemost estimate expresses the vox populi, every other estimate being condemned as too low or high by a majority of the voters (for fuller explanation see One Vote, One Value, NATURE, February 28, p. 414). Now the middlemost estimate is 1207 lb., and the weight of the dressed ox proved to be 1198 lb.; so the vox populi was in this case 9 lb., or 0.8 per cent. of the whole weight too high. The distribution of the estimates about their middlemost value was of the usual type, so far that they clustered closely in its neighbourhood and became rapidly more sparse as the distance from it increased.

But they were not scattered symmetrically. One quarter of them deviated more than 45 lb. above the middlemost (3.7 per cent.), and another quarter deviated more than 29 lb. below it (2.4 per cent.), therefore the range of the two middle quarters, that is, of the middlemost half, lay within those limits. It would be an equal chance that the estimate written on any card picked at random out of the collection lay within or without those limits. In other words, the “probably error” of a single observation may be reckoned as 1/2(45 + 29), or 37 lb. (3.1 per cent.). Taking this for the p.e. of the normal curve that is best adapted for comparison with the observed values, the results are obtained which appear in above table, and graphically in the diagram1.

The abnormality of the distribution of the estimates now becomes manifest, and is of this kind. The competitors may be imagined to have erred normally in the first instance, and then to have magnified all errors that were positive. The lower half of the “observed” curve agrees for a large part of its range with a normal curve having the p.e. = 45, and the upper half with one having its p.e. = 29. I have not sufficient knowledge of the mental methods followed by those who judge weights to offer a useful opinion as to the cause of this curious anomaly. It is partly a psychological question, in answering which the various psychophysical investigations of Fechner and other would have to be taken into account. Also the anomaly may be partly due to the use of a small variety of different methods, or formulae, so that the estimates are not homogeneous in that respect.

It appears then, in this particular instance, that the vox populi is correct to within 1 per cent. of the real value, and that the individual estimates are abnormally distributed in such a way that it is an equal chance whether one of them, selected at random, falls within or without the limits of -3.7 per cent. and +2.4 per cent. of their middlemost value.

This result is, I think, more creditable to the trustworthiness of a democratic judgement than might have been expected.

The authorities of the more important cattle shows might do service to statistics if they made a practice of preserving the sets of cards of this description, that they may obtain on future occasions, and loaned them under proper restrictions, as these have been, for statistical discussion. The fact of the cards being numbered makes it possible to ascertain whether any given set is complete.

Francis Galton.


Notes

1 The original article included a diagram that illustrated the normal vs. observed curve. I plan on adding this at some point but have not yet had the time to try to emulate the hand-written diagram with modern plotting tools.

RubyConf2006 - Ruby on Rails Podcast

Posted over 7 years back at Ruby on Rails Podcast

A chat with Greg Edwards of EyeTools (blog), a user interface research lab.
Elsewhere: Matz Keynote, Adam Keys USSRuby Sketch (alt), and the Erlang promo video.

RoR(Ruby on Rails) in India – Ruby on Rails based Indian Company

Posted over 7 years back at Ajax on Rails


Ruby on Rails is creating the storms in the web development all over the world. RoR is even capable to challenge Big Caps like Microsoft’s Asp.NET and so everything else in the specific area. World is continuously changing… The current WEB not solely depends on the old,encoded,paid,stressful technologies but the fresh,open-source,free,joyful technologies like Ruby on Rails are now creating the new highways to connect the WEB… What else ?.. Providing a beautiful atmosphere to web-developers. At the moment the whole world of web-development is cherishing the fresh breeze of RoR.
How much of INDIA is delighted by Ruby on Rails ?
Currently, the INDIAN side of Rails is a small community…but growing at a rapid rate. I am proudly working at VINSOL(New Delhi,India), a company full fledged working on rails.
VINSOL is currently holding some good clients for web-development and providing efficient services in Ruby on Rails.

Captcha in Ruby on Rails – Customize the use of captcha in the plugin validates_captcha

Posted over 7 years back at Ajax on Rails


Hello Everyone !!
I have released a captcha plugin Simple Captcha. It is really simple to implement, and provides a cool feature of multiple styles of images.


Previous Post for validates_captcha


To implement captcha in RubyonRails, validates_captcha plugin can be a good option but a small customization i need with this plugin was to use it on some specific action and not to be validated the captcha field every time an instance of the model is saved or updated.
Here is a small work-around for its customization…
How to use customized captcha in RoR ?
Install the plugin validates_captcha in your rails application by running this command from the root of your application

ruby script/plugin install http://svn.2750flesk.com/validates_captcha

Make sure that you can now see the directory vedor/plugins/validates_captcha.

Now run these commands from your application root to make the image and data directories

  ruby script/generate captcha store_directory
  ruby script/generate captcha image_directory

Here is the complete API for the usage of this plugin. I am describing the same idea as given in this API but in a bit more specific means.

Lets consider a model User in which we will implement the captcha.
Add the following code in the file app/models/user.rb

  class User < ActiveRecord::Base

    validates_captcha :if => :request_captcha_validation?
    attr_accessor :request_captcha_validation

    def request_captcha_validation?
      (self.request_captcha_validation==true)? true : false
    end

  end

Handle View and Controller

Add the code in the view inside your existing form.

  <% c = prepare_captcha :type => :image -%>
  <%= captcha_hidden_field c, 'user' %>
  <%= captcha_image_tag c %>
  <%= captcha_label 'user', 'Type in the text from the image above' %>
  <%= captcha_text_field 'user' %>

Your controller will look like

  def save
    # the line in bold represents that you need captcha validation.
    # if captcha validation is not required then remove this line from your controller.
    @user = User.new(params[:user])
    @user.request_captcha_validation = true
    @user.save
  end

However image is too noisy and it contains repeated strings.
To improve the quality of images generated by the plugin validates_captcha visit Here.

Using RMagick with Flickr

Posted over 7 years back at schadenfreude

In my previous article, Render Great-looking Collages with Ruby and RMagick, I showed how you can use RMagick to generate a lovely collage from a selection of random images. This tutorial will take it one step further and show you how to use RMagick with RFlickr to generate a collage from your own Flickr account or even a results from a flickr search.

4 random images found with the search term “Mazda MX-3” (my car)

Using RMagick with Flickr

Posted over 7 years back at schadenfreude

In my previous article, Render Great-looking Collages with Ruby and RMagick, I showed how you can use RMagick to generate a lovely collage from a selection of random images. This tutorial will take it one step further and show you how to use RMagick with RFlickr to generate a collage from your own Flickr account or even a results from a flickr search.

4 random images found with the search term “Mazda MX-3” (my car)

Using RMagick with Flickr

Posted over 7 years back at schadenfreude

In my previous article, Render Great-looking Collages with Ruby and RMagick, I showed how you can use RMagick to generate a lovely collage from a selection of random images. This tutorial will take it one step further and show you how to use RMagick with RFlickr to generate a collage from your own Flickr account or even a results from a flickr search.

4 random images found with the search term “Mazda MX-3” (my car)

MicroSoft’s IE-7 Released – another headache for web developers.

Posted over 7 years back at Ajax on Rails


Current World’s software giant Microsoft finally released the new milestone IE-7.
Once again web programmers have to reload their guns to cross a new barrirer of all new standards of MicroSoft another thing IE-7.
Its a feel of proud for Microsoft to not to follow the web-standards of W3C and to give themselves a fresh new region of narrow mentality people and a feel of headache for web developers to again customizing their previous running web-sites which already been specially customized to go ok with a mess IE-6 and here is a repeated story again coz the most amazing thing is that IE-7 is even not following the styles of IE-6

Go FireFox !! Go Flock !!

BillMonk - Ruby on Rails Podcast

Posted over 7 years back at Ruby on Rails Podcast

The founders of BillMonk talk about building a community site with Rails, email as an API, and dynamically generated graphics.

Blogging for Britain

Posted over 7 years back at Luke Redpath - Home

An interesting article dropped into my newsreader this morning. The National Trust are organising what they hope to be “Britain’s biggest blog” by encouraging people to blog about a normal day living in Britain. The blog entries will then be archived and stored in the British Library amongst other places.

As a relatively new blogger (this blog is my fourth attempt at getting a blog going and has been up and running since May this year), I’ve tried to avoid blogging about the mundane day-to-day aspects of life but I have to admit that this sounds like an intriguing idea that I’d really like to have a go at.

If you live in the UK and you’d like to take part yourself, entries can be uploaded between 17 – 31 October on the History Matters website. It doesn’t have to be more than 650 words long. I’ll be picking a day in the coming fortnight to give it a go (hopefully an interesting day!) and I’ll post my entry up on here too.

Go on, blog for Britain!