| Latest |Kites |Pictures |Programming |Life |
|
Hacking code together. Is it art? Is it science? Can it be quantified? Are comments really essential? Who knows, I sure as hell don't. ![]() Python chain methods ![]() I don't know why I didn't know this, but you can chain methods in Python. I use this quite a bit in PHP and Zend Framework uses it a little. But here it is in Python: class table_model: >>> That's it. Job done. ![]() MySQL max of two columns ![]() How to get the MAX or MIN value of two columns: GREATEST( col_1, col_2 ) Or a more interesting example. I have a client who may have some reports. I need to list the clients in 'most recently active' order. So if they have had a recent action they should be near the top of the list, or if they have recently had a report they should be near the top of the list: SELECT clients.id, clients.name, clients.date, MAX(r.date), GREATEST(clients.date, IFNULL(MAX(r.date), clients.date)) AS date So this uses MAX to get the most recent report (this may return NULL if they have no reports) then I use GREATEST to choose the most recent of the two dates (two columns). Job done.
![]() since I put ![]() Google analytics, page views from Feb 2007 to July 31 2008: 2,405,706
![]() Part of the problem ![]() Part of the problem is that programming is hard to teach. “Programming is a mixture of a highly technical skill and an aesthetic art. And that’s a very difficult combination.” Not really. It's only a problem if you care... ![]() Python static method staticmethod ![]() Tagged: @staticmethod, staticmethod, class, def, static, static method, static variable, python, def, __init__, self OK, I'm always forgetting how to add static methods to Python classes, so: class C:
>>> Job done.
![]() PHP Closeures ![]() PHP 5.3 has closures in it! Finally we get some good stuff to play with: PHP 5.3 and Closures. This is excellent news, even if the closures look weird -- look at the strange use keyword.
![]() Zend Framework DB Insert NOW ![]() Some keywords: SQL Insert Update Zend_Db_Table_Row NOW() now function Zend_Db_Table Zend_Db_Expr Use the SQL function NOW() in ZF: $k = new My_Table(); This works because DB Expr doesn't escape the string 'NOW()'. Yay. |
| Unique hits [] : Total hits [] : Server Grind [0.0348 seconds] |