CSS, Minification… and You.

If you run Yahoo’s YSlow or use FireBug to display page load times, one of the recommendations to increase your site’s performance is to optimize CSS and JavaScript transfers by “minifying” them.

Minification is the process of stripping out any of the unnecessaries that developers add to their files to make them easier to read and prettier to view. Things like white space (spaces), comment characters, line breaks, tabs, etc.

Example,

Original (279 bytes):

body {
font-family: helvetica, arial, sans-serif;
color: block;
line-height: 1.2em;
}

/* make divs centered */
.center {
display: block;
margin: 0 auto;
}

#box {
border: 1px solid #000;
padding: 15px;
margin-top: 5px;
}

Minified (165 bytes):

body{font-family:helvetica,arial,sans-serif;color:block;line-height:1.2em}
.center{display:block;margin:0 auto}#box{border:1px solid #000;padding:15px;
margin-top:5px}

The original CSS is now 41% smaller after minification! For low traffic websites, saving 114 bytes on a page load isn’t significant but for high volume sites, 1000 page loads (ignoring caching for the sake of argument) is about 111K of less data to be transferred. Now imagine a site like amazon.com getting millions of hits – the bandwidth savings becomes quite significant.

So, web developers. Reduce your bandwidth footprint and minify your CSS and Javascript files! You can use the free tool below to do so:

CSS/JavaScript Minify-O-Matic!

 

String Conversion Functions

I had been doing some nerdy spring-cleaning and found this while digging through the ‘junk’ folder. Maybe useful so I’m posting it here.

// Convert ASCII Text to Binary
function text2bin($string) {
    $string_array = explode("\r\n", chunk_split($string, 1));
    for ($n = 0; $n < count($string_array) - 1; $n++) {
        $newstring .= substr("0000".base_convert(ord($string_array[$n]), 10, 2), -8);
    }
    $newstring = chunk_split($newstring, 8, " ");
    return $newstring;
}

// Convert Binary to ASCII Text
function bin2text($string) {
    $string = str_replace(" ", "", $string);
    $string_array = explode("\r\n", chunk_split($string, 8));
    for ($n = 0; $n < count($string_array) - 1; $n++) {
        $newstring .= chr(base_convert($string_array[$n], 2, 10));
    }
    return $newstring;
}

// Convert ASCII Text to Hexadecimal
function ascii2hex($string) {
    return chunk_split(bin2hex($string), 2, " ");
}	

// Convert Hexadecimal to ASCII Text
function hex2ascii($string) {
    $string = str_replace(" ", "", $string);
    for ($n=0; $n < strlen($string); $n+=2) {
        $newstring .=  pack("C", hexdec(substr($string, $n, 2)));
    }
    return $newstring;
}

// Convery Binary to Hexadecimal
function binary2hex($string) {
    $string = str_replace(" ", "", $string);
    $string_array = explode("\r\n", chunk_split($string, 8));
    for ($n = 0; $n < count($string_array) - 1; $n++) {
        $newstring .= base_convert($string_array[$n], 2, 16);
    }
    $newstring = chunk_split($newstring, 2, " ");
    return $newstring;
}

// Convert Hexadecimal to Binary
function hex2binary($string) {
    $string = str_replace(" ", "", $string);
    $string_array = explode("\r\n", chunk_split($string, 2));
    for ($n = 0; $n < count($string_array) - 1; $n++) {
        $newstring .= substr("0000".base_convert($string_array[$n], 16, 2), -8);
    }
    $newstring = chunk_split($newstring, 8, " ");
    return $newstring;
}

Uninstall MySQL on OS X

If you look through the MySQL support docs, there is no clear description for uninstalling MySQL in OS X. Here’s how:

Make sure MySQL isn’t running. If you have the preference pane installed, stop the server. Otherwise you can stop it from the terminal:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

Edit /etc/hostconfig

sudo nano /etc/hostconfig
Password:

AFPSERVER=-NO-
AUTHSERVER=-NO-
TIMESYNC=-NO-
QTSSERVER=-NO-
MYSQLCOM=-YES-

Remove or comment out (# marks the line as a comment) the line that says “MYSQLCOM=-YES-”.

Remove MySQL
Still in the terminal….

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
sudo rm /etc/my.cnf

That’s it. MySQL is gone.