Archive

Archive for September, 2008

Your .sql is Too Big for PHPMyAdmin? BigDump it!

September 25th, 2008

When I was migrating the sampsonvideos forums from the old server to the new, I expected it to be a very quick transition. I would create a dump, and upload it through PHPMyAdmin on the new server. Needless to say, things didn’t go as smooth as I had hoped. Turned out there was something like a 3mb limit on .sql files for my particular instance of PHPMyAdmin:

//thank you very much
$frustration++;

So after some time searching for solutions, I came across BigDump. What is BigDump?

“Staggered import of large and very large MySQL Dumps (like phpMyAdmin 2.x Dumps) even through the web servers with hard runtime limit and those in safe mode. The script executes only a small part of the huge dump and restarts itself. The next session starts where the last was stopped.”

I used it, and it worked perfectly. It saved me a lot of time and frustration. Thanks Alexey Ozerov!

General, MySQL, PHP, Programming

jQuery, IE, and Cleartype.

September 24th, 2008

Many of you who use jQuery regularly may have noticed that using .fadeIn(), .fadeOut(), or .fadeTo() will remove cleartype from your opacified-text. This sucks, as you would guess. To my knowledge this is an IE-exclusive “feature”.

After doing a small bit of searching, I discovered the solution over on Benjamin Novakovic’s blog. In his example he uses fadeIn, and fadeOut, but these functions both have a similar footprint to fadeTo - [callback].

Essentially it’s this, you remove the filter from the affected region. If you’re fading .opacity, then remove the css filter property after you’re finished. This doesn’t remove all woes, unfortunately. You still get a nasty transition where for a moment your cleartype is gone, and returns only when the fading is completed.

Ben provided the following replacement functions. After some quick testing, they seem to be pretty solid.

?View Code JAVASCRPIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};

Javascript, Programming, jQuery

Use Safe Passwords

September 20th, 2008

This is a very very non-technical post, but I find it so dreadfully important. I just got a phone call from a friend who found a few extra charges on his credit card. Fortunately, the bank will cover those and they’ve issued a new card that will arrive in about a week.

After talking with my friend for a few minutes, I asked if he uses his card online - yes, he did. I then asked if he has any web-accounts tied to it - yes, he does. Last question, “Do you use a single-word as a password for that web-account? A sorrowful “yes” followed through the receiver.

I think many people fear “strong” passwords because they’re afraid they may not remember them. While “boston” is easy to remember, it’s also easy to guess. Hackers can brute-force (manually crack via numerous guesses) any account that uses a single-word like this with dictionary files. And with the resources available to those hackers today, they can try thousands of words in a few short moments - they will guess your password.

Protect yourself. Try using a pass-phrase instead of a word. “Boston” is easier to guess than “iwasborninboston” or “livinginboston”. Those latter two strings won’t appear in the terms found in a dictionary, and they would be far harder to guess than the first string.

If you want to further complicate things for others, try alpha-numeric words. “b05ton” in place of “boston” for example. Or “b0s70n” even. You will remember that your “o” is replaced with “0″, “t” is replaced with “7″, and so on. This creates variability that will drive script-kiddies mad.

To make things even harder, write down 13 random numbers and letters on a small piece of paper. Keep it in your wallet, or some place private, and use it as your password. a83jZeoaLwyHe - let’s see you guess that, suckas! You can even upper-case some letters for added insanity!

Oh, and don’t use the same password for more than one account ;)

General, Rant

Animated Rollover-Opacity with jQuery

September 19th, 2008

I’ve got to admit, everything is easier with jQuery. I don’t mean that as a marketing thing, I mean that as a “everything is friggin’ easier with jQuery” thing - and that’s that. You see online many websites that provide links to network sites, only these links are images, and these images have nice transitions when you rollover them from 50% opaque, to 100% opaque. Remove your cursor, and it transitions back to 50% opaque.

So how is that done? Well, I can’t answer for any of those guys, but I can tell you that it’s extremely easy to do this in jQuery with only a few lines of code.

Suppose you have the following list of images:

1
2
3
4
5
<ul>
  <li><img src="php.jpg" alt="PHP Is Awesome" /></li>
  <li><img src="mysql.jpg" alt="MySQL Is Sexy" /></li>
  <li><img src="jQuery.jpg" alt="jQuery Is Sooo Dreamy" /></li>
</ul>

To start our opacification and instant sexification of our demonstration, we could add a class “opacify” to anything on the page we want to add this effect to. So our images now become something like this:

1
<img src="filename.extension" alt="...message..." class="opacify" />

Next up, the jQuery code!

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
$(document).ready(function () {
  $(".opacify").fadeTo(1, 0.5);
  $(".opacify").hover(
    function () {
      $(this).fadeTo("fast", 1);
    },
    function () {
      $(this).fadeTo("normal", 0.5);
    }
  );
});

So what do we have here? Well, before we go through the code, you can simply copy and paste it to see it in effect. First though, you’ll need to get the latest release of the jQuery javascript file. You can find it online at http://docs.jquery.com/Downloading_jQuery#Download_jQuery - as I write this, the release is 1.2.6.

Download that, place a reference to it in your tag, and you’ll be up and running.

Now, let’s actually look at the code - this won’t take long. The first thing you’ll notice is that I have my effect-code within another block:

?View Code JAVASCRIPT
1
2
3
$(document).ready(function(){
  // put your effect code here
});

This code basically checks to make sure the document (webpage) is ready, and once it is it runs the code that is in place of the comment. Simple, right? :)

Now what is going on here:

?View Code JAVASCRIPT
1
$(".opacify").fadeTo(1, 0.5);

Basically we’re selecting all elements that have the classname of “opacify”, hence the CSS-ish request for “.opacify”. We’re then running the fadeTo() function on each of these matched elements, will will in 1 millisecond set their opacity to 0.5. The first argument here can also be a string if you like. You can say “slow”, “normal”, or “fast”.

Lastly, we have the following:

?View Code JAVASCRIPT
1
$(".opacify").hover(<func1>,<func2>);

Again we’re calling all elements with “opacify” as a classname, and we’re setting some functionality for the hover-event, when your mouse passes over the element. This hover() function takes two parameters. The first is a function that will run when your mouse enters the elements area, and the second parameter is the function that will be called when the mouse leaves the elements area.

So again, in the end we have the following:

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
$(document).ready(function () {
  $(".opacify").fadeTo(1, 0.5);
  $(".opacify").hover(
    function () {
      $(this).fadeTo("fast", 1);
    },
    function () {
      $(this).fadeTo("normal", 0.5);
    }
  );
});

General, Javascript, Programming, jQuery

Javascript-driven Markdown GUI!

September 10th, 2008

I’m a huge fan of PHP Markdown, so naturally I was excited when I came across a Javascript port of it. John Fraser created “Showdown”, which is his version of Markdown driven by Javascript. Note, this isn’t merely a gui that calls the markdown php function, and displays the results asynchronously, this is a complete re-write of the markdown function into javascript.

If you aren’t familiar with Markdown, get familiar with it.

If you are familiar with it, check out “Showdown” over at http://attacklab.net/showdown

Javascript, Programming

PHP Array to Multiple HTML Lists

September 9th, 2008

I needed to split a single array up into two UL elements side-by-side, so I decided to write a small function. But then I started thinking, “What if I want more than two columns eventually?” So I wrote a little added logic to handle that. “But what if I want it split by a certain number of entries per column, and not necessarily by a number of columns,” so I wrote a bit more logic.

Here’s the end result. It’s all yours ;) Free.

string buildListColumns (array $sourceArray[, string $limitType][, int $limit])

sourceArray
This is an associative array that contains your values.

limitType (Optional - Defaults to column)
This is a string, either “column” or “entry”. Column indicates you want a fixed number of columns, and Entry declares a fixed maximum number of entries per column.

limit (Optional - Defaults to 1)
This is a number that declares how many columns/entries you are setting the limit to.

Example of Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
$categories = array(array("category"=>"Biology"),
		array("category"=>"Physics"),
		array("category"=>"Geology"),
		array("category"=>"Astronomy"));
print buildListColumns($categories,"column",2);
 
function buildListColumns($sourceArray = array(), $limitType = "column", $limit = 1) {
	if (count($sourceArray) > 0) {
		$sizeOfArray = count($sourceArray);
		$limit = ($limitType == "entry") ? $limit : (ceil($sizeOfArray/$limit)) ;
		$output = "";
		$current = 0;
		if (in_array(strtolower($limitType),array("entry","column"))) {
			// User has chosen a set number of entries per column
			foreach ($sourceArray as $item) {
				// If first element in list, or element number matches break number
				if ($current == 0 || (($current % $limit == 0) && $current > 0)) {
					// Start new List
					$output .= "<div><ul>\r\n";
				}
				// Insert current element
				$output .= "\t<li>{$item['category']}</li>\r\n";
				// If last element in list, or current element matches break number
				if ($current == ($sizeOfArray - 1) || ((($current + 1) % $limit == 0) && ($current + 1) > 0)) {
					// End List
					$output .= "</ul></div>\r\n";
				}
				// Increment current element number
				$current++;
			}
		} else {
			// Invalid limit type
			$output = "Invalid limitType. Use 'column' or 'entry'.";
		}
		// Return our lists
		return $output;
	} else {
		return "Empty array.";
	}
}
?>

PHP, Programming

Sony isn’t all that bad…

September 9th, 2008

You know, I need to take just a moment and breath. I was kinda rough on Sony a couple days ago when I belittled them for screwing over millions of teens who convinced mom and dad to buy them every friggin’ game available for the PS2, only to watch that treasure sink like Atlantis in the horizon of a new generation of PlayStation consoles - but that’s their problem. Like I said, I don’t own any PS2 games anyway.

What I do own now is a PS3, so that’s where my interest is at. A few nights ago I discovered that PS3 comes with in-box support of Folding@Home. Now, if you’re not familiar with folding, then you likely could care less - but you should care, and you should get familiar wit Folding, because it’s something that may eventually save your life, or a loved one.

Check out Folding@Home: Distributed Computing

So last night I setup my PS3 to start folding, and after a couple software updates I was up-and-running. My first work-unit will be done in about 15 hours from now. It’s likely that each unit will take about a day of processing.

I had attempted folding on my pc a while back, but it required too much power and I got sick of the whiring-disk at my feet breaking the sound of silence. The PS3 seems to be a perfected folding machine.

Good job Sony! Good job for pre-loading the PS3 with software that everybody should be running. Software that works toward the good of all mankind. Oh, and thanks to the software-engineers for making the Folding@Home app fun to use! It features a 3d-globe that shows the current sun-position in relation to the Earth, and even light-images from planet-Earth…so you can watch as your location gets darker, and the lights begin coming on.

While spinning and exploring your globe, you can listen to music from your PS3, or switch the view to the current protein you’re folding with numerous rendering options. Having the massive protein wiggling around on your screen makes you look very technical. So if any of you fellas out there have women who love geeky things, this will definitely score you some points!

“What’s that?”, “That? Oh, that’s nothing…I’m just processing complicated protein-data for Stanford in a 3d environment. Yeah, my PS3 may cure Cancer in the next 24 hours. Go ahead, spin it around and see how amazing I am.” Ohhh yeah.

General, Rant

Sony Screws its Most Valuable Customers?

September 7th, 2008

After several months of thinking, lusting, and general in-store petting, my wife and I finally purchased a gaming-console. I’m a PC-gamer through and through, but she’s got a fetish with shiny objects in the house, and I’ve got a fetish for sweet-functioning tech-gadgets.

Enter the console wars. Do we get a 360 and give me the opportunity to play with XNA a bit, or maybe blast some alien filth in halo3? Do we get the Wii and work up a sweat playing tennis in the living room? Or do we get the PS3 and enjoy gaming, plus some nice blu-ray action? We decided that PS3 was where we would spend our money. Then the crap began.

I had no idea the new 80gb PS3 isn’t backward-compatible with PS2 games. Granted, we don’t currently own any PS2 games, but my wife’s favorite game just happens to be a PS2 game, and we were looking forward to renting it. But that got me thinking, what about all of the other PlayStation-gamers who’ve invested hundreds of dollars into their PS2 game-collection, only to be cut-off by their massive tech-nipple that fed them for so many years? Why on Earth would you do that to your followers and faithful supporters!?

Apparently, Sony did release a 40gb version of the PS3 a few months (or over a year?) ago, but nobody was carrying that anymore…or were they?

I remember several months ago Mayra and I went to Blockbuster to rent a movie, only to see that they were selling PS3 units complete with a blu-ray DVD (Spiderman 3 in our case), game (Transformers - sucks), HDMI Cable, and a Remote.

As we exited BestBuy, with heads hanging low in despair, my wife passingly suggested we drive over to Blockbuster - perhaps they still have one dust-covered in the corner. So over to the movie-store we went; she vanished behind the posters hanging in the windows as I waited patiently in the car, engine running.

She returned about 5 minutes later with a thumbs-up - we now own a PS3. But I’m still annoyed at Sony for building units that aren’t backward compatible with their previous games, and doing so after releasing a batch of units that were!

Not that it means anything big, but Sony, I do bite my thumb at thee!

Rant

PHP Function: deep_replace() Replace values in string/array

September 6th, 2008

The following function will search and replace any occurrence of a value within a string, or an array of any depth, including jagged arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function deep_replace($search, $replace, $subject) {
  $subject = str_replace($search, $replace, $subject);
  foreach ($subject as &$value)
    if (is_array($value)) {
      $value = deep_replace($search, $replace, $value);
    }
  return $subject;
}
 
$phrases = array("Jonathan likes computers.",
                 array("Jonathan laughs like a sissy-girl."),
                 "Jonathan doesn't like cake.",
                 "Jonathan is extremely handsome.",
                 array("Jonathan has a bike!",
                       "Jonathan needs to learn how to ride a pony."));

You call it like this:

1
$newValue = deep_replace("Jonathan","Dazulu",$phrases);

PHP, Programming

Relocate File PHP Function, with “Save-Original” Option!

September 6th, 2008

This function will allow you to move files from one location to another, with the added ability to automatically save any originals by appending the current UNIX Timestamp to the end of its filename.

# Source, Destination, Save Original as Backup
print relocatefile("file.txt","folder/file.txt",true);

function relocatefile($source,$destination,$saveoriginal = true) {
    if (file_exists($destination)) {
        if ($saveoriginal == false)
            unlink($destination);
        else
            rename($destination,($destination.time()));
    }
    if (rename($source,$destination))
        return true;
    else
        return false;
}

PHP, Programming