Oct 4

I have spent quite a bit of time on this and also Google around.  So I figured I will share:

This assume you are using rails 3.0 or above, Warbler, and Tomcat 7.0 above

  1. Download latest log4j.jar and put it in your rails project’s lib directory
  2. Put your log4j.properties file in the rails root directory
  3. Add this line in warble.rb: config.java_classes = FileList["log4j.properties"]
  4. Add this line in warble.rb:  config.webxml.jruby.rack.logging = ‘log4j’

Explaination:

Step 2 and 3 will allow warbler to put log4j.properties into the WEB-INF/classes directory

Step 4 will make sure jruby-rack using log4j for logging.

If you run into any issue, check your log4j.properties.

Here is the standard one I use:

log4j.rootLogger=INFO, R

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.base}/logs/production.log
log4j.appender.R.MaxFileSize=10000KB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

Apr 26

http://blog.blenderbox.com/2011/01/07/installing-rvm-ruby-rails-passenger-nginx-on-centos/

Mar 13

I just finished another iphone app.  It is a fun app that mix Chinese Fortune Cookies with pictures.  Here it is : http://itunes.apple.com/us/app/ipicfortune/id423065900?mt=8

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

Nov 3

Yes, everyone woke up find out Google analytics has missed yesterday data?  What’s up Google?

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 21

The winner is Palm Pre SDK.  Why?  Palm picks a good architecture using javascript, html and css as its core technologies.  There is little learning curve. Unlike iphone which you need to learn Objective-C, xcode, Cocoa, etc.   It also follows convention over configuration (similar to rails).  Using Eclipse as IDE is also a good choice.  Using VirtualBox as the base of the Emulator is a very smart engineering choice.  I like people who don’t reinventing the wheel.  Setting up is esay and so is getting the helloworld app up.   Good job Palm.  I think you will have a good future in competing with Apple.

« Previous Entries