Planning to change the world? read this :-
http://blog.sethgodin.silkware.com/Listening-to-the-new.4272.entry
Planning to change the world? read this :-
http://blog.sethgodin.silkware.com/Listening-to-the-new.4272.entry
Posted at 07:42 AM in marketing | Permalink | Comments (0) | TrackBack (0)
Ladies and Gentleman,
cronolog unix logging utility. Sailent features of the thingy are: * With Log4u *
real 0m24.053s
user 0m21.881s
sys 0m1.176s
* With Logger *
real 0m25.191s
user 0m23.033s
sys 0m1.212s
svn checkout svn://rubyforge.org/var/svn/patang/branches/log4u
Posted at 06:48 PM in logger, ruby | Permalink | Comments (1) | TrackBack (0)
Well much has been said about class variables in Ruby and how good and bad they are. When a C++/Java Programmer comes to Ruby, his search of static class variables begin immediately and unfortunately current Text on Ruby seems to suggest that, class variables are apt equivalents of static variables.
Answer is yes and no. When you use class variables, remember they are the same for all instance of the classes, even derived classes will reflect upon the same value and if you modify the class variables in one of those derived classes, it would be changed for all the other classes, which inherit the same parent. Got the picture?
@@avar = 1
class A
@@avar = "hello"
end
puts @@avar # => helloThere is nothing special about code, if you look closely, because if you don’t define a class and declare class variables outside class definition, by default it gets hooked into Object class and since all the classes one way or the other end up inheriting from Object class, if you change the class variable declared at Object class scope in any of the classes, it would be reflected back in class variable held by Object class(bullshit, its the same variable)
Often, thats not.. what you want. Enter class instance variables, which are nice and dandy variables.. which are again avaialble to all the instances of the class and if you change the variable in one instance of the class, it would be reflected everywhere. But unlike class variables, they are not inherited.
class A
@foo = "bar"
class << self; attr_accessor: foo; end
end
class B < A
end
p A.foo #=> bar
p B.foo #=> nil
B.foo = "blah"
p B.foo #=> blahThe overhead is, if you have to access them from instance methods of classes, then you will have to use self.class.foo
Posted at 02:40 AM in ruby | Permalink | Comments (0) | TrackBack (0)
For me, In any long running server app, there are only two rules of multithreaded programming:
Posted at 01:31 AM in Programming | Permalink | Comments (0) | TrackBack (0)
Books I have been reading recently:
The book is quite nice and explains practises of software programmers. How Projects succeed or fail and stuff.
I am reading it, so comments would follow.
A hilarious dilbert book about individhuals.
Call me that I was hiding under a rock, but I never really read the book and I done it recently.
Posted at 08:46 AM in fun | Permalink | Comments (0) | TrackBack (0)
Some rails stuff from ActiveSupport
>> a = "Hemant Kumar"
=> "Hemant Kumar"
>> a.at(4)
=> "n"
>> a.from(4)
=> "nt Kumar"
>> a.first(4)
=> "Hema"
>> a.last(4)
=> "umar"
>> a = "2007/01/01 9:11:25PM"
=> "2007/01/01 9:11:25PM"
>> a.to_time
=> Mon Jan 01 21:11:25 UTC 2007
>> a.to_date
=> #<Date: 4908203/2,0,2299161>
>> a = "camels"
=> "camels"
>> a.pluralize
=> "camels"
>> a = "user_comments"
=> "user_comments"
>> a.camelize
=> "UserComments"
>> "UserComments".underscore
=> "user_comments"
>> "user_comments".dasherize
=> "user-comments"
>> "UserComments".demodulize
=> "UserComments"
>> "UserComments".tableize
=> "user_comments"
>> "UserComments".classify
=> "UserComment"
>> "UserComments".humanize
=> "Usercomments"
>> "UserComments".foreign_key
=> "user_comments_id"
>> "User".constantize
=> User
>> "user_comments".each_char {|char| print char}
=> nil
>> "640 <lol>".starts_with? 640
=> true
>> "640 <lol>".ends_with? "lol>"
=> true
>> "अ".is_utf8?
=> true
>> class Foobar
>> cattr_reader :name
>> def foo
>> p "#{@name}"
>> end
>> end
=> nil
>> foo = Foobar
=> Foobar
>> foo.name = "Hemant"
"NoMethodError: undefined method `name=' for Foobar:Class
from (irb):45"
>> foo.name
=> nil
>> class << foo
>> cattr_accessor :age
>> end
=> [:age]
>> foo.age = 10
=> 10
>> foo.age
=> 10
>> foo.class_variables
=> ["@@name"]
>> foo.instance_variables
=> ["@inheritable_attributes"]
>> class Blah
>> class_inheritable_writer :age
>> end
=> [:age]
>> class Bleh < Blah
>> end
TypeError: superclass mismatch for class Bleh
from (irb):80
>> class Beam
>> end
=> nil
>> class Blem
>> end
=> nil
>> " ".blank?
=> true
>> " ".blank?
=> true
>> a = nil
=> nil
>> a.blank?
=> true
>> a = []
=> []
>> a.blank?
=> true
>> a = {}
=> {}
>> a.blank?
=> true
>> a = User.find(:all,:select => "id,login")
=> [#<User:0xb6f84128 ]
>> a.class
=> Array
>> a.index_by(&:id)
=> {71=>#<User:0xb6f84024>}
>> a.index_by(&:id).hash
=> -612671648
>> c = a.index_by(&:id)
=> {71=>#<User:0xb6f84024 @attributes={"id"=>"71"}}
>> c.class
=> Hash
>> a = [1,2,3,4]
=> [1, 2, 3, 4]
>> a.sum
=> 10
>> a = {:name => "Hemant Kumar",:age => 10}
=> {:name=>"Hemant Kumar", :age=>10}
>> a.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <name>Hemant Kumar</name>\n <age type=\"integer\">10</age>\n</hash>\n"
>> b = "<person><name>Hemant</name><age>10</age></persone>"
=> "<person><name>Hemant</name><age>10</age></persone>"
>> b = "<person><name>Hemant</name><age>10</age></person>"
=> "<person><name>Hemant</name><age>10</age></person>"
>> Hash.from_xml b
=> {"person"=>{"name"=>"Hemant", "age"=>"10"}}
>> c = Hash.from_xml b
=> {"person"=>{"name"=>"Hemant", "age"=>"10"}}
>> a
=> {:name=>"Hemant Kumar", :age=>10}
>> a.diff c
=> {:name=>"Hemant Kumar", :age=>10, "person"=>{"name"=>"Hemant", "age"=>"10"}}
>> a.stringify_keys
=> {"name"=>"Hemant Kumar", "age"=>10}
>> d = a.diff c
=> {:name=>"Hemant Kumar", :age=>10, "person"=>{"name"=>"Hemant", "age"=>"10"}}
>> d.symbolize_keys
=> {:name=>"Hemant Kumar", :person=>{"name"=>"Hemant", "age"=>"10"}, :age=>10}
>> a.reverse_merge c
=> {:name=>"Hemant Kumar", :age=>10, "person"=>{"name"=>"Hemant", "age"=>"10"}}
>> a = 23
=> 23
>> a.even?
=> false
>> a.odd?
=> true
>> a.multiple_of 23
"NoMethodError: undefined method `multiple_of' for 23:Fixnum
from (irb):123"
>> a.multiple_of? 23
=> true
>> 1.ordinalize
=> "1st"
>> module Fleh
>> mattr_writer :age
>> end
=> [:age]
>> Fleh.age = 10
=> 10
>>Posted at 06:59 AM in rails | Permalink | Comments (0) | TrackBack (0)
Whenever I stay at home during afternoon, I would be afraid someone may come with a bill and I won’t have cash to pay him.
I hate ding dong in afternoon.
Posted at 03:16 AM | Permalink | Comments (0) | TrackBack (0)
Hmm, well with new year all the rails programmers have been chattering away about rails 1.2 and how it will do laundry for them and get christmas presents too( href )
Here is something, where I would list gotchas and stupid things that can stop you from going full steam ahead:
require 'user' in application.rb fixed the issue. Cheers to Rails core team for helping me out on IRC. config.load_once_paths = ["#{RAILS_ROOT}/lib"]>> rs.recognize_path "/forums/index"
=> {:controller=>"forums", :action=>"index"}
>> rs.recognize_path "/forums"
=> {:controller=>"forums", :action=>"index"}
>> rs.recognize_path "/forums/index/foo"
=> {:controller=>"forums", :action=>"index", :id=>"foo"}
>> rs.recognize_path "/forums/index/foo.bar"
ActionController::RoutingError: no route found to match "/forums/index/foo.bar" with {}
>> map.connect('/forums/index/:id',
:controller => 'forums',
:action => 'index',
:id => /.*/)
gem install rails --source http://gems.rubyonrails.org --include-dependencies
rake rails:update
request.domain you would normally get just the domain name but with rails 1.2.1 both request.host and request.host return the same thing by default. It means you will have to resort to these sort of ugly hacks: def get_subdomain url
domain_string = url.split("://").last
domain_array = domain_string.downcase.split('.')[0..1]
country_codes = %w[au br ca cn fr de hk in it jp kr mx mg es tw uk us]
country = domain_array.find { |x| country_codes.include? x}
return country
endPosted at 05:08 PM in rails | Permalink | Comments (0) | TrackBack (0)
you can do:
str.tr('A-Z','0-7') to each A with 0 and so onPosted at 02:53 AM in ruby | Permalink | Comments (0) | TrackBack (0)
Dynamic fixtures are nice, but recently I found that It doesn’t work so well with timestamp entries, so if you are trying something like this in your fixture:
message:
pub_date: <%= Time.now %>
it won’t work. The simple solution is:
message:
pub_date: <%= Time.now.to_s(:db) %>Another testing nightmare could be testing your RJS templates or embedded RJS code in controller. Normal asserts won’t work.
assert_rjs :alert, 'Hi!'
assert_rjs :assign, 'a', '2'
assert_rjs :call, 'foo', 'bar', 'baz'
assert_rjs :draggable, 'draggable_item'
assert_rjs :drop_receiving, 'receiving_item'
assert_rjs :hide, "post_1", "post_2", "post_3"
assert_rjs :insert_html, :bottom, 'posts'
assert_rjs :redirect_to, :action => 'list'
assert_rjs :remove, "post_1", "post_2", "post_3"
assert_rjs :replace, 'completely_replaced_div'
assert_rjs :replace, 'completely_replaced_div', '<p>This replaced the div</p>'
assert_rjs :replace, 'completely_replaced_div', /replaced the div/
assert_rjs :replace_html, 'replaceable_div', "This goes inside the div"
assert_rjs :show, "post_1", "post_2", "post_3"
assert_rjs :sortable, 'sortable_item'
assert_rjs :toggle, "post_1", "post_2", "post_3"
assert_rjs :visual_effect, :highlight, "posts", :duration => '1.0'Read about Arts here
Posted at 09:27 PM in rails | Permalink | Comments (0) | TrackBack (0)