Category: Welcome
Using sqlite db in android
July 25th, 2010Android has built-in sqlite database support. But it needs special table in database before it can be used:
- A table named android_metadata which only have one TEXT columm: locale.
- A record in this table, value is en_US.
Here are samples of SQL:
CREATE TABLE if not exists android_metadata (locale TEXT)
insert into android_metadata(locale) value 'en_US'
我家小宝的照片
July 12th, 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