Posterous theme by Cory Watilo

Laptop Battery Myths

What your friends tell you about battery conditioning probably does not apply to the Lithium-ion-polymer batteries presently used by most computer manufacturers.

This is what you need to know.

  1. It is OK to keep your laptop plugged in all the time.
  2. You run your laptop on battery at least once a month – this should be easy, it’s a laptop right?.
  3. Battery capacity diminishes over time. Expect to lose most of the capacity within 2-3 years after manufacture.

via post by Laptop battery myths

Battery technology has unfortunately not caught up with the rest of technology. Laptops with batteries that lasts for days are long overdue.

Relationships & Marriages in the Chinese Culture

I have been spending most of my time in mainland China for my trip, specifically, the Shanwei City (Haifeng county) within the Guangdong Province.

Through living here, I’ve observed a couple interesting facts. One of these is the acceptance of age difference among couples within a relationship; it seems to differ greatly from what we’re used to in the Western culture.

In China, it is perfectly acceptable for a adult male to marry someone twenty years younger; on the other hand, it is generally unappreciated for a male to marry an older women. Such bias is especially prominent in traditional upper-class chinese families where there is a strong emphasis on power and social status.

My opinion is that age is just a number, one that is insignificant when the couple in question are both mature adults (20+) and are at a point where they are responsible and self-sustainable.

At the end, it all comes down to living a happy life.

Dynamic Namespaced Class Instantiation in Ruby

Lets assume we have a module called Fruit, within the Fruit module is a bunch of Fruit classes.

module Fruit
   class Apple
   end
   class Orange
   end
   class WaterMelon
   end
end

If the name of the fruit comes from some data or memory store, and we want to instantiate the class dynamically via the fruit name, you might attempt to do something like this:

>> fruit_name = "Apple"
> "Apple"
>> class_name = "Fruit::#{fruit_name}"
> "Fruit::Apple"
>> klass = Object.const_get(class_name)
NameError: wrong constant name Fruit::Apple
        from (irb):14:in `const_get'
        from (irb):14

The problem here is #const_get does not support retrieving constants within a nested namespace. In order to combat this, we must first retrieve the module in which the class is in, then get the class.

>> Module.const_get("Fruit").const_get(fruit_name)
> Fruit::Apple
>>

Here is an example in action:

module Fruit
  class Apple
    def self.color
      "red"
    end
  end

  class Orange
    def self.color
      "orange"
    end
  end

  class WaterMelon
    def self.color
      "green"
    end
  end
end

%w{Apple Orange WaterMelon}.each do |fruit_name|
  klass = Module.const_get("Fruit").const_get(fruit_name)
  puts klass.color
end

# output
red
orange
green