Picking the last record of each date in mysql

When we have stats, often times the timestamp is involved. So, say we have a table like the following CREATE TABLE IF NOT EXISTS `my_stats_table` ( `id` int(11) NOT NULL AUTO_INCREMENT, `created_datetime` datetime NOT NULL, `value1` int(11) NOT NULL, PRIMARY KEY (`id`) ) Now, all I want is to grab data for each day. Of course, there could be many rows in a day, and there are many ways to handle that. In my case, I need to grab the last row since it’s most accurate. How to do that? ...

July 5, 2012 · 1 min · birdchan

Installing mysql on osx

I often need to do this so I figure I will write it down to remind myself later. First, download the mysql installation dmg file (version 5.5.20 as of now). osx already comes with mysql but I like the extra System Pref icon after the manual install. You can download at http://dev.mysql.com/downloads/mysql/. Pick Mac OS X 10.6 (x86, 64-bit), DMG Archive. Once you have the dmg file, open and install all three files ( mysql-5.5.20-osx10.6-x86_64.pkg, MySQL.prefPane, MySQLStartupItem.pkg) in there. ...

June 30, 2012 · 2 min · birdchan

Using memcache in php

So now I assumed you already got memcache running. If not, check out my previous tutorial on how to do that. Now in your php project, include the following code somewhere in your init.php file. Or you can always make it object oriented if you like. # Connect to memcache: global $memcache; global $memcache_server_up; $memcache = new Memcache; $memcache_server_up = $memcache->connect('127.0.0.1', 11211); # check to see if memcache server is up function memcache_server_is_up(){ global $memcache_server_up; return $memcache_server_up; } # Gets key / value pair into memcache function getCache($key) { global $memcache; if (memcache_server_is_up()) { return $memcache->get($key); }else{ return ""; } } # Puts key / value pair into memcache function setCache($key, &$object, $timeout = 600) { global $memcache; if (memcache_server_is_up()) { return $memcache->set($key,$object,MEMCACHE_COMPRESSED,$timeout); } } My setup will work if you have only one memcache daemon running. If you have a few, then make your changes accordingly. ...

June 28, 2012 · 2 min · birdchan

Setting Google Apps MX records for your domain

If you are trying to receive emails using Google Apps, while hosting your own web server somewhere else, then this tutorial may be useful for you. First of all, I am using Rackspace. But I think this will apply to the general server providers out there. OK, so first, run this little test and read this page created by google. If you get enlightened, good for you. If not, move on. Now, see what MX records currently are set on your server. Type the following in a command prompt. ...

June 27, 2012 · 2 min · birdchan

Installing memcache on osx for php

Finally got memcache working! I am compiling the steps here in case I need to do it again. First install libevent. This is a dependency to memcached, so need to get it. cd /tmp curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz tar -xvzf libevent-2.0.17-stable.tar.gz cd libevent-2.0.17-stable* ./configure make sudo make install Then install memcached. # Compile memcached utility cd /tmp curl -O http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz tar -xvzf memcached-1.4.13.tar.gz cd memcached-1.4.13* ./configure make sudo make install At this point, if everything goes well, the memcache daemon should be ready to run. You can try the following to see if memcached returns anything to you. ...

June 21, 2012 · 2 min · birdchan

Words for Small Sets

link: http://xkcd.com/1070/

June 19, 2012 · 1 min · birdchan

20美元變一萬個熱狗 現實裡五餅二魚故事

http://www.ctitv.com.tw/flash/ctiplayer.swf What it means to give. 我們花了兩個星期時間,在美國採訪貧窮問題,最後在LA認識了一個傳奇的台灣人,她的名字是amywang,在台灣沒唸過甚麼書,因為一些機遇,抱著剛生下來,沒有父親的孩子到了美國,想賺錢,但結果過著流落街頭的生活,因為極度的飢餓和寒冷,她的人生到了死亡的邊源,四十年過去,她從一個無家的人,變成一個專門幫助無家者的人。 ref: http://www.ctitv.com.tw/newchina_video_c134v70467.html

June 2, 2012 · 1 min · birdchan

Hide qtip2

Sometimes when you click on a qtip2 popup, you may want to close the popup somehow. For example, if your qtip2 popup contains a list of links, and clicking on the links will open up more popups. In that case, you would really want to close the previous qtip2 popup upon each link click. Well, here is how you can do that programmatically. $('.qtip:visible').qtip('hide'); Yeah, that’s it. Clean screen. Yeah~~~

May 29, 2012 · 1 min · birdchan

Custom sorting in Datatable

My datatable was acting cool and all until I added a link to each integer element of a particular column. All of a sudden the sorting feature was acting weird. Before I had something like this 23 After adding a link, I have 23 It turns out after I added the links, the default sorting function is treating everything as string. So to fix that I will need to add custom sort function to explicitly tell datatable how I want to do my sorting. ...

May 25, 2012 · 2 min · birdchan

TextMate drawer disappeared...

Sometimes after working on a few TextMate windows, one of them will have its file directory tree drawer missing. I don’t know why this happens but to bring back the drawer, just go to the menu bar and click View -> Show Project Drawer. Also another tip is, if you prefer the drawer to come out from the right side but it always comes out from the left, all you need to do is 1. Hide the drawer 2. Move your TextMate window to the left side of your screen so there is not much space to display the drawer on the left 3. Show the drawer ...

May 25, 2012 · 1 min · birdchan