cherrypy.subscribe or cherrypy.on_start or cherrypy.on_stop

February 29, 2008 § Leave a comment

Sometimes, on your web application, there are other processes that happen independently from typical HTTP requests.

The type of such processes can be:

  • daemon / cron.
  • setup / deployment script.

If such processes are not registered to cherrypy, cherrypy might not be able to auto-reload properly when server-side codes changed. In general it is nice to have those processes starting/stopping properly relative to the web server (cherrypy in this case).

In cherrypy 3.1, processes like those can be registered via callback using cherrypy.subscribe function. See below:

  • engine.subscribe(‘start’, callback).
  • engine.subscribe(‘stop’, callback).
  • engine.subscribe(‘start_thread’, callback).
  • engine.subscribe(‘stop_thread’, callback).

Above functions in cherrypy 3.0 are:

  • engine.on_start_engine_list.append(callback).
  • engine.on_stop_engine_list.append(callback).
  • engine.on_start_thread_list.append(callback).
  • engine.on_stop_thread_list.append(callback).

References:

Advertisements

Javascript: Array.sort()

February 20, 2008 § Leave a comment

What is it?

It is a global function that’s a built-in of Array object.

Syntax:

Array.sort(comparisonFunction);

How to use sort():

  • If sort function is being used without comparisonFunction parameter, the values inside array will first be converted into string, and sorted lexically.
  • If sort function is used with comparisonFunction, it must return either 1, 0, or -1 depending on the comparison.

Here is a sample of comparisonFunction:

function compare(a, b)

{

if ( a < b ) { return -1; }

else if ( a > b ) { return 1; }

else () { return 0; }

}

Reference:

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:sort

Games: Pirates Online

February 17, 2008 § Leave a comment

Pirates Online is MMORPG based on Pirates of The Caribbean. This game is actually fun. Fun in a non demanding, casual but still packing lots of action. This game might actually worth spending monthly subscription.

Below are some good points about why I think this game rocks:

  • The game client is fast to download (with cable connection) (+1.02).
  • Pirates Online is not demanding at all in terms of graphic card (+999.99).
  • There’s compelling single player story (+0.5).
  • Navigation and Menu are easy to learn thanks to in-your-face-big-fat-arrow help pointers (+99.123).
  • It is available on Mac (+9999999.99).
  • Ship battles are sooo much fun (+15.00002).

Some of the bad thing on why it sucks:

  • Free account is short, very very short. (- 10.3234)
  • $15 per month might be a bit too expensive because it is not WOW (-1000,2213).

Try it, and see if you like Pirates Online.

What people said about Python sucks

February 12, 2008 § 5 Comments

http://mikewarot.blogspot.com/2008/03/python-sucks.html — Seriously? There are multiple ways of solving his problem since string behaves like list of chars.

http://dannyman.toldme.com/2003/02/19/why-python-sucks/Funny and exaggerating post about him not knowing documentation command in Python. I think he is definitely joking.

http://mail.python.org/pipermail/python-list/2000-February/023373.htmlPython mailing list, funny trolling without any reasons why Python Sucks Loud. Other people’s responses are funny as well.

http://www.neopoleon.com/home/blogs/neo/archive/2005/03/03/14801.aspxHe said, “Because I kind of think Python sucks and is as overrated as OS X and Pink Floyd.” Somehow, I don’t mind that quote at all.

http://zifus.blogspot.com/2005/12/ruby-on-rails-vs-python-web-frameworks.html —¬†His first point is: Python Web Framework will never surpass Rails. I really don’t care about python web framework. Python programmers do not need web frameworks. His second point is: Python indentation (This kind of complaint is becoming like broken record).

http://daily.bluebones.net/2006/05/python-sucks.htmlFirst point:¬†Explicit self. Next point:¬†Indent… again… (God damn it, just drop it already)

http://wiki.theory.org/YourLanguageSucksNow, this is FUN! See how this wiki posting blasted on all languages.

Asynchronous I/O Programming

February 10, 2008 § Leave a comment

Some basic stuff. By Henrik Thostrup Jensen.

Still on YouTube Architecture

February 10, 2008 § Leave a comment

Readers have seen the slides, now you get to see it on Google Video.

TurboGears part 1: First Encounter

February 5, 2008 § Leave a comment

I’ve been reading TurboGears website, wiki, & FAQ for almost 2 weeks, now it’s about time to build something with it.

Below are steps I’ve done to have some sort of “Hello World” stuff.

Some Basic Pre-Assumptions

  • You have already installed Python
  • You will want to install easy_install. Read this for install instruction. Easy Install is like apt-get for Python modules.

Installation

  • Download tgsetup.py from TurboGears website. Then run the script by calling python tgsetup.py
  • The process above will install a whole bunch of TurboGears component such as:
    • Kid(think CakePHP’s thml or Rails’ rhtml)
    • CherryPy(think of WebServer)
  • SQLObject (think Rails ActiveRecord) is preferred by TurboGears, so we need to install it. In your command-line console, type: easy_install sqlobject.
  • When above are all finished, it’s time to create new project.

Creating New Project

  • TurboGears gives you tg-admin tool (just like Rails’ generate or CakePHP bake script), so let’s use it.
  • tg-admin is an interactive command-line tool which help you building some basic structure for your application.
  • When this process is finished, see if your project is runnable.

Run the Web Server, See if Your Project is Runnable

  • Inside your project directory, from command-line, type: python start-{your_project_name}.py
  • By default, the web server (which is CherryPy) is using port: 8080. If that’s being used, change the configuration, which I will tell you how below.

Changing the Configuration

  • The default configuration of TurboGears is pretty light weight, not quite real life setting. If you don’t like it, modify dev.cfg file.
  • Inside dev.cfg file, you can:
    • use MySQL instead of SQLLite
    • Change the port of your Web Server
    • and more…
  • Try restarting the server, see if your new configuration works.

Well, congratulation, you just created the structure for your next WEB 2.0 project!

In the next series, I will describe my adventure, using TurboGears, to build: Calculator! The next big thing in Web 2.0 world.

Where Am I?

You are currently viewing the archives for February, 2008 at RAPD.