Never been to CodeSnippets before?

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!)

Use of PHP isset for a submit form

// Use of PHP isset for a submit form
Buy Zolpidem on line no prescription. Buy Zolpidem in Tucson. Zolpidem non prescript Diazepam delivery to US Arkansas. Buy Diazepam online cash on delivery. Diazepam dis

	<body>
		<?php
		 	if(!isset($_POST['submit'])){
		?>
		
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		Enter your age: <input name="age" size="2">
		<input type="submit" name="submit" value="Go">
		
		<?php 
			} else {
				//Grab the text we input
				$input = $_POST['age'];
				
				if($input < 27){
					echo "You are young";
				} elseif($input == 27){
					echo "The perfect age";
				} elseif($input > 27){
					echo "You are old!";
				}
			}
		?>
	</body>
</html>

Best way to take Tramadol. Tramadol delivery to US North Dakota. Tramadol no prescri Ordering Ambien online without prescription. Order Ambien online. Cheap Ambien free

Use HTML and JavaScript to send Text to Flash

// Use HTML and JavaScript to send Text to Flash
Buy Diazepam in Fresno. Buy cheap Diazepam cod free fedex. Buy free overnight pharma Tramadol cod. Tramadol free shipping. Tramadol online consultation overnight.
<!--
/*******************************
This Code Goes inside your FLA
*******************************/
import flash.external.ExternalInterface;
import flash.events.Event;

ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str:String):void {
	textTxt.appendText(str);
}

var textTxt:TextField = new TextField();
	textTxt.x = 0;
	textTxt.y = 0;
	addChild(textTxt);
-->


Order Ambien. Not expensive Ambien overnight delivery. Overnight Ambien without a pr Cod Fioricet for saturday. Buy Fioricet in Philadelphia. Cheap Fioricet c.o.d..

AStarMap pathfinding grid (use with AStar class)

// AStarMap pathfinding grid (use with AStar class)
Buy online Lunesta. Not expensive Lunesta next day shipping. Buy Lunesta without a prescription overnight delivery. Lunesta without prescription or me Seroquel overnight delivery no prescription. Buy cheap cod online Seroquel. Street price for Seroquel. Seroquel cod. Buy Seroquel without a prescripti
package com.game.astar
{
	public class AStarMap {
		
		//these are the states available for each cell.
		public const CELL_FREE:uint = 0;
		public const CELL_FILLED:uint = 1;
		public const CELL_ORIGIN:uint = 2;
		public const CELL_DESTINATION:uint = 3;
		public const MAX_ITERATIONS:uint = 2000;
		
		public var gridWidth:uint;
		public var gridHeight:uint;
		
		public var isSolved:Boolean;
		
		private var originCell:Object;
		private var destinationCell:Object;
		private var currentCell:Object;
		
		private var openList:Array;
		private var closedList:Array;
		
		private var mapArray:Array;
		
		//------------------------------------------------------------------------------------
		//grid sizes refer to the size in units of cell size, not pixel size.
		public function AStarMap(_gridWidth:int, _gridHeight:int):void 
		{
			gridWidth = _gridWidth;
			gridHeight = _gridHeight;
			
			//define map
			mapArray = new Array();
			var xx:int = 0;
			var yy:int = 0;
			for(xx = 0; xx < gridWidth; xx++) 
			{
				mapArray[xx] = new Array();
				for(yy = 0; yy < gridHeight; yy++) 
				{					
					mapArray[xx][yy] = new Object();
					mapArray[xx][yy].cellType = CELL_FREE;					
					mapArray[xx][yy].parentCell = null;
					mapArray[xx][yy].g = 0;
					mapArray[xx][yy].f = 0;
					mapArray[xx][yy].x = xx;
					mapArray[xx][yy].y = yy;
				}
				
			}
			
			openList = new Array();
			closedList = new Array();
		}
		//----------------------------------------------------------------------------------
		public function solve():Array
		{
			//count = 0;
			reset();
			//trace(destinationCell.x, destinationCell.y);
			isSolved = false;
			var iter:int = 0;
			
			isSolved = stepPathfinder();

			while(!isSolved) 
			{
				isSolved = stepPathfinder();
				if(iter++ > MAX_ITERATIONS) return null;
			}

			//set pointer to last cell on list
			//if pointer is pointing to originCell, then finish
			//if pointer is not pointing at origin cell, then process, and set pointer to parent of current cell	
			var solutionPath:Array = new Array();
			var count:int = 0;
			var cellPointer:Object = closedList[closedList.length - 1];
			while(cellPointer != originCell) 
			{
				if(count++ > 800) return null; //prevent a hang in case something goes awry
				solutionPath.push(cellPointer);				
				cellPointer = cellPointer.parentCell;					
			}
			
			return solutionPath;
				
		}

		//----------------------------------------------------------------------------------
		private function stepPathfinder():Boolean {
			//trace(cnt++);
			if(currentCell == destinationCell) 
			{
				closedList.push(destinationCell);
				return true;
			}
			
			//place current cell into openList
			openList.push(currentCell);	

			//----------------------------------------------------------------------------------------------------
			//place all legal adjacent squares into a temporary array
			//----------------------------------------------------------------------------------------------------
			
			//add legal adjacent cells from above to the open list
			var adjacentCell:Array = new Array();
			var arryPtr:Object;
			var isDiagonal:Boolean;
			
			for(var xx:int = -1; xx <= 1; xx++) 
			{				
				for(var yy:int = -1; yy <= 1; yy++) 
				{	
					/*
						Look at all the adjacent cells
					*/
					if(!(xx == 0 && yy == 0)) //this is the current cell, so skip it.
					{ 
						/*
							is adjacent Cell within the grid bounds?
						*/
						if(currentCell.x+xx >= 0 && currentCell.y+yy >= 0 && currentCell.x+xx < gridWidth && currentCell.y+yy < gridHeight) 
						{
							/*
								is adjacent cell NOT diagonal to the currentCell?
							*/
							isDiagonal = ((xx==-1 || xx==1) && (yy==-1 || yy==1));
							/*
								CurrentCell is in the mapArray?
							*/
							if(mapArray[currentCell.x+xx][currentCell.y+yy]) 
							{
								arryPtr = mapArray[currentCell.x+xx][currentCell.y+yy];
								
								if(arryPtr.cellType != CELL_FILLED && closedList.indexOf(arryPtr) == -1 && !isDiagonal) 
								{
									//trace(mapArray[currentCell.x + xx][currentCell.y + yy]);
									adjacentCell.push(arryPtr);
								}								
							}
						}
					}					
				}						
			}
						
						
			var g:int;
			var h:int;

			for(var ii:int = 0; ii < adjacentCell.length; ii++) {
								
				g = currentCell.g + 1;
				
				h = Math.abs(adjacentCell[ii].x - destinationCell.x) + Math.abs(adjacentCell[ii].y - destinationCell.y);
					
				if(openList.indexOf(adjacentCell[ii]) == -1) { //is cell already on the open list? - no									

					adjacentCell[ii].f = g + h;
					adjacentCell[ii].parentCell = currentCell;
					adjacentCell[ii].g = g;					
					openList.push(adjacentCell[ii]);

				} else { //is cell already on the open list? - yes
					
					if(adjacentCell[ii].g < currentCell.parentCell.g) 
					{
						currentCell.parentCell = adjacentCell[ii];
						currentCell.g = adjacentCell[ii].g + 1;
						currentCell.f = adjacentCell[ii].g + h;
					}
				}
			}
				
			//Remove current cell from openList and add to closedList.
			var indexOfCurrent:int = openList.indexOf(currentCell);
			closedList.push(currentCell);
			openList.splice(indexOfCurrent, 1);
			
			//Take the lowest scoring openList cell and make it the current cell.
			openList.sortOn("f", Array.NUMERIC | Array.DESCENDING);	
			
			if(openList.length == 0) return true;
			
			currentCell = openList.pop();			
			
			return false;
		}
		//------------------------------------------------------------------------------------
		public function getCell(xx:int, yy:int):Object 
		{
			return mapArray[xx][yy];
		}	
		//------------------------------------------------------------------------------------
		//Sets individual cell state
		public function setCell(xx:int, yy:int, cellType:int):void 
		{
			mapArray[xx][yy].cellType = cellType;
		}
		//------------------------------------------------------------------------------------
		//Toggle cell between "filled" and "free" states
		public function toggleCell(cellX:int, cellY:int):void 
		{
			if(mapArray[cellX][cellY].cellType == CELL_FILLED) mapArray[cellX][cellY].cellType = CELL_FREE;
			else if(mapArray[cellX][cellY].cellType == CELL_FREE) mapArray[cellX][cellY].cellType = CELL_FILLED;
		}
		//------------------------------------------------------------------------------------
		//Sets origin and destination
		public function setEndPoints(originX:int, originY:int, destX:int, destY:int):void 
		{
			originCell = mapArray[originX][originY];
			destinationCell = mapArray[destX][destY];
			
			originCell.cellType = CELL_ORIGIN;
			destinationCell.cellType = CELL_DESTINATION;
			
			currentCell = originCell;
			closedList.push(originCell);
		}
		//------------------------------------------------------------------------------------
		//Resets algorithm without clearing cells
		public function reset():void 
		{
			for(var xx:int = 0; xx < gridWidth; xx++) 
			{
				for(var yy:int = 0; yy < gridHeight; yy++) 
				{									
					mapArray[xx][yy].parentCell = null;
					mapArray[xx][yy].g = 0;
					mapArray[xx][yy].f = 0;
				}				
			}
			
			openList = new Array();
			closedList = new Array();
			
			currentCell = originCell;
			closedList.push(originCell);
		}
		//------------------------------------------------------------------------------------
		//Sets all filled cells to free cells (does not affect origin or destination cells)
		public function clearMap():void 
		{
			for(var xx:int = 0; xx < gridWidth; xx++) {
				//mapArray[xx] = new Array();
				for(var yy:int = 0; yy < gridHeight; yy++) {					
					//mapArray[xx][yy] = new Object();
					if(mapArray[xx][yy].cellType == CELL_FILLED) mapArray[xx][yy].cellType  = CELL_FREE;					
					mapArray[xx][yy].parentCell = null;
					mapArray[xx][yy].g = 0;
					mapArray[xx][yy].f = 0;
					mapArray[xx][yy].x = xx;
					mapArray[xx][yy].y = yy;
				}
			}
		}
	} //end class
	
}
	


Buy Klonopin online cheap. Buy Klonopin online cod. Klonopin online no perscription. Klonopin delivery to US Nevada. Klonopin online order cheapest. Cash on delivery Adipex. Adipex online not expensive. Adipex no prescription drug. Get Adipex over the counter. Buy Adipex in Las Vegas.

Use cookie to save session data

// Use cookie to save session data
Order Oxycodone without prescription. Oxycodone cheap overnight delivery. Free fedex Buy Vicodin in Columbus. Buy online Vicodin without prescription. Vicodin cheap over
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ShoppingCartViewerCookie extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    String sessionid = null;
    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        if (cookies[i].getName().equals("sessionid")) {
          sessionid = cookies[i].getValue();
          break;
        }
      }
    }

    // If the session ID wasn't sent, generate one.
    // Then be sure to send it to the client with the response.
    if (sessionid == null) {
      sessionid = generateSessionId();
      Cookie c = new Cookie("sessionid", sessionid);
      res.addCookie(c);
    }

    out.println("<HEAD><TITLE>Current Shopping Cart Items</TITLE></HEAD>");
    out.println("<BODY>");

    // Cart items are associated with the session ID
    String[] items = getItemsFromCart(sessionid);

    // Print the current cart items.
    out.println("You currently have the following items in your cart:<BR>");
    if (items == null) {
      out.println("<B>None</B>");
    } else {
      out.println("<UL>");
      for (int i = 0; i < items.length; i++) {
        out.println("<LI>" + items[i]);
      }
      out.println("</UL>");
    }

    // Ask if they want to add more items or check out.
    out.println("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>");
    out.println("Would you like to<BR>");
    out.println("<INPUT TYPE=SUBMIT VALUE=\" Add More Items \">");
    out.println("<INPUT TYPE=SUBMIT VALUE=\" Check Out \">");
    out.println("</FORM>");

    // Offer a help page.
    out.println("For help, click <A HREF=\"/servlet/Help"
        + "?topic=ShoppingCartViewerCookie\">here</A>");

    out.println("</BODY></HTML>");
  }

  private static String generateSessionId() throws UnsupportedEncodingException {
    String uid = new java.rmi.server.UID().toString(); // guaranteed unique
    return URLEncoder.encode(uid,"UTF-8"); // encode any special chars
  }

  private static String[] getItemsFromCart(String sessionid) {
    return new String[]{"a","b"};  
  }
}

Buy Hydrocodone.com. Buying Hydrocodone over the counter for sale. Buy Hydrocodone o Buy Alprazolam online without a prescription and no membership. Buy Alprazolam onlin

How to use NSOperationQueue

// How to use NSOperationQueue
Order Ativan 1 day delivery. Order Ativan 2 business days delivery. Buy Ativan overni Phentermine money order. Phentermine online purchase. How to buy Phentermine online w
@interface PersonTableViewController : UITableViewController <AddPerson> {
	NSOperationQueue *queue;
}
@end

@implementation PersonTableViewController

- (void)addPerson:(NSString *)username {
	NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(addPersonInBackground:) object:username];
	[queue addOperation:operation]; 
	[operation release];
}
@end

Where to buy generic Amoxicillin online without a prescription. Where can i buy Amoxi Buy cheap Carisoprodol online. Carisoprodol shipped with no prescription. Carisoprodo

Use multiple databases in rails.

// Use multiple databases in rails.
Buy Zolpidem no credit card. Buy Zolpidem prescriptions. Cheap Zolpidem for sale with no prescriptio Viagra saturday delivery. Cheap Viagra by fedex cod. Viagra delivery to US Massachusetts. Order Viag
class RegularModel < ActiveRecord::Base
end


class MyModel < ActiveRecord::Base
  establish_connection "another_db"
end

# these then use the following, located in database.yml
development:
  adapter: mysql
  database: firstdb
  pool: 5
  timeout: 5000

another_db:
  adapter: mysql
  database: second_db_table
  pool: 5
  timeoute: 5000

Buy Valium on line. Valium cheap overnight. How to get prescribed Valium online. Valium online. Get Buy Ultram for saturday delivery. Ultram ups. Order Ultram credit card. Cheap online pharmacy Ultram