Monday, March 30, 2009

superclass mismatch for class Item

I had an "superclass mismatch for class Item" when I ran rake db:migrate. It was because I defined the same class twice. The model class is Item and I happened to have another class Item in my migration.
mir% grep -R 'class Item' .
./test/unit/item_test.rb:class ItemTest < Test::Unit::TestCase
./app/models/item.rb:class Item < ActiveRecord::Base
./db/migrate/20090325060057_item.rb:class Item < ActiveRecord::Migration
I changed the class name in 20090325060057_item.rb from Item to AlterItem, but this was not enough. This gives me rather hard to corelate error message:
undefined method `migrate' for Item(id: integer, created_at: datetime, updated_at: datetime):Class
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in `method_missing_without_paginate'
/usr/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:170:in `method_missing'
It turned out that it was caused by filename and class name mismatch. I had to change the filename to 20090325060057_alter_item.rb to match with AlterItem class name.

Decluttered My Desk

It is hard to say whether I am an organized person or not. I am fairly meticulous about details, but my desk ended up like this recently.
送信者 for gacooh
Originally, I was thinking of adjusting the height of the desk and considering to replace my office desk. My research was to use Flickr to get ideas by searching "office desk" tags. I came across a very clean desk with a computer.
Office Desk Setup CC by tomas carrillo
A blog post refers another attempt: "Declutter Your Desk by Van Mardian". It looked like a doable and cheap solution to me. So, I decided to do it as my weekend project (and I forgot the original attempt of buying a new desk!).
The cable mess
I've purchased a peg board, cable ties, and shackles from OSH and Home Depot, and put most of the devices to the peg board. Physical work wasn't hard, but figuring out an suitable layout was. My first attempt was not optimal but I just line the devices up and it worked out okay. It has two cable taps, a cable modem, a wifi router, a network hub, a skype phone base, two external hard drives, an usb hub, and a usb audio output.
送信者 for gacooh
I flipped the desk back and connected a bunch of cables, and it looks quite well. The USB hub and audio jack are accessible from the front.
送信者 for gacooh
送信者 for gacooh
Most of the clutters were just needed to be cleaned up, but there were also a couple of things on the desk such as an USB audio, external hard drives, and an USB hub. They actually made the desk look cluttered even if I cleaned up. I'm satisfied with the improvement. There are still things under the desk and it is clear that they needs to be tidied up. It sounds a lot easier task as most of the stuff has been already handled.
送信者 for gacooh
送信者 for gacooh

Wednesday, March 25, 2009

attr_accessor is a method

Somehow I thought the action of defining a class is an declaration and doesn't execute statements, but I was wrong.
class MyClass
  put "Hello world"
  def MyMethod
    puts "output from MyMethod"
  end
end
The Ruby code above actually spits "Hello world". I tried this with Python and Python did the same. The reason I wondered this was Ruby's attr_accessor.
class MyClass
  attr_accessor :a
end
It looked to me like an declaration of @a to have accessors, but it isn't. attr_accessor is an method implemented in Module class and it is not a reserved word. The truth is that attr_accessor is executed when the source code is interpreted and it defines accessor methods. AH!

Saturday, March 21, 2009

Energy Saving

When I received the first PG&E bill after I moved into the current house, I was shocked with the amount. Electricity was $243.58.
I am not an avid environmentalist, but it became so clear that I wanted to save the earth, eh, $$$. And it is a good game for an engineer because it is clearly measurable.
The baseline was 34.65Kwh/day. The game was started with replacing light bulbs to compact fluorescent lamp (CFL) bulbs. The technology was far more advanced than I thought and the color is like regular light bulbs and there's even dimmer-able ones. These CFLs requires roughly 1/5 of electricity for the same brightness. The only drawback is the slow warm-up. It takes a minute or so to reach the full brightness. There are white LED lights which is even better and it only consumes a few watts, but they are still too-white, dark, and expensive.
Switching to these CFLs saved 6Kwh or so a day. The family room had eaten the most and kitchen was the next.
However, last two months or so, I couldn't bring it down further. I was wondering what was eating that much electricity. It turned out that there was lights in my backyard. Again, these were halogen lights. While it is nice to light up, I really don't see outside much at night, I just decided to turn them off completely. Result? It was great. It shelved another 3.8Kwh/day.
It actually brought the daily electricity cost by 47% to $104.79 while the electricity usage was down by 31%. The reason was electricity's heavy progressive cost structure.
Baseline usage (415.8 Kwh) @ $0.11536
101-130% (124.74 Kwh) @ $0.13115
131-200% (291.06 Kwh) @ $0.24711
200%-300% @ $0.35432
If you use more than twice as the baseline, your electricity is more than 3x expensive. Actually, the gas's cost structure is not as steep as electricity, you may want to use gas appliances over electricity ones. In my personal experience, electric heater was worse than gas furnace, and I am glad that I bought a gas dryer.
The next target is going to be lighting in bathrooms.

Monday, March 9, 2009

How to overcome the boring Internet?

I wrote a blog post on how to find interesting things on the internet while back in Japanese. My argument was "don't use sites like Digg". Following what many people like is reasonably fun, but it doen't satisfy you fully. In the post, I said that I found it better to search on a random topic which you are interested in. Although I said that, I sometimes see myself still visiting Digg, a Japanese social bookmark site, various news sites, and Google reader and read through all the new stuff and I was still not satisfied (this is what I said what was going to happen). I thought about why I did this instead of doing searches. It seems that it was hard to find a good keyword to start with. It requires some brain power. Once I found A keyword, following queries are easily following, but finding the first one is actually tough. So, I thought about how to come up with the first search keyword. I think I reached to a conclusion for myself: "use del.icio.us". I have been using del.icio.us to bookmark pages which I found useful. There's no single topic on my interests and my delicious bookmarks scatter across train, graphic design, programming, and bicycle. When I need to come up with the first keyword, my past bookmarks become a good starting point. I can continue a research on the last topic. I stopped digging for some reason (felt sleepy, needed to go out), but usually not because of completely satisfying myself. The information on the Internet is bottomless. Or, I can randomly click a tag to see what I bookmarked. It allows me to pick a path of Today's expedition. The topics are always relavent to you because all the content was prepared by yourself.