Thursday, January 25, 2007

Mongrel 1.0.1

To coincide with Rails 1.2.1, Zed just made Mongrel 1.0.1 official. He also points out that he started working on Mongrel around January, making it around 1 year old too.
i installed the new mongrel. it works well in local

Thursday, January 18, 2007

Unicode in Rails application

To avoid Unicode related problems, add the following line to the environment.rb file

$KCODE = 'u'

and add the following line to the database.yml file while
establishing a database connection

encoding: utf8

In Rails 1.2 , Unicode hack is a built in feature




Friday, January 12, 2007

Install These Plugins

The Following search engine plugins will be useful for a ROR developer

Install These plugins in your firefox browser...

Plugin Icon Koders (Ruby) en-WW (koders.com) by Diogenes de Araujo
Plugin Icon Ruby Application Archive Semi en-WW (raa.ruby-lang.org) by Shusaku Yokota
Plugin Icon Ruby Manual Semi en-WW (rubymanual.org) by Gregoire Lejeune
Plugin Icon Ruby on Rails Semi en-WW (rubyonrails.org) by Kenn A. Thisted
Plugin Icon Ruby on Rails Manual Semi en-WW (railsmanual.org) by Gregoire Lejeune
Plugin Icon RubyCorner Semi en-WW (rubycorner.com) by Edgar González
Plugin Icon RubyForge Semi en-WW (rubyforge.net) by Raghuraman Suraj
Plugin Icon RubyOnRails API Semi en-WW (api.rubyonrails.com) by Robert Gaal

To download these plugins, click http://mycroft.mozdev.org/download.html?name=ruby

Wednesday, January 10, 2007

Ruby Enters Top 10 Programming Languages at TIOBE


Ruby Enters Top 10 programming Languages at TIOBE

It seems that one day ruby will defeat Python, Perl, PHP and other stuffs... coz you can observe that ruby has climbed steadily throughout the year 2006. and it also got the TIOBE's award of "Programming Language Of 2006".

TIOBE says:

We are glad to announce that Ruby has become "Programming Language of the Year 2006". Ruby has the highest popularity increase in a year of all programming languages (+2.15%). Runner up this year is JavaScript with +1.31%. Both languages are boosted by their corresponding frameworks, Ruby On Rails and Ajax. This might be a new trend. In the recent past it was necessary to have a large company behind the language to get it in the spotlight (Sun with Java, Microsoft with C#), but nowadays a killer app appears to be sufficient. Viral marketing via the Internet works!

Tuesday, January 09, 2007

Interesting Array Methods - Ruby on Rails

1. to_sentence (Array)

Use to join elements of an array into a more English-friendly representation.

>> %w[Chris Mark Steven].to_sentence
=> "Chris, Mark, and Steven"

You can pass it two options: :connector and skip_last_comma. They work like a’this:

>> %w[Soap Mocha Chocolate].to_sentence(:connector => '&')
=> "Soap, Mocha, & Chocolate"
>> %w[Ratatat Interpol Beirut].to_sentence(:skip_last_comma => true)
=> "Ratatat, Interpol and Beirut"

2. to_param (Array)

This guy, in case you’re unawares, is the method Rails calls on any object when trying to figure out how the object should be represented in a URL.

For instance, on an ActiveRecord::Base object:

>> user = User.find(:first)
=> #
>> helper.url_for :controller => 'users', :action => 'show', :id => user
=> "/users/1"

Now let’s say we override the to_param instance method on User to return name:

>> user = User.find(:first)
=> #
>> helper.url_for :controller => 'users', :action => 'show', :id => user
=> "/users/chris"

Cool. That said, the Array version of to_param joins elements with a /.

>> helper.url_for :controller => 'users', :action => 'show', :id => %w[one two three]
=> "/users/one%2Ftwo%2Fthree"

(That’s escaped, of course.) This is so you can easily send and deal with catch-all routes. This thread on RailsForum goes into catch-all routes. You may or may not find them useful.

3. to_s (Array)

Sure, you know Array has a to_s, but did you know Rails overrides it to accept a format (:db) parameter? That’s right! Check it out:

>> array_of_posts = Post.find(:all, :limit => 3)
=> [#, #, #]
>> array_of_posts.to_s(:db)
=> "1,2,3"
>> [].to_s
=> ""
>> [].to_s(:db)
=> "null"

This really only works with ActiveRecord objects, as Rails tries to call #id on the elements of the array. Unlike Time, this to_s currently doesn’t provide a hook for you to add more formats. One day? One day.

4. to_xml (Array)

Another more-or-less ActiveRecord specific extension, you may call to_xml on an array when all the elements of the array respond to to_xml. Like, you know, an array of ActiveRecord objects.

>> puts array_of_posts.to_xml
=> "


... tons of xml ...


Pass in :skip_instruct to omit the line. You can also provide an :indent option (default: 2), a :builder option (you probably want to stick with the default of Builder::XmlMarkup), a :root option (defaults to the lowercase plural name of the class, posts in this case), and a children option (singular lowercase class—post for me).

5. in_groups_of (Array)

The docs have this one covered pretty well: “Iterate over an array in groups of a certain size, padding any remaining slots with specified value (nil by default) unless it is false.

And, three examples. This is almost cheating. But here:

>> %w[1 2 3 4 5 6 7].in_groups_of(3) { |g| p g }
["1", "2", "3"]
["4", "5", "6"]
["7", nil, nil]

>> %w[1 2 3].in_groups_of(2, ' ') { |g| p g }
["1", "2"]
["3", " "]

>> %w[1 2 3].in_groups_of(2, false) { |g| p g }
["1", "2"]
["3"]

>> %w[1 2 3 4 5 6 7].in_groups_of(3)
=> [["1", "2", "3"], ["4", "5", "6"], ["7", nil, nil]]

6. split (Array)

Cuts up an array into smaller arrays in the same way String.split cuts up a string into arrays. Can take a parameter (a value to cut on) or a block (where the result is what’s used for the cuttin’).

>> %w[Tom Jerry and Mickey and Pluto].split('and')
=> [["Tom", "Jerry"], ["Mickey"], ["Pluto"]]
>> %w[Chris Mark Adam Tommy Martin Oliver].split { |name| name.first == 'M' }
=> [["Chris"], ["Adam", "Tommy"], ["Oliver"]]

Stringy Shortcuts [ String Methods ] - Ruby on Rails

Seven Satisfying Stringy Shortcuts

1: at (String)

>> "Finally, something useful!".at(6)
=> "y"

2: from and to (String)

>> "Chris the Person".from(6)
=> "the Person"
>> "Chris the Person".to(4)
=> "Chris"

3: first and last (String)

>> "Christmas Time".first
=> "C"
>> "Christmas Time".first(5)
=> "Chris"
>> "Christmas Time".last
=> "e"
>> "Christmas Time".last(4)
=> "Time"

4: each_char (String)

>> "Snow".each_char { |i| print i.upcase }
SNOW

5: starts_with? and ends_with? (String)

>> "Peanut Butter".starts_with? 'Peanut'
=> true
>> "Peanut Butter".ends_with? 'Nutter'
=> false

6: to_time and to_date (String)

>> "1985-03-13".to_time
=> Wed Mar 13 00:00:00 UTC 1985
>> "1985-03-13".to_date
=> #

7: transformations! (String)

Use these Methods

pluralize, singularize, camelize, titleize, underscore, dasherize, demodulize, tableize, classify, humanize, foreign_key, and constantize

>> "reindeer".pluralize
=> "reindeers"
>> "elves".singularize
=> "elf"
>> "christmas_carol".camelize
=> "ChristmasCarol"
>> "christmas_carol".camelize(:lower)
=> "christmasCarol"
>> "holiday_cheer".titleize
=> "Holiday Cheer"
>> "AdventCalendar-2006".underscore
=> "advent_calendar_2006"
>> "santa_Claus".dasherize
=> "santa-Claus"
>> "Holiday::December::Christmas".demodulize
=> "Christmas"
>> "SnowStorm".tableize
=> "snow_storms"
>> "snow_storms".classify
=> "SnowStorm"
>> "present_id".humanize
=> "Present"
>> "Present".foreign_key
=> "present_id"
>> "Cheer".constantize
NameError: uninitialized constant Cheer
>> "Christmas".constantize
=> Christmas

Monday, January 08, 2007

Mod_Dosevasive in Apache

What Is Mod_Dosevasive?

Mod_Dosevasive is an evasive maneuvers module for Apache whose purpose is to react to HTTP DoS and/or Brute Force attacks.
An additional capability of the module is that it is also able to execute system commands when DoS attacks are identified. This provides an interface to send attacking IP addresses to other security applications such as local host-based firewalls to block the offending IP address. Mod_Dosevasive performs well in both single-server attacks, as well as distributed attacks; however, as with any DoS attack, the real concern is network bandwidth and processor/ RAM usage.

How Does Mod_Dosevasive Work?

Mod_Dosevasive identifies attacks by creating and using an internal dynamic hash table of IP Addresses to URIs pairs based on the requests received. When a new request comes into Apache, Mod_Dosevasive will perform the following tasks:
  • The IP address of the client is checked in the temporary blacklist of the hash table. If the IP address is listed, then the client is denied access with a 403 Forbidden.

  • If the client is not currently on the blacklist, then the IP address of the client and the Universal Resource Identifier (URI) being requested are hashed into a key. Mod_Dosevasive will then check the listener's hash table to verify if any of the same hashes exist. If it does, it will then evaluate the total number of matched hashes and the timeframe that they were requested in versus the thresholds specified in the httpd.conf file by the Mod_Dosevasive directives.

  • If the request does not get denied by the preceding check, then just the IP address of the client is hashed into a key. The module will then check the hash table in the same fashion as above. The only difference with this check is that it doesn't factor in what URI the client is checking. It checks to see if the client request number has gone above the threshold set for the entire site per the time interval specified.

Configuration

you should add the following directives to your httpd.conf file

LoadModule dosevasive20_module modules/mod_dosevasive20.so

-IfModule mod_dosevasive20.c
- DOSHashTableSize 3097
- DOSPageCount 2
- DOSSiteCount 50
- DOSPageInterval 1
- DOSSiteInterval 1
- DOSBlockingPeriod 10
-/IfModule

Saturday, January 06, 2007

Routing - Really Easy in Rails

wanna do complex routing in a simple way....

you can make whatever you imagine for routing... its possible in rails.
Using the rails routing feature, we can do that.

the following eg code only routes when a code no is included in the URL

map.address 'address/:code', :controller => 'address',:action => 'show',:code => /d{5}(-d{4})?/

wanna more tips???????? click the following link
demystify the routing system in Ruby on Rails

Thursday, January 04, 2007

Avoid Exception for Model.find(id)



When doing a Model.find(id), an exception can be returned if the item with an id of 'id' doesn't exist. If you want to avoid this, use Model.exists?(id) first to get a true or false for whether that item exists or not.

Tuesday, January 02, 2007

Creating EXE using ruby



http://www.erikveen.dds.nl/distributingrubyapplications/rails.html

Stop Google Web Accelerator in your Rails apps

Use the following code to stop Google Web Accelerator in your Rails apps


class ApplicationController < ActionController::Base
before_filter :disable_link_prefetching

private
def disable_link_prefetching
if request.env["HTTP_X_MOZ"] == "prefetch"
logger.debug "prefetch detected: sending 403 Forbidden"
render_nothing "403 Forbidden"
return false
end
end
end