Welcome

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

PHP redirect

For some reason I can never remember this code when I need it ... so here it is for easy reference.

<?php header("Location: http://www.domain.com/index.php"); ?>

Using stretchable images in Obj-C buttons

// New Obj-C buttons
Free Zolpidem. Buy cheap online Zolpidem. Buy Zolpidem no prescription. Zolpidem overnight fed ex no prescription. Diazepam no script required express delivery. Discount Diazepam. Buy Diazepam medication cod. Diazepam c.o.d..
UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
	UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[doSomethingButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
	UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[doSomethingButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];

Tramadol fed ex cheap. Ordering Tramadol online without a prescription. Buy Tramadol in Atlanta. Tramadol online not expensive. Ambien from india is it safe. Buy Ambien credit card. Ambien cod no prescription required. Buy Ambien order cod.

NSString MD5

// NSString MD5
Cheap online pharmacy Ambien pill. Cheapest Ambien medication. Ambien cr lunesta free standart shipping. Buy Ambien in Los Angeles. Not expensive 120 butalbital fioricet overnight delivery. Fioricet high without a prescription and cod delivery. Order Fioricet tablet. Fioricet 180 cheap online.
- (NSString *) MD5{
	const char* string = [self UTF8String];
	unsigned char result[16];
	CC_MD5(string, strlen(string), result);
	NSString* hash = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
					  result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], 
					  result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]];
	
	return [hash lowercaseString];
}

Herbal soma online health insurance lead. Purchase Soma over the counter fedex. Buying Soma 350 without a prescription. Soma for pets overnight fed ex no prescription. Cheap Xanax 2 mg cod. Xanax for cats without doctor rx. Xanax alprazolam discount. Xanax free air shipping.

Full directional movement of player

// cocos2D tilemap
Fioricet online ordering. Order Fioricet cod next day delivery. Fedex Fioricet without priscription. Docs dont presribe Fioricet. Cod saturday Soma. Soma cod saturday delivery fedex. Soma cost. Soma delivery to US Florida.
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
	
	BOOL moveX, moveY = NO;
	
    CGPoint touchLocation = [touch locationInView: [touch view]];		
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
    touchLocation = [self convertToNodeSpace:touchLocation];
	
    CGPoint playerPos = _player.position;
    CGPoint diff = ccpSub(touchLocation, playerPos);
	CGSize winSize = [[CCDirector sharedDirector] winSize];
	
	// Define areas on the screen to control player differently
	// Centralised cross that will move directly up, down, left or right (winsize.width/3, winsize.height/3)
	// Remaining areas will move diagonally
	// If central crossover area is pressed, player will not move.
	
	// Left/right press
	if (touchLocation.x < winSize.width/3) {
		moveX = YES;
	} else if (touchLocation.x > ((winSize.width/3)*2)) {
		moveX = YES;
	} else {
		moveX = NO;
	}
	
	
	// Up/down press
	if (touchLocation.y < winSize.height/3) {
		moveY = YES;
	} else 	if (touchLocation.y > ((winSize.height/3)*2)) {
		moveY = YES;
	} else {
		moveY = NO;
	}
	
	
	
    if (moveX) {
		if (diff.x >= _tileMap.tileSize.width) {
            playerPos.x += _tileMap.tileSize.width;
        } else if (diff.x <= (_tileMap.tileSize.width * -1)) {
            playerPos.x -= _tileMap.tileSize.width; 
        }    
	}
	
	if (moveY) {
        if (diff.y >= _tileMap.tileSize.height) {
            playerPos.y += _tileMap.tileSize.height;
        } else if (diff.y <= (_tileMap.tileSize.height * -1)) {
            playerPos.y -= _tileMap.tileSize.height;
        }
	}
	
	
	if (moveX || moveY) {
		
		if (playerPos.x <= (_tileMap.mapSize.width * _tileMap.tileSize.width) &&
			playerPos.y <= (_tileMap.mapSize.height * _tileMap.tileSize.height) &&
			playerPos.y >= 0 &&
			playerPos.x >= 0 ) 
		{
			[self setPlayerPosition:playerPos];
		}
		
		
	}
}

Xanax online no script. Xanax c.o.d.. Order Xanax credit card. Xanax without a prescription canadian. Tramadol for cat without prescription medications. Not expensive order prescription Tramadol. Buy discount Tramadol. Tramadol online overnight.

CSS Universal Styles

Start out a site's CSS with these, to level the playing field as much as possible.

/* remove all margins and padding */
* {
	margin: 0px;
	padding: 0px;
}
/* remove borders from any images that have links around them */
img {
	border:none;
}

/* remove default cellspacing and cellpadding, and set a width */
table {
  border-collapse: collapse;
  width:100%;
} 

/* all table cells align to top (not middle) and header cells to left */
td, th {
	vertical-align:top;
	text-align:left;
}

XHTML 1.0 Transitional template

// description of your code hereKamagra sildenafil citrate tablets 100mg

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="imagetoolbar" content="no" /><!-- kills IE's img toolbar -->
<meta name="MSSmartTagsPreventParsing" content="true" /><!-- kills related links in XP -->
<link rel="stylesheet" type="text/css" href="/styles/main.css" />

</head><body><div id="page">



<div id="header">
<h1>Header</h1>
</div><!--END #header-->



<div id="content">
</div><!--END #content -->



<div id="footer">
<h1>Footer</h1>
</div><!--END #footer -->
</div><!--END #page --></body></html>

XSL creating nested elements

When I start with a fairly flat XML structure (several sets of elements not nested), here's the XSL to nest them. The example starts out with a set of <question> elements and <answer> elements, and nests the answers within the appropriate questions.

<xsl:template match="//question">
<question>
	<xsl:copy-of select="*"/>
	<xsl:apply-templates select="//answer[question_id = current()/id]"/>
</question>
</xsl:template>
<xsl:template match="//answer">
<answer>
	<xsl:copy-of select="*"/>
</answer>
</xsl:template>

MySQL using group and group_concat

// description of your code here

/* group by */
SELECT department, SUM(sales) AS total_sales
FROM order_details
GROUP BY department;

/* group_concat */
SELECT GROUP_CONCAT(popname ORDER BY popname ASC SEPARATOR ', ') 
FROM populations;

/* group_concat as aggregate function with group by:
SELECT state, GROUP_CONCAT(city) AS cities
FROM bigcities
GROUP BY state;

MySQL duplicating a table for testing

Here’s a maxim worth remembering when you feel the itch to run queries on a production database table: Duplicate the table you want to play with. The MySQL syntax for this command is simple.

/* this duplicates the table and all data in it */
CREATE TABLE new_table SELECT * FROM old_table;

/* this duplicates only a portion of the data, for testing */
CREATE TABLE new_table 
SELECT * FROM old_table WHERE field1='value' LIMIT 0, 10000;