Archive for the ‘Ruby’ Category

Block magic for Rails helpers

Ever wondered how can you have something like this <% some_helper do %> Some text here <% end %> Well, here how it is… def some_helper(&block) content = capture(&block) concat(“this comes before the block”, block.binding) concat(content, block.binding) # adds “Some text here” to the view concat(“this comes after the block”, block.binding) end Neat! Isn’t it

Will be introducing MAIT students to Ruby & Rails…

Now this is going to be fun! Workshop for MAIT students (part 1 of 2)

Super sexy BDD with Cucumber and Webrat

Fatal – you don’t have any automated test cases Recoverable – you have some sorts of test suite in place Best – you are already using unit/integration tests or have TDD/RSpec in place Without wasting words, I’d put you right to the Cucumber and Webrat goodness… Points worth noting… This was ALL the code I [...]

Learning from the best!

Just bought “Programming Ruby 1.9” from Flipkart. From For Blog When I joined IBM ISS UI team and my tech lead suggested that we should start doing things in Rails- and I was prompt enough to pop up a suggestion – “that why don’t we use Python based web app frameworks Django or Turbo Gears [...]

Super easy SUB-URI hosting with mod_rails

With an Amazon EC2 instance up, next very obvious task was to get the hosting up. Objective was to host static content along with multiple Rails apps on the same EC2 instance. Purists might not agree to this, but getting up and running was the first target. Apache is configured with DocumentRoot as /mnt/app/shared My [...]

Revisting Ruby – Array.each

I’ve been in love with Ruby for long now – and its only obvious that I should get serious about it. Hence, I’ve decided to go through Programming Ruby 1.9 – a chapter a day. Understanding Array.each and blocks #!/usr/bin/env ruby   class MyObject   attr_accessor :data     def initialize     @data = [...]

Script free SMS via 160by2.com

Courtesy – yet again, Ruby! #!/usr/bin/env ruby   require "rubygems" require "mechanize"   module SMS     class OneSixtyByTwo     attr_accessor :agent, :uid     attr_accessor :urls       def initialize(username, password)       @urls = {         :login => "http://m.160by2.com",         :sms => "http://m.160by2.com/SaveCompose.asp?l=1"   [...]

Google Suggest + Ruby = Fun!

Google Suggest – (as put by Google) use a wide range of information to predict the queries users are most likely to want to see. For example, Google Suggest uses data about the overall popularity of various searches to help rank the refinements it offers. An example of this type of popularity information can be [...]

How to stip tags, script and style off the HTML

Havn’t you just wished sometimes that all the html, script and style tags would just vanish from the html pages and all you get is pure text (for fun and profit). Well, here’s how I am managing it require “open-uri” require “hpricot” require “sanitize” html = open(“http://www.google.com”) hp = Hpricot(html.read) hp.search(“script”).remove hp.search(“style”).remove sanitize(hp.innerHTML, okTags=”") And [...]

Getting back to the drawing board…

Drawing boards are so much more fun than paper’n pencil