Q&A

  • Why an instance method not available in class method?

because you need an object of the class to call an instance method

  • where to change home directory and shell?

/etc/passwd on your machine

  • why do operation in migration instead of database level?

Because it is more flexible using validations, and more important, is to change active records correctly! It is dangerous to change db without testing.

  • CLN = chang list number, VFI = version filter instance

soggy adj, soft, wet: the bag of cookies will become soggy if we don’t zip it.

Advertisements

Time in ruby

why ruby does not have 15.minutes method? rails seem does

because rails defines it

is there any way to get Time.now-15.minutes with ruby?

Time.now-15*60

=> Thu May 31 09:52:34 -0700 2012

minus the number of seconds

 

>> a=Time.now
=> Mon Jun 11 19:40:57 -0700 2012
>> a-15*60 (seconds)
=> Mon Jun 11 19:25:57 -0700 2012
>> a=DateTime.now
=> Mon, 11 Jun 2012 19:41:09 -0700
>> a-15*60 (days)
=> Thu, 24 Dec 2009 19:41:09 -0700

Parameter URL in Ajax of jquery

I am always wondering where the request will be sent after calling ajax; i.e., after the ajax action, what controller/action in Rails will be called.

see

jQuery.ajax( url [, settings] )

urlString
Default: The current page

A string containing the URL to which the request is sent.

when calling ajax, url is a string the request going to. When there is no value, it will be the current page by default.

OptionParser

Simple Switch

A simple switch is an argument with no optional forms or no parameters. The effect will be to simply set a flag in the options hash. No other parameters will be passed to the on method.

options[:simple] = false
opts.on( ‘-s’, ‘–simple’, “Simple argument” ) do
options[:simple] = true
end

Switch with Mandatory Parameter

Switches that take a parameter only need to state the parameter name in the long form of the switch. For example, “-s”, “–simple Simple” means the -f or –file switch takes a single parameter called Simple, and this parameter is mandatory. You cannot use either -f or –file without also passing it a parameter.

options[:simple] = “”
opts.on( ‘-s’, ‘–simple Simple’, “simple with an argument” ) do|f|
options[:simple] = f
end

If without ‘Simple’ inside ‘–simple Simple’, the value of f will be switch value: true or false, rather than the real simplevalue in the command line”–simple simplevalue”

http://ruby.about.com/od/advancedruby/a/optionparser2.htm

need () for “not expression”

>> a=1
=> 1
>> not a
=> false
>> Rails.env.production?
=> false
>> Rails.env.development?
=> true
>> not Rails.env.development?
=> false
>> a && not Rails.env.production?
SyntaxError: compile error
(irb):6: syntax error, unexpected kNOT
a && not Rails.env.production?
^
from (irb):6
>> a && (not Rails.env.production?)
=> true
>> a && !Rails.env.production?
=> true

Movies and Novels

  • Finished “Six Feet Under”

Very good TV series in which people find ways to let their depress out

  • finished “young adult” and “underworld 4”
  • finished “SAN TI” (三体), a fiction novel

Making people to think widely: There is a planet with three suns which causes the chaos. Why three suns cause chaos? Because if there is one sun in the sky with no gravity force from other planet on it, the sun will be still in the sky and the day and night will show up regularly. When there are two suns, because of gravity, finially, these two suns will find a steady state after some rotations. But if there are three suns, the gravity between these suns makes the trail of any sun unpredictable and there are no model can predict their future moving. When people can see one sun, like what we did on earth, the world is steady. When people see two suns, it becomes too hot that people dry out and become a piece of dry skin. When there are three suns show up together, the world will be destroyed in a second because of the unbearable high temperature, so civilization disappear until next dynasty. When the one sun shows up again, the dry skin was put into the water, then people have body again. It is also possible that none of the suns show up, leading the sky endless dark with icy cold, just like living in south and north poles of earth.

When people on earth try to find out aliens outside the sky, they find out the classic physics is false. All the classic theory and models become big lies.  That makes many more people desperate and commit suicide. Especially, some people found that the picture they are taking have a number of dates, which is impossible in 60s. Interestingly, those dates are decreasing, from 2000:16:00, 2000:15:00 to 1999:16:00 next day. People are wondering that what will happen when the dates become zero.

It turns out that the three suns planet and earth know the existence of each other, which is exciting that knowing there are lives outside their own planet. But every planet has its own problems: wars and nuclear weapons, killing animals and cutting down trees. The people in three suns planet are afraid that the moral disciple and people’s life value won’t mix with that on earth. So the three suns planet decide to destroy earth, while people on earth are actively sending messages of hopes to people in three suns people. Actually, the big lies seen by earth people are created by three suns planet. It is ironic that earth people want help and wait for being saved from three suns planet.

Then ending is fuzzy but give hope to earth people. Like no matter how hard we try to kill insects, insects still exist in this world. If earth people are so tiny like the insects in the eye of three suns planet,  aliens in three suns planet cannot destroy earth, just like earth people cannot kill all of insects.

Facts: earth is a planet, 行星,which is moving and have no light of its own; Sun is a star,恒星,which rarely moves and have its own light. We have sunrise and sunset because of the earth’s self-rotation.