Ruby

This is a simple walkthrough for creating a Rails 3 application that supports token based authentication.

This is written for Rails 3 but should work just fine for Rails 2.x

You can find the source code of the demo app on github:
http://github.com/wnoronha/device-auth-demo

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

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.

Using thinking sphinx to search objects that are tagged using the acts_as_taggable_on plugin.

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">]

Lets run the indexer

 

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"

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

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
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

This is fucking sweet!

Syndicate content
Drupal theme by Kiwi Themes.