Archive for the ‘Code Snippets’ Category

How to Time Delay Posts in Wordpress

Saturday, March 8th, 2008

One reason I’ve heard people say that they prefer a full-blown CMS to Wordpress is that Wordpress doesn’t allow time delayed posting. I was about to figure out a way to mod Wordpress to make this possible – until I realized that there is some decent built-in functionality for time delaying.

You can easily delay the release of your posts into the main indexes (front page, archives, “Recent Posts” list, etc). With a little bit of code, you can also restrict people from viewing the page before its appointed “Published” date.
(more…)

How to Work With Directories in PHP

Thursday, March 6th, 2008

PHP offers a number of different functions to work with the local directory structure. There are at least three fairly simple ways to create and output a list of files in a directory.

Like the file functions, each method is slightly different. Knowing how each operates will help you choose which function to use when you want to work with directories in your PHP script.
(more…)

Use Javascript to Parse a Query String

Tuesday, March 4th, 2008

Most server-side scripting languages, like PHP, come with built-in functionality for reading query strings. Javascript doesn’t have any kind of standard counterpart, but that doesn’t mean you can’t use query strings in Javascript.

With some String functions, you can create your own function to parse a query string attached to the request url and store it in an associative array – just like PHP would for you.
(more…)

How to Enable Client-Side Caching of Resized Images

Saturday, March 1st, 2008

About a month ago, I wrote a tutorial on dynamically resizing images in PHP. Despite my best intentions, I never found the time to go back and rewrite the script to include server-side caching of the images created.

However, one reader asked if it was possible to enable a client-side cache of a dynamically resized image. It surely is, and it’s very simple.
(more…)

How to Randomize AdSense Ads with Javascript

Friday, February 29th, 2008

I came across this problem on the forums today. How can you randomize which Ad Sense ad to show using Javascript?

The solution, it turns out, is very simple.
(more…)

How to Generate a List of Possible Combinations

Tuesday, February 26th, 2008

In statistics and probability, the combination is something special. There are tons of problems that revolve around how many combinations you can get choosing a certain number of random items from a set.

We’ve developed mathematical formulas to help us determine the number of possible combinations – and therefore the possibility of getting any single combination – but how can we generate a list of the actual combinations?
(more…)

Javascript Function: Random Number Generator

Sunday, February 24th, 2008

Yesterday, I wrote a short article on generating random numbers in Javascript. The Javascript random number generator is similar to C/++ – it gives you a random number from 0 to 1 and you need to make it useful.

At the suggestion of a reader (thanks Justin), I decided to go ahead and turn the general formula for this into a short helper function to generate a random number.
(more…)

JS Game: Making a Real Game Board from a Concept

Wednesday, February 20th, 2008

In a recent post, I sketched out how to use Javascript to build a gameboard for a browser-based game – specifically Tic Tac Toe. After a little tweaking, I’ve worked this into a functioning Tic Tac Toe board.

In this post, we’ll explore the code used to set up this board. Once that’s done, the next step will be to create a php script to evaluate some of the game’s logic.
(more…)

JS Game: Creating a Simple Game Board in Javascript

Tuesday, February 19th, 2008

A thorough knowledge of Javascript can give you tremendous control over what happens on a website. Combined with PHP through an AJAX request, you can make some pretty nifty browser-based games.

This tutorial will focus on the first part of making a basic board game – creating a board. The end result will be a three by three game board suitable for use in developing a tic-tac-toe game.
(more…)

How to Only Show the Digg Badge for Popular Posts

Monday, February 18th, 2008

Digg can be a great source of traffic and recognition for tech related blogs. Some people take it to the extreme though, and show the “Digg This” badge on every article they write.

As others have pointed out, this can be counter-productive. People don’t like to read articles that have just one Digg – they seem unpopular.

So here’s a solution: use the Conditional “Digg This” Wordpress Plugin to only show the Digg Badge for articles that have a certain number of Diggs.
(more…)