Eddie On Everything

Don't get me started

Entries for the ‘programming’ Category

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 [...]

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, [...]

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 [...]

What’s the difference between the Strong and the Bold tag in HTML? <Strong> vs. <B>?

A few versions back, Wordpress’ WYSIWYG editor started using the <strong> tag instead of the <b> tag.
And it wasn’t just Wordpress – a lot of software quietly made the shift was well.  Dreamweaver, for one.
Why the change?  What’s the difference between the two HTML tags?
As with most arguments of a religious nature, there’s both a [...]

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). [...]

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 [...]

How to Easily Install a Perl Module In Ubuntu Linux

Wow, I think I just found the best tip EVER.
I had to install a perl module (WWW::Mechanize) and was stuck in a serious dispute with CPAN over dependencies.  Wow, what a mess.
Fortunately I found this post by David Yin about how to use Debian’s totally awesome apt-get command to install the module.
Steps:
1.  Search the apt-get [...]

Make any website editable with this handy javascript snippet

I recently spotted this handy little tip at blogstorm.co.uk.
Ever wanted to edit the text of a web page to create an annotated screenshot or mockup? Simply paste this line of code into your browser’s location bar, and voila, the page text can be edited:
javascript:document.body.contentEditable=’true’; document.designMode=’on’; void 0
No, you it doesn’t enable you [...]

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 [...]

How To Block an IP Address On Linux / Apache Server

I operate a number of websites, some quite large as far as total “number of pages.” Over the years, I’ve noticed an increasing number of poorly behaved web crawler applications – some completely ignore the robots.txt file, and more and more submit dozens of requests per minute. (eek!) For a site with [...]

How to do a search and replace in multiple files using perl and linux

So you’ve got 100 files in a directory and you want to replace the string “foo” with “bar”. Stop before you waste your time opening up every single file and making the change, you can make all of the changes with a single line of perl.
perl -pi -w -e ’s/foo/bar/g’ *\.php
On his blog, [...]

Working around the 1935 error with HRESULT 0×80131532 when installing Visual Studio

Oy vey Microsoft made it a huge pain-in-the-butt to install a newer version of Visual Studio!
It took me no less than 5 hours of my day to uninstall the previous (beta) version (a long, multi-step process), do a boatload of manual cleanup, troubleshoot no fewer than 5 errors with the install of the new [...]