Javascript Circular Selection Knob (IE6 Compatible)

August 23rd, 2010 by Cory No comments »
Polished Knob Logo

An inherent problem with the internet is that the UI elements are disconnected from the real world. People in the world are accustomed to things like switches, knobs and the like.

One thing that has been missing (at least I couldn’t find anything?) from HTML UI elements is the knob. An element that you can spin around to assign a value to some property. The functionality of a knob is basically the same as a slider — only the shape is different.

Up until now, you only had horizontal and vertical sliders to choose from. Boring. The look of them is generally ugly and there is nothing special about the design or intuitivityness.

» Read more: Javascript Circular Selection Knob (IE6 Compatible)

Ajax spinner… I hate you.

May 22nd, 2010 by Cory 2 comments »

It’s time to kill the ajax spinner. It had a good run, but now it’s time to retire it to gif heaven where it belongs, right next to the animated “under construction” and “email me!” gifs of 1994.

» Read more: Ajax spinner… I hate you.

Backup/Migrate MySQL Databases to New Server (Windows)

March 27th, 2010 by Cory No comments »

Bird migration image from: http://audubonoffloridanews.org/?p=3314

I searched far and wide and could not find a way to easily migrate MySQL data from one server to another. I remember a few years back that MySQL released a migration assistant that did the job pretty well, but that software seems have reached EOL. I had to move files on my local (windows) dev server to a new desktop that I purchased and decided to write a couple bat files that automate the process of exporting and importing the databases. Download the scripts now.

It seems that MySQL has replaced the former helpful software with MySQL Workbench — which is pretty cool, but unfortunately it doesn’t include any help for migration.

A future release of MySQL Workbench (post 5.2) will add a migration plugin, providing features comparable to the MySQL Migration Toolkit component of the MySQL GUI Tools Bundle. We will also be adding many other enhancements and new features.

Where does that leave us? Mysqldump.

I modified a MySQL backup shell script from Sonia Hamilton, and these scripts could both be modified to work with nix, but they are mainly for Windows. Read on for how to migrate your windows MySQL server.
» Read more: Backup/Migrate MySQL Databases to New Server (Windows)

Re-introducing Eventageous for PHP

March 3rd, 2010 by Cory No comments »

This is an old project of mine but I decided to remake it bigger, stronger and faster. And it seems, I never actually released it before when I thought I did. I’ve completely rewritten the code and put it up on google code.

So what is it? It is basically a glorified event logger for PHP. Information can be logged to files (and auto-rotated), output to screen, extended with custom events, and even use it with your PHP ajax.

Click through for details.

» Read more: Re-introducing Eventageous for PHP

SimpleTabs: A pure javascript easy tab implementation

February 18th, 2010 by Cory No comments »

I’ve written — and lost — at least two reusable tab components in Javascript before. So I’m posting this one here as a reminder to myself to never, ever, ever write one of these again.

There are tons of HTML tabbing classes/functions/extensions/plugins/blahblah out there but almost every one I’ve ever found has been a plugin for [insert Javascript library here]. I don’t see a point in using [insert Javascript library here] just to have 3 tabs on a page, do you?

So here it is, a simple tab class with callbacks that could be extended to do all your tabbing needs at 1.7kb min’d. You could probably get that down to 1k if you really wanted to and didn’t need callbacks. What’s an extra 1.7kb in your Javascript file? You are including a single JS file instead of ten 5kb files, aren’t you?

Source/examples after the break.

» Read more: SimpleTabs: A pure javascript easy tab implementation

Facelift mentioned in print

February 1st, 2010 by Cory 1 comment »

FLIR has recently been mentioned in a book by author Allan Walker entitled Joomla 1.5: Multimedia. This is a first for the project as far as I know, so I thought it was worth noting. Cool stuff! In other news, I discovered that Rackspace’s cloud hosting site has a nice use of Facelift. It looks so nice that I almost paid for some service right there!

About Joomla 1.5: Multimedia

Joomla! is a content management system designed to organize and deliver content within a web site environment. Multimedia provides us with stunning interactive user experiences and wonderful design options, but it requires discipline and knowledge to utilize it effectively so that we do not alienate our audiences. If you want to display more than just text on your Joomla! pages, this book has been designed for you and is a must-read. It takes you beyond the basics of Joomla! and helps to take full advantage this powerful CMS structure to deliver media-rich web content to your site users.

Click through for the relevant page.

» Read more: Facelift mentioned in print

Greasemonkey Script: Remove Wikipedias liquid layout for article content to ease reading

January 21st, 2010 by Cory No comments »

I’ve recently upgraded to a new large screen monitor. It’s great for many things–but browsing the internet is not one of them. Fixed width web pages look awkward in the middle of my browser with massive amounts of space on either side and liquid layouts cause LONGGGGGGG lines of text, which makes reading much more difficult. I forget the exact study, but I remember reading a study that anything more than 60 words per line and your reader will lose their much more often.

Wikipedia uses a liquid layout for their articles, and this makes reading articles on hard-to-understand topics that much more difficult to comprehend.

This Greasemonkey script for Firefox will adjust the width of the content to make it easier to digest. Nothing fancy here. Just few changes to the styles–but helpful nonetheless!

Click through to get the script.

» Read more: Greasemonkey Script: Remove Wikipedias liquid layout for article content to ease reading

Separate RGB Channels from an Image in PHP

January 20th, 2010 by Cory No comments »

Divide an conquer! That’s what I always say. But how do you go about dividing an image up into it’s separate channels–like Photoshop does it?

There are actually two ways to go about doing it. First, is displaying the actual amount of red, green, or blue that is contained in each pixel which results in images that are made up entirely of shades of the color channel that you are viewing. The second is to to simply display the information in an easily understood visual representation by using shades of grey. Both are detailed below.
» Read more: Separate RGB Channels from an Image in PHP

pr() a print_r enhancement for your HTML web page

January 18th, 2010 by Cory No comments »
function pr ($mixed)
{
	echo '<pre>' . htmlentities( utf8_encode( print_r( $mixed, true ) ), ENT_QUOTES, 'utf-8' ) . '</pre>' ;
}

When writing PHP, I often find that I need quick debug access to an Object or Array to see what it contains. PHP provides print_r, which works great–except that the data appears without all the tabbing in regular ol’ HTML. This is annoying for large Arrays or complex Objects.

That is why I created the pr() function. It basically just wraps the output of print_r in pre tags and then your formatting is back.

Depending on the encoding of the data you are passing to and getting from print_r, you may run across problems when combining print_r and htmlentities (with utf-8). If the encodings don’t match, it may return nothing at all! This could either mean that the variable is some kind of empty, or it could mean that htmlentities didn’t like the encoding that was returned by print_r, and crapped all over itself.

So, you first have to convert the data returned by print_r to utf8 (or whatever the encoding of your web page is) before passing it along to htmlentities. Since I try to keep every web page I work on in utf8, I keep this function set up to compliment that.

As long as you have a working utf8_encode, this function should always output pretty, utf-8 encoded data in HTML. If you need to convert to some other encoding beside utf8, you can use mb_convert_encoding.

More examples of image manipulation with PHP

January 14th, 2010 by Cory No comments »

All of these examples use the PHP simple image manipulation class that I created.

Every now and then I write a batch image converter snippet that others might find useful. I figure I’ll post them here for my benefit and yours. These snippets will also serve as a way to better understand the class. As I come up with these in life, I’ll update this post.

All of these examples assume that you’ve already included the class in your file.

» Read more: More examples of image manipulation with PHP

Simple Image Manipulation in PHP (Rotate, Resize, Crop, Flip and Mirror, Thumbnails square and regular)

December 31st, 2009 by Cory 30 comments »

UPDATE: I’ve added support for PNG alpha transparency which makes this class significantly more useful. Changelog in the class code below.

I keep misplacing this class so I figured I’d post it here so that I know where it is.

I wrote/assembled this class because I wasn’t happy with any of the image manipulation libraries out there. They are either way too complex with a steep learning curve or didn’t work all that great. (I didn’t see any reason to load up a class with 3,000 lines of code just to resize or rotate an image.)

So here it is, a simple class that allows you to open an image, perform common operations, and save. There are no bells and whistles or anything exciting here. Just a collection of commonly used image manipulation functions: Rotate, Flip, Resize, Thumbnail (square and regular), and Crop.

A lot of the class code is original but some of it has been gathered over my life as a programmer from long lost sources. If you recognize your work, leave a comment and I’d be happy to cite you!

» Read more: Simple Image Manipulation in PHP (Rotate, Resize, Crop, Flip and Mirror, Thumbnails square and regular)

Firefox and broken images: Help get the behavior changed

December 30th, 2009 by Cory No comments »

Whenever I am working on a PHP script that generates an image, I am always frustrated by the standard Firefox broken image error.  The problem is that I have PHP output error messages to the screen while developing for the sake of simplicity.  These error messages mix with the binary data of the image, and it causes the image to break.  The end result is no image, and no error messages.

But what if I want to read those helpful error messages?

» Read more: Firefox and broken images: Help get the behavior changed

AdCenter SEMs lives just got easier (Greasemonkey script inside)

December 18th, 2009 by Cory No comments »

If you are a search engine marketer that has used Microsoft’s AdCenter, you probably have found it a bit annoying that when creating text ads, it doesn’t tell you how many characters you have left.

This means that the genius PPC ad-copy that you just wrote will only be rejected when you go to save because it is too long.

This Greasemonkey script detects when the new text ad dialog is visible, and will update the remaining characters that you have left to use as you type.  Something that Microsoft should have done…. pay me MS, you lazy bastards.

This isn’t the only thing I find annoying about Microsoft AdCenter, but all the Greasemonkey scripts in the world won’t fix it. Click through for the script.
» Read more: AdCenter SEMs lives just got easier (Greasemonkey script inside)

Stop the toolbar and overlay madness!

December 11th, 2009 by Cory 5 comments »

If you are thinking about putting a “toolbar” on your blog, please reconsider right now.

In recent months, I’ve noticed a resurgence of the website toolbar.  What is a website toolbar?  Usually, it takes the form of a small bar that is on your screen at all times, and it provides little links to supposedly helpful tasks for the visitors of the website.  It seems that this company is responsible for most of the madness through their freely available script.

In the toolbar pictured above, you can search the website, translate it, get the sites latest news, or share the page with the community of your choice. Helpful right?  Wrong.

» Read more: Stop the toolbar and overlay madness!

Piracy and the Myth of Lost Profits

December 7th, 2009 by Cory 4 comments »

As some of you may know, I’ve made the horrible mistake of going back to school.  These days, I spend my free time doing homework instead of working on things that really matter to me, which I treasure and it is of the utmost importance to me.  I’m happy to be doing all this extra work, because it earns me a magical sheet of paper that won’t be worth the paper it’s printed on because of the rapidly evolving field of computers a BS in IT, which I will proudly display on my wall.

The good thing about this whole school thing is that I’m getting learned on dem books, and it has also given me the opportunity to complete a previous thought that I called my downloading is theft rant.  I’ve taken that idea there, twisted it, rubbed some spit on it, and turned it into some kind of research paper (with the help of my girlfriend who was able to remove all my sarcastic remarks from the final draft). After spending a bunch of hours on it, I figured I might as well put it up here for anyone who is interested and to prove that I can in fact write a complete sentence.

In case you were wondering… here is an example of the sheer brilliance that my girlfriend had to edit out:

So who is doing all this pirating?  Terrorists.  That’s according to a study by The RAND Corporation that was “made possible by a grant from the Motion Picture Association.”  That’s right; those vile individuals that are hell-bent on the destruction of America have lately taken to a more subtle approach to the complete and utter obliteration of the American way of life: pirating Black Hawk Down on DVD.  So, Osama Bin Laden is selling DVDs in the mountains of Pakistan?  Not exactly.  According to the study, there aren’t really any clear connections to terrorism.  It can be said that movie piracy is connected to terrorism in the same way that Iraq was connected to al Qaeda and weapons of mass destruction – not at all.

So without further ado, break out your red pens and put away your fact checker…

Piracy and the Myth of Lost Profits, starring Johnny Depp.

» Read more: Piracy and the Myth of Lost Profits

Paypal support: down, Skype support: down, Ebay support: down

December 4th, 2009 by Cory 4 comments »

ebayfail

You can’t make this stuff up.

» Read more: Paypal support: down, Skype support: down, Ebay support: down

Another look at Repeatable Random

December 3rd, 2009 by Cory 1 comment »

My last post was about a similar subject only with an emphasis on generating an evenly distributed set of random numbers that existed between a minimum and maximum value.

I found this post from Jackson Dunstan about a repeatable random class written in AS3.  In that post, he mentioned that it could easily be ported to Javascript or other languages — and he was right.  Here is that class written in Javascript and as far as I can tell, it does indeed produce a repeatable random set of numbers.

His class works by taking an initial seed number, performs a simple mathematical calculation, and then returns it before making it the new seed number, and starting the cycle over. The result is a set of random numbers that are repeated based on the starting seed number.

A technique such as this is mainly used for video games but it could also be useful in web development to randomly place objects on a page. This code doesn’t do much of anything by itself but is a good jumping off point. See a working example at the bottom of this page.

» Read more: Another look at Repeatable Random

Repeatable Random: An even distribution of pseudo-randomness

December 2nd, 2009 by Cory 2 comments »

duck_goose_medium

Does the concept of true randomness really exist?  To tackle that question we must first ask ourselves, does free will exist, or are all our lives pre-determined based on some cosmic event that happened billions of years ago?  That is a question I’m not going to even try to answer in this post. Instead, I will provide you with a simple PHP function that can provide you with a repeatable random number generator.

OK, maybe “random number generator” isn’t an accurate name for it. Perhaps hasher-to-evenly-distributed-values generator would be a much better title since that is exactly what it does.

Why would you need such a thing?

Random numbers are great. They allow you to give your web applications some personality. Let’s say you only want to display a message on a web page ~10% of the time. Random numbers allow you to do this. You would simply do something like: if ( rand ( 1, 10 ) == 5 ) echo ‘This is my message. I display about 10% of the time!’;

That’s all well and good, but what if I want to display a random message to my visitors AND make sure they see the exact same one each time? Not possible with plain ol’ random.

However, it is possible with this very simple repeatable_random PHP function.

» Read more: Repeatable Random: An even distribution of pseudo-randomness

Serious Facelift vulnerability discovered – Details and fix included

December 1st, 2009 by Cory 1 comment »

Update immediately! A serious directory traversal vulnerability has been discovered that affects all versions of Facelift.  It could allow an attacker to retrieve plaintext versions of any file that PHP can read. This could include your WordPress database settings, for example. It is bad.

A patched version has already been made available at the facelift homepage.  If you downloaded facelift in the last couple days and the zip file was either *2.0b3-B or 1.2.2 then you have the patched version. If not you should either update your Facelift installation or remove generate.php immediately.

To update your Facelift installation, please download an updated version. Overwrite the generate.php in your install with the patched version from the download. You can leave your config-flir.php and all other files alone. The problem only affects generate.php.

Many Facelift plugins are available for Drupal, Joomla, WordPress  etc.  I’ve already contacted as many of these authors as I could and most have already issued fixes.

The problem exists in generate.php and is due to a variable not being properly sanitized. Big thanks goes out of Johannes Herbst for discovering the problem.

If you are using one of the third-party plugins, please update your plugin immediately.

Manually Fix:

The problem can be fixed by changing one line in generate.php:

Facelift v1.2:

$FLIR['output']        = isset($FStyle['output']) ? ($FStyle['output']=='jpeg'?'jpg':$FStyle['output']) : 'auto';

Change To

switch ( $FStyle['output'] ) {
	default: 	$FLIR['output'] = 'auto'; 	break;
	case 'png': $FLIR['output'] = 'png'; 	break;
	case 'gif': $FLIR['output'] = 'gif'; 	break;
}

Facelift v2.0b3

$FLIR['output']        		= isset($FStyle['output']) ? $FStyle['output'] : 'png';

Change To

switch ( $FStyle['output'] ) {
	default: 	$FLIR['output'] = 'auto'; 	break;
	case 'png': $FLIR['output'] = 'png'; 	break;
	case 'gif': $FLIR['output'] = 'gif'; 	break;
}