How to use JSON in PHP 4 or PHP 5.1.x

PostMar 16th, 2009 | Comments (0)
Here's an easy forward-compatible way to use JSON (json_encode() and json_decode()) in versions of PHP earlier than 5.2.

Download the Services_JSON PEAR package

And then add the following to your custom functions:

if (!function_exists('json_decode')) {
    function json_decode($content, $assoc=false) {
        require_once 'classes/JSON.php';
        if ($assoc) {
            $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        }
        else {
            $json = new Services_JSON;
        }
        return $json->decode($content);
    }
}

if (!function_exists('json_encode')) {
    function json_encode($content) {
        require_once 'classes/JSON.php';
        $json = new Services_JSON;
        return $json->encode($content);
    }
}


That's it! Your code will continue to work, even when you eventually upgrade to PHP 5.2.

PHP/MySQL: Setting a field to NULL if a form field is left blank

PostFeb 11th, 2009 | Comments (0)
For those of you working with PHP and MySQL who want to set a field in MySQL to NULL if the corresponding field in an HTML form is left blank, here is a slick trick:

UPDATE table_name SET date_field=IF('$date_value'='',NULL,'$date_value')

For text fields this isn't a huge deal, but for any of the formatted field types like "date" or "decimal," setting them equal to an empty string (i.e. '') results in them having values like 0000-00-00 and 0.00. So this little "if" shorthand in MySQL is a great solution.

Add a pause or delay in jQuery

PostFeb 6th, 2009 | Comments (4)
Karl Swedberg over at Learning jQuery has a great trick for pausing during a jQuery effect chain.

Here's an example that fades an object in, pauses for 3 seconds, and then fades the object out.

$("#some_object").fadeIn().animate({ opacity: 1.0 },3000).fadeOut();

Notice the animate() in there. All it does is change the opacity of an object from 1.0 to 1.0 (i.e. do nothing) over the span of 3 seconds. Brilliant.

Testimonial Generator

PostDec 31st, 2008 | Comments (0)
For web designers out there who need a few quick and dirty testimonials to use as place-holders, check out the Testimonial Generator.

Just don't be an asshat and try and pass them off as real testimonials by posting them as comments on your own website:

(I refuse to link to these sites and give them even a miniscule Google Rank boost.)

* http://www.surveyspaidfor.com/surveys-paid-online/get-paid-for-taking-online-surveys-150-per-hour

* http://www.beststeps2freedom.com/

Iconic Concepts & Oshkosh Symphony Orchestra

PostOct 7th, 2008 | Comments (0)
I just added a bunch of screen shots from my latest couple client projects:

Oshkosh Symphony Orchestra




Iconic Concepts


Firefox not loading PHP stylesheet

PostJun 19th, 2008 | Comments (3)
Quick tip:

If you're going to create a dynamic CSS stylesheet using PHP (e.g. style.php instead of style.css), make sure you spit out a "content-type" header at the top of the stylesheet or Firefox will choke and not load it.

Put this at the top of the page:

<?php header("Content-type: text/css"); ?>

Goody Green Bags is live

PostJun 6th, 2008 | Comments (3)
I just added a couple screen shots of my latest client project for Goody Green Bag.



Check 'em out...

Nuda Tees is having a megamuthafunkin' blowout sale. All t-shirts are only $8!

PostMar 31st, 2008 | Comments (0)
Nuda Tees is having another Megamuthafunkin' sale this week!

All t-shirts are only $8!

There are also four new designs:








How to stop iChat from being a RAM hog

PostMar 20th, 2008 | Comments (2)
Is iChat hogging a ton of RAM for you? The "File Transfers" window might be the cause.

(This post refers to iChat v4.0. I'm not sure if the same problem exists for previous versions.)

I get a lot of big files sent to me via IM - Photoshop files, Illustrator files, etc. I leave the File Transfers window open all the time, and I almost never clear it. It turns out, that's not a very good idea.

Each file transfer that you receive results in iChat immediately grabbing more RAM. And if you don't clear your File Transfers list, each file will continue to hog that RAM until you clear the list - even if you quit iChat and relaunch it. I ran a little test to prove it.

I sent myself 8 files totalling 2.4 megs:



In Activity Monitor, iChat was using 119 megs of RAM:



I then clicked the "Clear" button in iChat's File Transfers window:



iChat's RAM usage instantly dropped to 98 megs:



That means that only 2.4 megs of file transfers resulted in iChat grabbing 21 megs of RAM. You can imagine what leaving the File Transfers window uncleared for weeks would do. iChat was routinely hogging 600+ megs of RAM for me, which was really slowing my computer down.

So make sure you clear your File Transfers window often!

How to regain access to Webmin with IP Access Control enabled

PostDec 31st, 2007 | Comments (0)
For anyone who is as smart (read: really dumb) as me and enabled Webmin's IP Access Control feature but forgot to add their server's IP address as an allowed IP address, here is how to regain access to Webmin after your local IP address changes and Webmin locks you out.

Edit /etc/webmin/miniserv.conf and change the "allow" IP address to your new IP address.

Now is also the perfect time to add your server's IP address to the whitelist, so that you can at least access Webmin locally from the server via lynx if you need to in the future.

To add multiple IP addresses, just put a space in between them.

Example:

allow=12.34.56.78 98.76.54.32
Visit the archives to see older posts