01110000 01100001 01110011 01110011 01101001 01101111 01101110

Laptop Battery Myths

Posted: February 25th, 2010 | Author: Kevin | Filed under: Random, Tips | Tags: | No Comments »

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](http://www.marco.org/195827279

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


Dynamic namespaced class instantiation in ruby

Posted: February 12th, 2010 | Author: Kevin | Filed under: Development, Tips | Tags: | No Comments »

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

VIM tip of the day: quickly reformat your document

Posted: July 25th, 2009 | Author: Kevin | Filed under: Development, Tips, Tool | Tags: , , | No Comments »

Quickly reformat your document in VIM with:

gg=G
  • gg goes to the beginning of the document
  • = kicks off the indent filter (:help = for more information)
  • G goes to the end of the document

Another way to achieve the same result through visual mode is.

ggvG=
  • gg goes to the beginning of the file
  • v enables visual mode
  • G goes to end of the file
  • = apply indentation

Similarly, if you are on a line that needs formatting, simply use ==, or v=. You can also select a block of code in visual mode and press = to reformat the selection.

Breath this command and make your team happy.

If you find this post useful, please drop a line in the comments.