You might often want to connect to different databases using ActiveRecord. Here’s how you do it:
class DatabaseCurrent < ActiveRecord::Base
self.abstract_class = true
class DatabaseOld < ActiveRecord::Base
self.abstract_class = true
#Model definitions (current):
class Video < DatabaseCurrent
class Photo < DatabaseCurrent
class User < DatabaseCurrent
class Tag < DatabaseCurrent
#Model definitions (old):
class FileDB < DatabaseOld
Pretty easy. The only thing to note is that you should
set_table_name, otherwise, AR chokes up. Also, often you want to directly play directly with SQL. Unfortunately,
ActiveRecord::Base.execute doesn’t work any longer (coz it doesn’t have a connection), but you can do it this way:
That’s the tutorial for the day!
A hint for developers on the Orkut Sandbox, download its two CSS files: here and here and use those classes to style your content. It feels much more a part of orkut that way. To figure out what styles to use, firebug the orkut page.
A lot has been said about OpenSocial and Facebook, this is an attempt to say a bit more. As usual, a free-flowing list of observations:
- It’s currently not clear how OpenSocial apps communicate between each other across networks and how one app maps a user profile in one network to another. Without this, it’s mostly a single API which works across multiple containers in isolation. A single API that collates multiple containers is much more interesting.
I’m loving web.py for developing tiny web apps. Here’s how to get it going on a Mac:
sudo port -v install python2.4 py-setuptools mysql5
#coz macports insists on adding a '5' suffix to all mysql5 tools.
sudo ln -s /opt/local/bin/mysql_config5 /opt/local/bin/mysql_config
sudo easy_install web.py cheetah markdown MySQL-python DBUtils
Not the twenty odd steps that’s on the web.py page (that even includes installing and configuring postgresql – bizarre!).
What I love about web.py is that this small bit of code:
urls = (
print "Hello, world!"
if __name__ == "__main__": web.run(urls, globals())
… and running
python code.py in a terminal gets you a working dev environment. Even camping doesn’t feel this tiny.
Edit: the performance numbers for this simple action are also very impressive:
time httperf --client=0/1 --server=localhost --port=8080 --uri=/ --send-buffer=4096 --recv-buffer=16384 --num-conns=10000 --rate=500
httperf --client=0/1 --server=localhost --port=8080 --uri=/ --rate=500 --send-buffer=4096 --recv-buffer=16384 --num-conns=10000 --num-calls=1
Maximum connect burst length: 17
Total: connections 10000 requests 10000 replies 10000 test-duration 20.000 s
Connection rate: 500.0 conn/s (2.0 ms/conn, <=24 concurrent connections)
Connection time [ms]: min 0.1 avg 1.8 max 2987.4 median 0.5 stddev 42.2
Connection time [ms]: connect 0.7
Connection length [replies/conn]: 1.000
Request rate: 500.0 req/s (2.0 ms/req)
Request size [B]: 60.0
Reply rate [replies/s]: min 499.8 avg 500.0 max 500.0 stddev 0.1 (4 samples)
Reply time [ms]: response 1.0 transfer 0.0
Reply size [B]: header 108.0 content 14.0 footer 2.0 (total 124.0)
Reply status: 1xx=0 2xx=10000 3xx=0 4xx=0 5xx=0
CPU time [s]: user 3.75 system 9.17 (user 18.7% system 45.8% total 64.6%)
Net I/O: 88.9 KB/s (0.7*10^6 bps)
Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0
httperf --client=0/1 --server=localhost --port=8080 --uri=/ --send-buffer=409 3.75s user 9.17s system 64% cpu 20.028 total
That’s 10K connections and more than 500req/s in a 20 sec timeframe. Really good.