Tooltip

If you are looking for nice tooltip libraries, I recommend trying qTip2. It’s a jquery plugin. And it’s got most of the pop-up tooltip features you can imagine. I personally like this feature, that you can assign different behaviors (by different actions) to the same element. See below: // Create our first tooltip $('.selector').qtip({ content: 'Mouse entered', show: { event: 'mouseenter', solo: true // Only show one tooltip at a time } }) // Remove the previous tooltips data .removeData('qtip') // Create our second tooltip .qtip({ content: 'Click', show: { event: 'click', solo: true // Only show one tooltip at a time } }); With the above code, you can have a specified mouseover preview tooltip, and a detailed view upon a mouse click. Very handy! ...

February 1, 2012 · 1 min · birdchan

rounded corners

An ordinary div Row 1 A div with rounded corners Row 2 The second div looks so much more fun and professional at the same time! As it turns out, all you need is one or two extra lines in order to add these rounded corners. See code below: #my_div { border-radius: 15px; } If you want more fine-tuning, try the following. The first parameter is the horizontal radius of the rounded corner, the second the vertical. ...

January 31, 2012 · 1 min · birdchan

PHP array delete an item

Say, you have an array like the following, how to delete “three”? $arr = array("one", "two", "three", "four", "five"); PHP has this function called unset, with which you can do: unset($arr[2]); But… yea… there is no direct way to do something like array_delete_value(“three”)… I don’t understand why there is no easy way to do deletion by value… You will need to get the array index first, whenever you want to delete by value. We will use array_search to get the index or key. ...

January 26, 2012 · 1 min · birdchan

PHP encode JS decode

Very often I need to encode some string in PHP, then pass that to javascript. For example, say I am using PHP to generate some javascript functions. See below: $s = "some text from somewhere"; $js_code = " function do_something(some_text){ alert(some_text); } do_something('$s'); "; The above javascript code would work fine until one day you have some symbols in $s, for example the single quote. (There may be more troublemakers, but at least this is a common one). ...

January 19, 2012 · 1 min · birdchan

jquery datepicker date format

If you are using the jquery datepicker and have been displaying the date in the usual mysql date format, you probably will find it annoying that the date picker gives you the slash date format back. Here is how to keep the mysql date dash format all throughout. var queryDate = '2012-01-10', dateParts = queryDate.match(/(d+)/g) realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]); // months are 0-based! $('#datePicker').datepicker({ dateFormat: 'yy-mm-dd' }); // format to show $('#datePicker').datepicker('setDate', realDate); The code above will translate the mysql date to do the initial setup, then use the dash format for the text field. ...

January 11, 2012 · 1 min · birdchan

newline character in title

To create a line break in the title attribute, use " “. Hover over me! Hover over me!

December 7, 2011 · 1 min · birdchan

PHP command line memory limit error

Very often, when data size gets bigger and bigger, some scripts will break due to default memory limit. I got the following error today. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /someDir/myScript.php on line 15 Segmentation fault: 11 I checked my php help. I am using version 5.3.6. $ php -h Usage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...] php [options] -a -a Run as interactive shell -c | Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f Parse and execute . -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP after processing all input lines -H Hide any passed arguments from external tools. -s Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z Load Zend extension . args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf Show information about function . --rc Show information about class . --re Show information about extension . --ri Show configuration for extension . Looks like -d with do it. So I ran the following: php -d memory_limit=512M myScript.php It worked fine. If you can afford to change your php.ini file, use - -ini to see where your php.ini file is, then make your changes accordingly. You can also use -n to ignore your php.ini file, but then you will be using default parameters which may be even harder to debug. ...

November 11, 2011 · 2 min · birdchan

Validate line by line

Here is a good compilation of codes doing string format validation in C#, VB.NET, Java, Javascript, PHP, Perl, Python, and Ruby. It’s a good reference page. http://answers.oreilly.com/topic/224-how-to-search-line-by-line-with-a-regular-expression/

November 11, 2011 · 1 min · birdchan

Stop UTF 8 with javascript

Below is how you can detect non-ascii characters with javascript. s = $("#something").val(); for (var i=0; n = 128) { alert('Invalid character '' + String.fromCharCode(c) + '''); return false; // or throw an error } } Of course if you have to take in non-ascii values, then be prepared to set up your environments first. The links below will help. http://us.php.net/manual/en/function.base64-encode.php http://pureform.wordpress.com/2008/03/23/make-your-website-completely-utf-8-friendly/

November 9, 2011 · 1 min · birdchan

max_allowed_packet error during mysqldump

Got a “max_allowed_packet” error during mysqldump. This happened after I added a longblob to one of my tables. Below is the error: mysqldump --routines --user=root -p localDB > backup.mysql.txt mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `table2` at row: 86 It turns out max_allowed_packet is set to something less than whatever is in my row 86. Longblob can go up to 4Gb so I will need to override the max_allowed_packet value. I found the following way the easiest to re-enable the dump. ...

November 8, 2011 · 1 min · birdchan