Archives for: June 2010
ActiveRecord without Rails
June 14th, 2010Link: http://blog.aizatto.com/2007/05/21/activerecord-without-rails/
The basic idea is to using following method to connect database.
require "active_record"
ActiveRecord::Base.establish_connection(params)
The params must be a hash or object.
Based on this method, user can use yaml to load configure just like rails do:
dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)
SQLite sample
development: adapter: sqlite3 database: db/development.db pool: 5 timeout: 5000
Migration
ActiveRecord::Migrator.up('db/migrate')
class CreateLogTables < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
t.integer :account_id
end
end
end
Using ActiveRecord
class Account < ActiveRecord::Base
has_many :sessions
end
class Session < ActiveRecord::Base
belongs_to :user
has_many :actions
end
class Action < ActiveRecord::Base
belongs_to :session
end
Logger
ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a'))
ActiveRecord::Base.colorize_logging = false
Build kernel for Ubuntu 10.04
June 12th, 2010Link: https://help.ubuntu.com/community/Kernel/Compile
Install package and source
sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package
Get source
sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r) apt-get source linux-image-$(uname -r)
Accerlerator Net::HTTP download performance
June 10th, 2010Link: http://www.ruby-forum.com/topic/73148
Here is a very useful document about net::http performance. It introduces a idea that small buffer used in rbuf_fill causes interior performance of net/http. And he also introduce a workaround. The general idea is override the default behavior. Here are code:
class OverrideInternetMessageIO < Net::InternetMessageIO
def rbuf_fill
timeout(@read_timeout) {
@rbuf << @socket.sysread(65536)
}
end
end
class NewHTTP < Net::HTTP
def NewHTTP.socket_type
OverrideInternetMessageIO
end
end
A great site contains many free software
June 7th, 2010Link: http://mulder.dummwiedeutsch.de/home/?page=guestbook
This is a great site containing free software for video playing, authoring and other utilities such as mplayer, avimux, DirectorySize etc.
Fix chinese problem for Console2
June 5th, 2010Console2 is a great replacement for cmd. But it has problem to display chinese characters. The root case is that console assume that one character only occupy one column. Even it is true for english, but it is wrong for chinese. I patch a quick and dirty fix at least work for chinese character.
I attach win32 release version you can used to override original console. Please get from here http://blog.joyofthink.com/yangchen/media/blogs/a/console_chinese.zip
Pass argument to Rakefile.
June 2nd, 2010Link: http://stackoverflow.com/questions/825748/how-do-i-pass-command-line-arguments-to-a-rake-task
The most usable format is:
use ENV["name"] to access.
It supports "rake var_name=var_value"