Implement Transparent File Caching for functions in PHP

Sometimes a script needs to call a function that either uses a large amount of system resources, or that performs external calls to servers or APIs that place limits on requests. Often, however, the data returned by these functions isn’t highly volatile, and can be expected to remain the same for subsequent calls.

In these cases, it is necessary to implement a form of cache, to store the results of running the function once, and use the same results on subsequent calls (clearing the cache regularly, to prevent buildup).

Caching to disk is fairly easy to implement in PHP, but it is nice to have a prebuilt, general purpose solution that can be dropped in to any project.
read more »

ADVERTISEMENT:

Sort by Last Name First in PHP

This is less of a post, and more of a useful snippet. I’ve seen many posts online about sorting an array of names by surname, and they’ve all failed to be complete. Here is my addition to the pile. Keep in mind that it has known issues with compound last names that contain a space, like “Von Zinger”, “Mac Innis”, or “Di Vece”. However, it is a more robust solution than many others online today.

ADVERTISEMENT:

Create “Archive-Only” Custom Post Types in WordPress, and make “team” pages simple

One of the more complicated things to handle in wordpress is creating a “team” page that is attractive and easy to maintain.  Many designers use pre-packaged plugins that remove a level of control, or create these pages as flat pages with complicated custom layouts (sometimes with the assistance of Visual Composer or another complicated shortcode library).

The same issue tends to carry over to other ‘aggregate’ pages like “board of directors” or “testimonials”.  However, it’s actually fairly simple to implement these pages as a Custom Post Type, giving content-editors a simple post interface to add and delete team members, and making front-end layout a simple job for a custom template and some css.
read more »

ADVERTISEMENT:

jQuery.smartCrop – Enabling Truly Responsive, Client-Side Image Processing (Proof of Concept)

Demo: http://gschoppe.com/projects/jQuery.smartCrop/
GitHub: http://github.com/gschoppe/jQuery.smartCrop

Let’s face it, responsive images are a real pain in the neck.

As a web designer, I want complete control over picture dimensions at any size; but i am constantly compromising designs to deal with the constraints of user-provided images.  These constraints are well known to any designer: read more »

ADVERTISEMENT:

Picking Winners for Hashtag Contests

My office wanted to hold a drawing a few weeks ago, where people would share a photo with the company name as a hashtag, and one random poster would win a gift card.  These are great contests to boost a business’s social standing, but with so many hashtag friendly social networks, it’s hard to choose a winner in a fair way.

We found a great hashtag aggregator, called Hashtagr.co, that displays a pinterest-like feed of hashtagged posts across multiple social networks.  It made for a great leaderboard, and got all the data in one place, but it still didn’t solve the picking problem… So I wrote a quick script, and packaged it up as a bookmarklet.  A bookmarklet is a link that can be added to your bookmarks, that, when clicked, will run some custom javascript, rather than changing pages.

My bookmarklet for Hashtagr selects a random post in the list, scrolls the browser window to it, highlights it with a red border on the bottom, and opens an alert box that declares that poster as the winner.  To use the bookmarklet yourself, simply drag the bookmarklet below to your bookmarks, go to a hashtag feed on hashtagr.co, and click the bookmarked link.

Hashtaggr – Pick Winner

ADVERTISEMENT: