You must remember that there are hard-coded urls all over word press. Here are 3 sql statements to update those urls:

  1. Update all post guids: UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain-name.com','http://www.new-domain-name.com');
  2. Update all post content: UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain-name.com', 'http://www.new-domain-name.com');
  3. Update all home and site_url options: UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain-name.com', 'http://www.new-domain-name.com') WHERE option_name = 'home' OR option_name = 'siteurl';
seth

Linux Find Examples

There is a very helpful reference on wagoneers.com for the Linux 'find' command. Download a printer friendly version of the Linux Find Examples.

seth

Sql foo gone bad…

group_concat is awesome, until your realize it starts truncating at 1024 :(...

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_group_concat_max_len

seth

BEWARE! Koobface Facebook Virus

I just finished cleaning off a machine with this virus. Please don't click on any links from Facebook that sound like this...

Yesterday, reports started circulating about a virulent piece of worm spreading through Facebook. The malicious code isn't exactly new (it started surfacing in August), but has now been altered to strike social networking websites only and is currently making the rounds on Facebook pretty quickly, it seems. The virus can spread fast because they travel through messages which appear to come from your friends.

The Koobface messages carry subject lines like "You look so funny on our new video" or something similar, and contain a link to a video site that appears to contain a movie clip. If the user tries to watch it, a message appears saying that he or she needs the latest version of Flash Player in order to play the clip. This tricks users into downloading a file carrying the malware. An earlier version of the virus targeted MySpace users earlier this year but was quickly eliminated after new security measures were put in place.

Entire article here...http://www.washingtonpost.com/wp-dyn/content/article/2008/12/05/AR2008120501081.html

seth

Counter Class

Counter Class

Counter class can be used to keep a count and timer of a given object or group of objects. I use it mainly for counting links and stopping and starting a timer in session. This helps me to keep track of how long a user is on a particular page or group of pages. You may find it useful to call this object through AJAX to update counter information in your database, or just hit it using a normal post. In my case, I wrote a small extension of this class which does all of the necessary DB handshaking between the counter data and the database.

Usage:
* @example $counter = new Counter(100) - this instantiates the $counter object and sets the initial counter 'page'=>100,'count'=>1
* @example $counter = new Counter(null,true); - this instantiates the $counter object and sets the initial counter [page]=>'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'],[count] => 1, [time] => 0
If the second value is true, the clock will start ticking on your page's session variable. Every time the counter is called again, the session variable will update to the time difference between the second call and the initial call. You may use the other methods such as, stopTimer, restartTimer to do the obvious. When finished counting and timing, you may obtain all of your counts and times using the getAllCounts method. That's about it. It's simple, but it comes in real handy for me when attempting to, well, count things.

Counter Class

seth

Fade to DIV with MooFX

Here's a quick example of fading in/out of divs with Moofx. In order to use this, you will need two href tags with ids, and two divs to fade in and out of. Read the code comments for more instruction:

/* Set default opacities
 * When the page loads, display the gallery;
 * Turn off the display of the specials page;
 * Also turn down the opacity.
 */
Window.onDomReady(function(){
	$('gallery').setOpacity(1);
	$('specials').setOpacity(0);
	$('specials').setStyle('display','none');
})

/* Attach events to the href ids that you will be using to trigger the events;
 * In this example, I have two divs to toggle, specials and gallery.
 * When one div is toggled, make sure to toggle off the other div first.
 * Also make sure to set your opacity to 0 before displaying.
 * If not, your div will display in full before doing the actual fade in.
 */
$('show_gallery').addEvent('click', function(e){
	$('specials').setStyle('display','none');
	$('gallery').setOpacity(0);
	$('gallery').setStyle('display','');
	var myFx = new Fx.Style('gallery', 'opacity').start(0,1);
});

$('show_specials').addEvent('click', function(e){
	$('gallery').setStyle('display','none');
	$('specials').setOpacity(0);
	$('specials').setStyle('display','');
	var myFx = new Fx.Style('specials', 'opacity').start(0,1);
});

This will not get you to SQL-foo master status, but it will help you out when trying to find duplicate rows in a database table that is, err, let's just say not-so-well-formed:

select
count(*),
min(id),
max(id),
email
from users
group by email having count(*)  > 1;
seth

State name >> abbreviation

This is a quick write up for walking through a result set data and converting state names to abbreviations:

/**
* Walks through an array and looks for a specific state key. It then tries to convert the full state name to its abbreviation.
* Originally written for importing CSV data to the database where all of the rows contained full length state names. Thought it would
* be useful in other functions so added it to global. Call it like this: array_walk($arr,'state_abbr',[state_key_name]);/sa
* @uses array $states - Must have a states array formatted with abbreviations as the key.
* @param array $arr - reference to the array we are walking through
* @param string $key - current key
* @param string $array_key - state field name string we should be checking for in array
* @return void
*/
function state_abbr(&$arr,$key,$array_key){
global $states;
if(strlen($arr[$array_key])==2 && array_key_exists(strtoupper($arr[$array_key]),$states)){ return false; }; //if the value is already a abbr, don't do anything
$arr[$array_key] = array_search(ucwords(strtolower(trim($arr[$array_key]))),$states);
}
/* Don't forget your states array */
array('AL'=>'Alabama','AK'=>'Alaska');