Jan 7

After many hours of work, I finally got my iphone app approved by Apple app store.  Here it is:  http://itunes.apple.com/us/app/ushospfinder/id412630399

Mar 1

Here is a question comes up a lot. Here is how to do it without additional plugin.
config/database.yml:

development:

adapter: sqlite3
database: db/development.sqlite3
timeout: 5000

second_development:

adapter: sqlite3
database: db/second_development.sqlite3
timeout: 5000

test:

adapter: sqlite3
database: db/test.sqlite3
timeout: 5000

second_test:

adapter: sqlite3
database: db/second_test.sqlite3
timeout: 5000

production:

adapter: sqlite3
database: db/production.sqlite3
timeout: 5000

second_production:

adapter: sqlite3
database: db/second_production.sqlite3
timeout: 5000

migration for models in first database is like normal migration, example (xxxxxxx_create_user.rb):

def self.up

create_table “users” do |t|

t.string “password”
t.string “email”

t.timestamps

end

end

def self.down

drop_table :users

end

migration for models in second database require slightly modification, example (xxxxxxx_create_dogs.rb)

def self.up

ActiveRecord::Base.establish_connection “second_#{RAILS_ENV}”
create_table :dogs do |t|
t.string :name, :null=>falset.timestamps
end
ActiveRecord::Base.establish_connection “#{RAILS_ENV}”

end

def self.down

ActiveRecord::Base.establish_connection “second_#{RAILS_ENV}”
drop_table :users
ActiveRecord::Base.establish_connection “#{RAILS_ENV}”

end

Note that schema_migration table is located in the first database (default one) only in this case.

Models for the first (default database) is the same as regular rails model.

Models for the second database requires adding the following line in the Models:
establish_connection “second_#{RAILS_ENV}”
Example:

class Dog < ActiveRecord::Base
establish_connection “second_#{RAILS_ENV}”
end

That is it.  Not that complicated.

Sep 4

I am currently reading a book on Erlang Programming by Francesco Cesarini:Erlang Programming .  It is quite well written.  In it, there is some programming exercises.  One of them is to write a simple key value DB.  So I wrote one.  Here it is:

-module(db).
-export([new/0,destroy/1,write/3,delete/2,read/2,match/2]).
new()->Db=[],
Db.

destroy(Db)->_=Db,
ok.

write(Key,Element,Db)->NewDb = [{Key,Element}|delete(Key,Db)],
NewDb.

delete(Key,Db)->case Db of
[H|T] ->
case H of
{Key,_} -> T;
_-> [H|delete(Key,T)]
end;
[] ->Db
end.

read(Key,Db)->case Db of
[H|T] ->
case H of
{Key,Element} ->Element;
_->read(Key,T)
end;
[] ->{error,instance}
end.
match(Element,Db)->case Db of
[H|T] ->
case H of
{Key,Element}->[Key|match(Element,T)];
_ ->match(Element,T)
end;
[] ->Db
end.
To use it:

1> Db = db:new().
[]
2> Db1 = db:write(book,elrang,Db).
[{book,elrang}]
3> Db2 = db:write(author,francesco,Db1).
[{author,francesco},{book,elrang}]
5> db:read(author,Db2).
francesco
6> db:match(elrang,Db2).
[book]

Not very useful but it shows how to write simple program in erlang.

Jul 30

Yes, it is true.  I have tried it on many times and look at them side by side.  I will say Bing is as good if not better than Google.  Google now finally have a competitor.  Yahoo makes the right decision to use Bing.

Jul 23

This is ofcourse a rhetorical question.  I know we can’t write law like we write software because the political process will never be able to do that.  But think for a moment for the why shouldn’t we?  Law likes software is a set of rule governing a system.  Although law is not exact instruction like software but it acts almost like  software requirements or system specifications.  We don’t expect to write a perfect requirements and system specificatons right the first time we try.  That is why software development has become an iterative and agile process.  A good software development process will require small iteration, constant refinement, constant feedback.  Law should use the same kind of process.  Instead of trying to get it perfect the first time. Why can’t we just keep iterating?

Jul 20

I just installed the Palm Pre SDK which includes the emulator.  I also installed the eclipse plug-in.  I have to say.  It is so far so good.  Palm has  a good website to guide you through: http://developer.palm.com/index.php .  I am going to play more and see how easy it is to develop an application.

Jun 18

Add these two sites through help->software updates

Name :RDT
URL : http://updatesite.rubypeople.org/release
Name :RadRails
URL : http://radrails.sourceforge.net/update

Jun 10

I am learning scala and erlang the same time to get an idea of FP.  So far, I like Erlang better in term of syntax.  Scala is good but its syntax is just getting too complicated.  It is trying to replace java but the its syntax is no simpler than java.  I think if Scala is not static type, the syntax would be simpler.

Jun 8

I am starting to learn Scala. This will be my first step to Functional programming world (even though Scala is not a pure functional programming language, it supports OO too).  I highly recommended this article for anyone who wants to take the first step: http://www.artima.com/scalazine/articles/steps.html .

Apr 20

Oracle is offering to buy Sun at $9.50 per share (http://news.yahoo.com/s/ap/20090420/ap_on_bi_ge/oracle_sun).  That is bad news for Sun, Java and MySQL.  Sun bought MySQL and I thought it was a great idea to compete with Oracle.   Now MySQL is under Oracle and you know Oracle is going to kill MySQL because they don’t want free open source database to compete with their product.  It is time to fork MySQL to a different open source project so that it won’t be controlled by Oracel.

« Previous Entries