Ruby

Testing REST API Calls using Curl

Representational State Transfer (REST) was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. Fielding is one of the principal authors of the Hyper Text Transfer Protocol (HTTP) specification versions 1.0 and 1.1.

Since my current application is just a bunch of REST services, I needed to test these calls before publishing them. Unfortunately there were no good tools I could use to test these calls. I spent some time searching for scripts or apps that can make my life easier till I ran into this jewel somewhere on the web

Jquery and Ruby on Rails

What is Jquery

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. -- From the Jquery Website.

Jquery is one of the many Javascript frameworks out there. Its competition includes YUI, Prototype, Moo etc.

Jquery UI

In additions to the framework; Jquery also has a powerful UI framework. Jquery and Moo have the most complete and easy to use UI framework now. It has widgets such as sliders, tabs, accordions, calendars, dialog and modal windows. It also has a very nice button framework.

You can find more information on their website http://ui.jquery.com.

Acts as taggable on and Thinking Sphinx Integration

This post tells you how to using the thinking sphinx rails plugin to search a bunch of records that have a specific tag (acts_as_taggable_on).

class Photo < ActiveRecord::Base
  ...
 
  acts_as_taggable_on :keywords
 
  define_index do
    indexes :caption
    indexes keywords.name, :as => :keywords
  end
 
  ...
end

Now lets assign some tags to our Photo

>> photo = Photo.create :user_id => 1, :caption => 'BMW M7', :keyword_list => 'BMW, Car'
>> photo.keywords
=> [#<Tag id: 1, name: "BMW">, #<Tag id: 3, name: "Car">]

Simple Consistent Hash for Memcache in Ruby

Consistent hashing is a scheme that provides hash table functionality in a way that the addition or removal of one slot does not significantly change the mapping of keys to slots. In contrast, in most traditional hash tables, a change in the number of array slots causes nearly all keys to be remapped. By using consistent hashing, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots.

servers = ['memcache1', 'memcache2', 'memcache3', 'memcache4']
servers[ 'product-1'.hash % servers.size ]
 
servers[ 'product-1'.hash % servers.size ] => "memcache4"
servers[ 'product-2'.hash % servers.size ] => "memcache1"

Ubuntu Ruby

My powerbook recently crapped out. Time to bring out the good ol' think pad.

Just found this meta package that will install everything for you.

apt-get install ruby-full

GeoCoding using Ruby

A quick hack to get a location's geo coding

 
 require 'xml-simple'
 require 'net/http'
 
 # Enter the location to get the lat and long
 #
 def yahoo_geo(location)
   host = "api.local.yahoo.com"
   q =  "http://api.local.yahoo.com/MapsService/V1/geocode"
   q << "?appid=wnorrix&location=#{URI.encode(location)}"
   xml = XmlSimple.xml_in(Net::HTTP.get(host, q), {"ForceArray" => false})
   return xml["Result"]
 end

Rodney asking me if I want to go for a smoke?

class Smokers <  ActiveRecord:: Base
 belongs_to      :heart_failure_statistics
 has_many        :cigarettes
 attr_accessor   :mins_since_last_puff
 
 before_validation :check_cigarettes
 
 def smoke?
   if mins_since_last_puff  >= 60
     write_warren("Smoke?") 
   end  
 end
end

Ruby on Rails 1.0 has finally arrived!

Finally after a long wait its finally here! There have been soo many changes since the early 0.5 days. I still remember the good ol' days where you had to do so many things manually. Thanks to the rapid development of the framework, most of this is taken care of now. I remember times where I had to spend time on apache to get things right and now every thing seems to work out of the box.

The community has grown from 10 to over 400 users (on IRC we lost a good few though). Hope to see Rails establish it self as the next industrial standard.

Syndicate content