March 4, 2010 | Posted in PHP
Here's a class that has come in super handy for me lately. I created it for use with Kohana v3. Basically, say you have an adminstrator backend to your website and you so you have a page for blog posts and one for blog categories. Simple enough. But you wanna give your users options to filter their results so they don't have to search through hundreds or thousands of blog posts every time they wanna find a certain post. Easy enough.
But then you have the problem where the user filters the results, finds the post they want, goes to edit it, then it sends them back to the list of all posts. But whoops, they forgot they wanted to change something else in that same post. Now they have to re-filter all over again and find it. VERY ANNOYING!
So with this class you can provide it with an array of keys to keep track of over multiple page loads. It keeps every controller and actions filters seperate so that you can easily use them throughout your controllers and views. So if you want to filter by 'Author' and 'Category' then the class will look for the keys 'author' and 'category' in either $_POST or $_GET and add them to the filters. Now when the user returns to that page, all filters will still be applied. It's a big time saver!
December 3, 2009 | Posted in Javascript
The other day I needed a stopwatch to time a talk I was giving, but I had a problem. My stopwatch was ALL the way outside in the garage! Now I obviously wasn't going to get up and get it, so I figured there's gotta be something online. Sure enough, there are quite a few online stopwatches.
After using one, I started to think "Man, I should try to make this, it'll be a good exercise". So I did.
And I failed... Sort of... I've only worked with time in javascript a couple times, so after trying to figure it out for awhile, I modified some code I'd found a couple different javascript stopwatches using. Then I added some cool extra functionality and styled it all up with CSS (with CSS3 features!).
Hopefully you'll find this useful. And if not, at least it looks cool!
Javascript Stopwatch
September 12, 2009 | Posted in Code Snippets, HTML, PHP
If you're ever posting a piece of code on your blog or whatever, you've probably realized that it's a pain to have to convert any special character to its HTML entity. Why not take the pain away and let PHP handle that for you?
I'm using something similar for the comments on this blog. After I read Matthew James Taylor's post about this, I tried to come up with something using a little less code.
There really isn't a foolproof method to pull this off, and I have been told that traversing the code using the DOM would be better, but this function (as ugly as it is) actually works quite well if you have a proper HTML structure with valid code.
It checks for any <code> and <pre> tags and converts any special characters inside them to there respective HTML entity. It even accounts for nested <code> and <pre> tags, as well as any attributes you give them.
August 25, 2009 | Posted in HTML

I've always got ideas running through my head of how to code something, or how something might look. But sometimes I don't feel like going through the trouble of making a new file and filling it with a proper HTML structure just to test a piece of code out real quick. That's why I created this HTML Sandbox page to test out my code.
Features
- Choose your own
DOCTYPE
- Enable syntax highlighting code editor
- Paste in code snippets to save time
- Hide form to see just your content
July 27, 2009 | Posted in Freebies, PHP
There are already a couple PHP Flickr API classes out there, but they all seemed a bit over-complicated. Flickr has already done all the work for us, so why make it harder than it is. They've even got all the documentation, so if you ever need to know anything about it, just head over there.
Download Class
This class makes making a request to Flickr's API very simple. And it returns the results as a PHP object. It will even cache your requests so you aren't hitting Flickr as often, thus increasing the speed and performance of this script.
<?php
$api_key = 'your_flickr_api_key_here';
$flickr = new Flickr($api_key);
$params = array
(
'user_id' => 'your_flickr_user_nsid_here',
'extras' => 'url_m,url_sq',
'per_page' => 10,
);
$result = $flickr->call('people.getPublicPhotos', $params);
foreach ($result->photos->photo as $photo)
{
$p = $flickr->call('photos.getInfo', array('photo_id' => $photo->id));
echo '<h2>'.$photo->title.'</h2>';
echo '<a href="'.$photo->url_m.'"><img src="'.$photo->url_sq.'" alt="" /></a>';
echo nl2br($p->photo->description->_content);
}
// Example using chaining
$result = Flickr::factory($api_key)->call('people.getPublicPhotos', $params);
For a live demo, just check out my sidebar over on the right.