launchctl list

Here is what the output of “launchctl list” means: list [-x] [label] With no arguments, list all of the jobs loaded into launchd in three columns. The first column displays the PID of the job if it is running. The second column displays the last exit status of the job. If the number in this column is negative, it repre- sents the negative of the signal which killed the job. Thus, "-15" would indicate that the job was terminated with SIGTERM. The third column is the job's label. So when you run “launchctl list | grep something”, the columns correspond to: 1. PID (if it’s running) 2. last exit status code 3. process name ...

November 2, 2011 · 1 min · birdchan

generating excel files programmatically

I remember dealing with this problem a few years ago. At that time, I didn’t know better so ended up generating tab delimited files. A few years later, I finally gain my dignity back by generating real excel files. I found many libraries out there, below are a few: Ruby roo: http://roo.rubyforge.org/ Ruby spreadsheet: http://spreadsheet.rubyforge.org/ OpenXML: http://openxmldeveloper.org/ Apache POI (Java): http://poi.apache.org/index.html Pear Spreadsheet_Excel_Writer (PHP): http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php PHPExcel: http://phpexcel.codeplex.com/ Python Excel: http://www.python-excel.org/ I believe they will all work just fine as they all look promising. ...

November 2, 2011 · 1 min · birdchan

GROUP_CONCAT

GROUP_CONCAT is very useful when you are doing a GROUP BY, and want to capture the values from other columns. For example: SELECT country, GROUP_CONCAT(city SEPARATOR ',') AS city_arr_str FROM myTable GROUP BY country ORDER BY country Then in say PHP, you can read the city names for each returned row: foreach ($rows as $r){ $country = $r["country"]; $city_arr_str = $r["city_arr_str"]; // parse the city names $city_arr = explode(",", $city_arr_str); // do your stuff... } Everything is fine and all, until later on your database gets much bigger. ...

November 1, 2011 · 2 min · birdchan

mysql python installation error on osx

I installed MySQL-Python (version 1.2.3 at the time being) from http://sourceforge.net/projects/mysql-python/ on my osx 10.6, python version 2.6.1. Just do the usual “python setup.py build” and “python setup.py install”. However though, in the python cli, when I do “import MySQLdb”, I got some error. >>> import MySQLdb Traceback (most recent call last): File "", line 1, in File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/birdchan/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/birdchan/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so Reason: image not found >>> Obviously, the error is “Library not loaded: libmysqlclient.18.dylib”. A quick fix is to simply create a symlink. ...

June 18, 2011 · 1 min · birdchan

mod rewrite

If you want to enable wordpress’ permalinks, it’s actually quite simple. Instead of displaying: http://birdchan.com/home/?p=2034 you can have it displayed as: http://birdchan.com/home/2011/05/25/mod-rewrite/ Picking the permalink format in the wordpress admin page is quite easy. The part that is a little tricky is on the server. Here are the steps: 1. If you have done it right, the .htaccess in your wordpress directory should look something like this: RewriteEngine On RewriteBase /home/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /home/index.php [L] 2. Then check your apache conf file. I am using ubuntu apache2 so your mileage may vary. Make sure you see the following settings enabled in /etc/apache2/sites-available/default ...

May 26, 2011 · 1 min · birdchan

Perl Arrays of Arrays

Coming from the python background, this arrays of arrays in perl has given me so much pain. I decided to put down this cheat sheet here for future reference. Basic perl knowledge is assumed. # assign to our array, an array of array references @AoA = ( [ "fred", "barney" ], [ "george", "jane", "elroy" ], [ "homer", "marge", "bart" ], ); print $AoA[2][2]; # assign a reference to array of array references $ref_to_AoA = [ [ "fred", "barney", "pebbles", "bambam", "dino", ], [ "homer", "bart", "marge", "maggie", ], [ "george", "jane", "elroy", "judy", ], ]; print $ref_to_AoA->[2][2]; For @array, use parentheses, i.e. the top example. For a reference, use square brackets, i.e. the bottom example. ...

March 28, 2011 · 2 min · birdchan

MySQL Storage Engines

Whenever I need to create a mysql db, I always wonder why there are so many storage engines to choose from. According to the official mysql site ( http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html), there are currently 10 storage engines available: MyISAM InnoDB IBMDB2I MERGE MEMORY EXAMPLE FEDERATED ARCHIVE CSV BLACKHOLE Which one to choose from? I have heard that MyISAM and InnoDB are the two most popular ones. But why? I am still not sure. Maybe someday I should gather all the info and write a little comparison table. ...

March 1, 2011 · 1 min · birdchan

Perl XML modules

XML::Simple Provides an extremely simple API to read and write XML into and out of Perl native data structures. Simple for simple things, but has some gotchas, which led to the creation of a " strict mode" for the API and a guide for switching to XML::LibXML. XML::Twig Very powerful module to read and process even huge XML documents. Allows you to process the XML one “twig” (tag with all its children and content) at a time, giving you the data either as native Perl datastructure or a structure of objects. See also: xmltwig.com ...

February 17, 2011 · 3 min · birdchan

pretty_print xml

Imagine you received a huge xml file but without line breaks… It’s one long line… Then you were told to make use of one section of it… I know how to view the xml structure by using the XML Notepad, but I will have problems to copy and paste certain parts of it out. I tried to replace “>” with “>n” and it was a little better at first, but I would then have to manually insert the indentations… I was tempted to write a quick and dirty xml parser… then I was like, I don’t think I am the only one having this issue. ...

November 12, 2010 · 1 min · birdchan

jQuery vs MooTools

If you are looking into learning javascript frameworks, this will likely be a question you will ask eventually. jQuery or MooTools? They are both very well known and well developed. By chance I came across this site http://jqueryvsmootools.com/ and I was quite impressed. The author did a pretty comprehensive analysis of these two frameworks. Good stuff! Be warned though, it’s quite a long read! ;)

August 17, 2010 · 1 min · birdchan