• joyofthink
  • Linkblog
  • Photoblog

Joy of Think


  • Home
  • About Blog A
  • About this system
  • Contact
  • Log in

Using sqlite db in android

July 25th, 2010

Android 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'

Posted in Welcome | Send feedback »

我家小宝的照片

July 12th, 2010

百般恳求,医生终于大发慈悲,帮着拍了几张照片。

Posted in Welcome | Send feedback »

ActiveRecord without Rails

June 14th, 2010

Link: 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

Posted in Welcome | Send feedback »

Build kernel for Ubuntu 10.04

June 12th, 2010

Link: 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)

Posted in Welcome | Send feedback »

Accerlerator Net::HTTP download performance

June 10th, 2010

Link: 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

Posted in Welcome | Send feedback »

1 2 3 4 5 6 7 8 9 10 11 ... 15 >>
  • July 2010
    Sun Mon Tue Wed Thu Fri Sat
     << <   > >>
            1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31
  • Joy of Think

    • Recently
    • Archives
    • Categories
    • Latest comments
  • Search

  • Categories

    • All
    • Background
    • Bookmark
    • English
    • Fun
      • In real life
        • Movies
        • Music
        • Sports
      • On the web
    • News
    • Programming
      • Android
      • C++
      • Linux
        • Toolchain
      • Perl
      • Web
        • Catalyst
        • HTML
        • Javascript
          • YUI
      • Windows Kernel
    • Toolkits
      • vim
    • Welcome
  • Blogroll

    • b2evolution
      • Blog news
      • Manual
      • Support
      • Web hosting
    • contributors
      • Daniel
      • Danny
      • Francois
      • Yabba
  • XML Feeds

    • RSS 2.0: Posts, Comments
    • Atom: Posts, Comments
    More on RSS
powered by b2evolution

©2010 by yangchen | Contact | Design by Michael | Credits: free blog | green hosting | François