Eddie On Everything

Don't get me started

Entries Tagged ‘code’

mod_rewrite in .htaccess to Force www in URL Not Working

Setting up a new site today, I ran into a problem with a .htaccess not working.
It was a pretty simple solution, and was the result of a minor oversight my part.
Still, it took me about 10 minutes to realize the mistake I’d made.
I just thought I’d post here in case someone else makes the same [...]

MySQL Performance Tip: ON DUPLICATE KEY is faster than INSERT IGNORE, but failing with a duplicate key error is a lot faster

I’m working on merging a couple of pretty big MySQL databases.
Each database consists of just three tables, but each of those tables has at least 9 million rows.
Because I need to maintain and update a number of data associations, it was necessary to write a custom script to perform the merge. (I chose to [...]

How To Use Global Variables From Another File In A Perl Module or Package

I’ve been doing a lot of Perl development for my latest project, and I wanted to use a single config file for many scripts.
Using a single config file in a basic Perl script is pretty straightforward – you simply use a require statement to read the external file, and the variables contained within are automatically [...]

How to Block a Quote

Blockquotes are a great way to reference others’ material.
A blockquote lets your reader know that you are quoting another source, and it pays proper attribution to your quoted source.
HTML supports the <blockquote> tag, which does exactly what one would suspect.
To block a quote in HTML, simply use this tag.
Example:

<blockquote> This is quoted text </blockquote>

The above [...]

Getting PHP’s print_r Function To Return A String

PHP’s print_r function is invaluable. It prints a human-readable string representation of a variable.
It’s one of the most useful debugging features I’ve seen in any language.
I like it so much that I’ve actually written print_r mimic functions for other languages.
By default, print_r literally prints a variable to the screen. Sometimes it’s useful to [...]

How To Set a Class Name using Javascript in IE and Other Browsers

I was working a client project today had to use a little javascript.
As anyone who’s worked with Javascript knows, Microsoft’s Internet Explorer can be a real pain the butt.
Things that work in Chrome, Firefox, and Safari don’t always work in IE – so you always have to come up with workarounds to make IE, well, [...]

Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further

I use the Google Syntax Highlighter for Wordpress plugin to display the code I share on this page all pretty-like.
The problem is, the thing isn’t very robust – it causes every single page on your blog to load up about 10 separate javascript files, regardless of whether the plugin is actually doing anything on that [...]

Customizing the Calibre Associated Press (AP) Recipe

I’ve been using Calibre to manage my eBook library and download daily news to my Kindle.   It’s great.  If you have a Kindle or other eBook reader, I recommend that you check it out.
Calibre comes stocked with a number of “recipes” for popular news sites.  One of those is the Associated Press (AP).  Since [...]

Calibre Recipe for Minneapolis Star Tribune (StarTribune.com)

I love my Kindle. And I love the Calibre eBook management software. If you haven’t had a chance to check out Calibre, you’re missing out – it’s kinda like an iTunes for your eBook collection. In addition to storing, converting, updating, and categorizing your eBook collection, the software will also download news [...]

Rotating Backup Directories using cp -al (hardlinks) to Save Disk Space

The copy command “cp -al” found on all versions of Unix/Linux creates what’s called a “hard link” to a file. The nice thing about this command is that it doesn’t create an actual copy of the file on disk – instead, it creates a “link” or pointer to the file data on the disk. [...]

Using rsync & ssh to Backup Files Between Linux Machines (Perl)

This script performs a network backup using unix’s rsync command over ssh. It performs an incremental backup, which means that it only updates new files and files that have changed since the last backup, thus minimizing network traffic.
This script runs on the source machine (SOURCE) and connects to the backup machine (BACKUP). [...]

“Argument list too long” from rm command. A Perl Script to Get Around the Problem

You’ve seen the problem – many Unix commands don’t like very long argument lists.  For instance, my Linux machine complains when I try to “rm” 10,000 files at once:
[eddie@yoakam test]$ rm *
-bash: /bin/rm: Argument list too long
Here’s a simple script that will delete all of the files in a given directory, even if the argument [...]

Calculate the Days Since a Given Date (Javascript)

I recently needed to calculate the number of days that had elapsed since a given date. Not happy with any of the code snippets I found on the internet, I wrote my own. A demo is below, along with the the javascript code. Note that the code uses a bit of dynamic [...]

PHP Programming: U.S. State list functions / State abbreviation to State name function

Here are a few PHP functions that I find useful for United States related things. Nothing brilliant or groundbreaking – just something to save you some typing.
1. A PHP function for printing a state select box
2. A PHP function that returns the full state name when passed the abbreviation
3. A PHP snippet for printing [...]