CSS: Rounded Corners in IE without any special Javascript?

This is sweet. I don’t know why it took me so long to find this. By including a custom .htc file, you are able to round corners of element in IE!

Check it out!

Download the file here:



Thursday, November 4th, 2010 CSS 2 Comments

Count UTF-8 bytes in Javascript

Recently I needed to count the number or bytes being used in a form for use in sending out a text message. Using the javascript length function simply counted the visible character length, however if I needed to count foreign text such as Chinese, it did not count the physical length or byte length correctly. I finally found the following code:

function checkLength(text) {

    var escapedStr = encodeURI(text);
    if (escapedStr.indexOf("%") != -1) {
        var count = escapedStr.split("%").length - 1;
        if (count == 0) count++; 
        var tmp = escapedStr.length - (count * 3);
        count = count + tmp;
    } else {
        count = escapedStr.length;
    return count;

Tuesday, October 5th, 2010 Javascript No Comments

Zend Studio Upgrade – Where oh where is my PHP content assist?!

Upgrading Zend Studio seems to break the Content Assist feature for PHP.

To get it working again delete the following file:


That will force Zend Studio (Eclipse) to create a new DLTK preferences file!

Now if I can only get rid of the java.lang.NullPointerException errors…

Errors occurred during the build.
Errors running builder ‘JavaScript Validator’ on project ‘PROJECT NAME’.

Thursday, September 30th, 2010 PHP 1 Comment

AJAX Call Appears to Not Fire when Firebug Enabled, works fine when Firebug Disabled

I ran into this issue while working on a project and came to a quick solution from another person that ran into the same problem.


Quick Answer:
Firebug’s console.log(), console.debug() functions break AJAX calls in Firefox when Firebug is disabled or not installed.

Tuesday, September 21st, 2010 Javascript, jQuery No Comments

How to: Set an Element’s text color based on it’s background color

Ever want to change your text color based on the value of the background it lies on? Me too.

Here is some code that allows you to get a decimal value from a hex value (#333333) and you can then set the text color to either light or dark depending on that value, check it out:

//Using jQuery to get/set the values

    var hex = $('input').css('background-color');

    if(getBrightness(hex) < 50){
    } else {


function getBrightness(hex) {
    var hex = hex.replace('#','');

    var c_r = hexDec(hex.substr(0, 2));
    var c_g = hexDec(hex.substr(2, 2));
    var c_b = hexDec(hex.substr(4, 2));

    return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;

function hexDec(hex_string){
    hex_string = (hex_string+'').replace(/[^a-f0-9]/gi, '');
    return parseInt(hex_string, 16);

Works like a charm ;)

Friday, July 16th, 2010 Javascript, jQuery No Comments

RegEx for Doctrine Connection String (DSN Format)

I needed to parse a DSN that was in the format used for Doctrine so that I could create my own PDO instances with the same connection strings found in my application.ini file. The regex is as follows:


This will parse a dsn formatted: mysql://db_username:db_password@db_host/db_name.

Came in very handy and hope it can help someone else to take a shortcut!

Wednesday, July 14th, 2010 Doctrine No Comments

Free Online jQuery Book!!

Check this out – seems to me like it could be a great extra resource:

Free Book!

Saturday, July 3rd, 2010 jQuery No Comments

Avoiding $ conflicts in jQuery

In a previous post we looked at how we could integrate the ZFDebug toolbar into the Zend Framework – what a great tool that is! However at the end of it’s call it called:


Which basically clears the “$” from being linked to the jQuery framework. When that toolbar was enabled we found that we would get javascript errors on some pages due to the scripts not recognizing the “$”.

When creating plugins, it is a better practice to wrap all your functions in the following manner to avoid this problem:

    //Your fancy plug-in code

This is creating a wrapper function for your code that passes jQuery as the parameter to be assigned to the “$”.


Saturday, July 3rd, 2010 jQuery No Comments

How to check if an attribute exists on your jQuery Selection

I recently purchased the new jQuery in Action (2nd Edition) book and I found something that I didn’t know existed (or at least that you could use ‘is’ in this way)! I recently ran into the situation where I wanted to select a group of elements let’s say they were elements, and I wanted to perform an operation on those elements that had a certain custom attribute set. Below is the code to how you could find out:

        alert("This one has that attribute!")

You of course replace attribute name with the attribute you are searching for (id,name,class,fooBizzle, etc.)


Saturday, July 3rd, 2010 jQuery No Comments

Force your users to login – Kill the Sessions!

Recently I had the need to clean out the users from our system and have them login again so that the correct user groups could be stored in the session etc. So this little snippet could come in handy again, and I thought it would be a good thing to have on here.

User session data: /var/lib/php/session

rm -f /var/lib/php/session/sess*

This will force remove all files beginning with ‘sess’.

Tuesday, June 29th, 2010 Unix/Linux No Comments
[ad code=1 align=center]