Of Monsters and Men - Little Talks

[youtube &w=640&h=360] “Little Talks” Hey! Hey! Hey! I don’t like walking around this old and empty house So hold my hand, I’ll walk with you, my dear [Video version:] The stairs creak as you sleep, it’s keeping me awake [Live version:] The stairs creak as I sleep, it’s keeping me awake It’s the house telling you to close your eyes ...

August 8, 2012 · 2 min · birdchan

things broken after installing mountain lion?

Just got a chance to upgrade to mountain lion today. Looking good so far. If you haven’t done it, make sure after you install it also install the system software update from the Mac App Store. Again they renamed my apache and php config files, thus making my website not working properly. To fix that just rename and copy old config files back (they got renamed to /etc/apache2/httpd.conf~previous and php.ini-5.2-previous). ...

July 26, 2012 · 3 min · birdchan

Dirty Waters, Dangerous Fish

[youtube &w=640&h=360] oh gosh… my lovely catfish…

July 23, 2012 · 1 min · birdchan

Representing a class in variable in PHP?

Say you wrote some code below for projectA. function do_task(){ // init my_init(); // calling a class function $v = class_A::some_method($p1, $p2, $p3, $p4, $p5, $p6, $p7); // return return $v; } Now, your boss loves it. Then he asks you to do a very similar thing for projectB. Naively, you may do: function do_task($project_type){ // init my_init(); // calling a class function if ($project_type == "projectA"){ $v = class_A::some_method($p1, $p2, $p3, $p4, $p5, $p6, $p7); }elseif ($project_type == "projectB"){ $v = class_B::some_method($p1, $p2, $p3, $p4, $p5, $p6, $p7); } // return return $v; } Um… it would work, but imagine if you will soon have projectC, and D, and on… and what if you need to add one more parameter to the some_method function? ...

July 23, 2012 · 2 min · birdchan

Text wrapping inside a table

Sometimes I have a long continuing string inside a table that messes up my table width. For example, SDFSDFDGFHDGREFGFGSDFGFGHGDSFGHJTYRGHTYYEGHJTRTWEGRTYEGFHERGHRETERHRTTWERHGEWGERGW That will give you a very wide column… Just how to squeeze the column to the width we specify? “Easy,” you might say, “just set the td width!” SDFSDFDGFHDGREFGFGSDFGFGHGDSFGHJTYRGHTYYEGHJTRTWEGRTYEGFHERGHRETERHRTTWERHGEWGERGW Nope. It turns out the same, one long continuous string. The root problem here is that, the table width is determined by the content, but not the width we specify! ...

July 20, 2012 · 1 min · birdchan

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

Home Organization

July 4, 2012 · 0 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