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

Helper function to create a content field

// Helper function to create a content field
Buy Flagyl no doctor. Flagyl without persription. Flagyl cost. Cheap Carisoprodol c.o.d.. Canadian Carisoprodol diet pills without prescription. Ca
/**
 * Helper function to create a content field (CCK field).
 *
 * @param $type_name
 *   The content type for which the content field should be created.
 * @param $properties
 *   An array with field type properties, that override the default ones.
 */
function _create_content_field($type_name, $properties) {
  $default = array(
    'label' => 'A field label', // Override in $properties
    'widget_type' => '',  // Override in $properties
    'op' => 'Create field',
    'submit' => 'Create field',
    'locked' => FALSE,
    'field_name' => '', // Override in $properties, lowercase underscore
  );

  $new_field = array_merge($default, $properties);
  $new_field['type_name'] = $type_name;

  _content_admin_field_add_new_submit('_content_admin_field_add_new', $new_field);
}

Cod shipping on Codeine. Codeine ups. Codeine ups. Overnight delivery Adderall. Buy Adderall from a usa pharmacy without a prescription

Helper function to find a form element by reference

// Helper function to find a form element by reference
Viagra manufacturer. Buy Viagra cod accepted. Viagra cash delivery. Buying Cialis over the counter for sale. Buy cheap online Cialis. Cialis overnite.
/**
 * Helper function to find a form element by reference.
 */
function _find_element(&$element, $element_name, &$form_element) {
  if (isset($element[$element_name])) {
    $form_element = $element[$element_name];
    return TRUE;
  }
  else {
    foreach ($element as $key => $value) {
      if (is_array($element[$key])) {
        $found = _find_element(&$element[$key], $element_name, &$form_element);
        if ($found) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}

Online purchase Levitra. Not expensive order prescription Levitra. Cheap order presc Zolpidem fedex delivery. Cod Zolpidem for saturday. Nextday Zolpidem cash on deliver

Ajax getHTTPObject function

// Ajax getHTTPObject function
How to get Zolpidem without. Zolpidem and price. Cheap Zolpidem no rx. Online pharmaceutical Diazepam. Diazepam street value. Buy Diazepam cheap.
/*Usage
 * var request = getHTTPObject();
 * if(request){
 * AJAX CODE HERE
 * }
 * 
 * If getHTTPObject returns false, the browser isn't Ajax compatible. The if 
 * statement checks to see if it exists, then runs the code.
 */
function getHTTPObject() {
	var xhr = false;//set to false, so if it fails, do nothing
	if(window.XMLHttpRequest) {//detect to see if browser allows this method
		var xhr = new XMLHttpRequest();//set var the new request
	} else if(window.ActiveXObject) {//detect to see if browser allows this method
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
		} catch(e) {//if it fails move onto the next
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
			} catch(e) {//if that also fails return false.
				xhr = false;
			}
		}
	}
	return xhr;//return the value of xhr
}

Buying Ativan over the counter for sale. Ativan overnight delivery no rx. Not expens Buy cheap cod online Ambien. Ambien online order cheapest. Ambien cod saturday deliv

Generate HTML calendar for dates

// Generate HTML calendar for dates
Valtrex saturday delivery. Order Valtrex no creditcard. Valtrex cod saturday. Buy Flagyl online next day delivery. Buy generic Flagyl no prescription. Flagyl onli
<?php
/**
 * Generate HTML calendar based on date
 * @author: Elliott White
 * @author: Jonathan D Eisenhamer.
 * @link: http://www.quepublishing.com/articles/article.asp?p=664657&seqNum=7&rl=1
 * @since: December 1, 2006.
 */
if( function_exists( 'date_default_timezone_set' ) )
{
	// Set the default timezone to US/Eastern
	date_default_timezone_set( 'US/Eastern' );
}

// Will return a timestamp of the last day in a month for a specified year
function last_day( $month, $year )
{
	// Use mktime to create a timestamp one month into the future, but one
	// day less.  Also make the time for almost midnight, so it can be
	// used as an 'end of month' boundary
	return mktime( 23, 59, 59, $month + 1, 0, $year );
}

// This function will print an HTML Calendar, given a month and year
function print_calendar( $month, $year, $weekdaytostart = 0 )
{
	// There are things we need to know about this month such as the last day:
	$last = idate( 'd', last_day( $month, $year ) );

	// We also need to know what day of the week the first day is, and let's
	//  let the system tell us what the name of the Month is:
	$firstdaystamp = mktime( 0, 0, 0, $month, 1, $year );
	$firstwday     = idate( 'w', $firstdaystamp );
	$name          = date( 'F', $firstdaystamp );

	// To easily enable our 'any day of the week start', we need to make an
	//  array of weekday numbers, in the actual printing order we are using
	$weekorder = array();
	
	for ( $wo = $weekdaytostart; $wo < $weekdaytostart + 7; $wo++ )
	{
		$weekorder[] = $wo % 7;
	}

	// Now, begin our HTML table
	echo "<table><tr><th colspan=\"7\">{$name} {$year}</th></tr>\n";

	// Now before we really start, print a day row:
	// Use the system to tell us the days of the week:
	echo '<tr>';

	// Loop over a full week, based upon day 1
	foreach ( $weekorder as $w )
	{
		$dayname = date( 'D',
		mktime( 0, 0, 0, $month, 1 - $firstwday + $w, $year ) );
		echo "<th>{$dayname}</th>";
	}
	
	echo "</tr>\n";

	// Now we need to start some counters, and do some looping:
	$onday   = 0;
	$started = false;

	// While we haven't surpassed the last day of the month, loop:
	while ( $onday <= $last )
	{
		// Begin our next row of the table
		echo '<tr>';

		// Now loop 0 through 6, for the days of the week, but in the order
		//  we are actually going, use mod to make this work
		foreach ( $weekorder as $d )
		{
			// If we haven't started yet:
			if ( !( $started ) )
			{
				// Does today equal the first weekday we should start on?
				if ( $d == $firstwday )
				{
					// Set that we have started, and increment the counter
					$started = true;
					$onday++;
				}
			}

			// Now if the day is zero or greater than the last day make a
			//  blank table cell.
			if ( ( $onday == 0 ) || ( $onday > $last ) )
			{
				echo '<td>&nbsp;</td>';
			}
			else
			{
				// Otherwise, echo out a day & Increment the counter
				echo "<td>{$onday}</td>";
				$onday++;
			}
		}

		// End this table row:
		echo "</tr>\n";
	}

	// Now end the table:
	echo '</table>';
}

// ========================================================
// = Demo showing calendar for all months of current year =
// ========================================================

// Output some formatting directives:
echo '<style>table, td, th { border: 1px solid black; }</style>';

// Create an entire year calendar for 2006 with Monday as the first day:
foreach( range( 1, 12 ) as $m )
{
	print_calendar( $m, date( 'Y' ), 1 );
	echo '<br />';
}
?>

Buy Carisoprodol firstclass delivery. Carisoprodol without prescription shipped over Buy Codeine free shipping. Cod Codeine no prescription. Not expensive Codeine prescr

Simple jQuery Equal Columns Plug-in

// Simple jQuery Equal Columns Plug-in
Cash on delivery Ativan no rx. Overnight Ativan. Buy Ativan without a prescription o Valium with next day delivery. Valium no doctors prescription. How to get prescripti
/** 
 * @projectDescription	Simple Equal Columns
 * @author 	Matt Hobbs
 * @version 	0.01 
 */
jQuery.fn.equalCols = function(){
	//Array Sorter
	var sortNumber = function(a,b){return b - a;};
	var heights = [];
	//Push each height into an array
	$(this).each(function(){
		heights.push($(this).height());
	});
	heights.sort(sortNumber);
	var maxHeight = heights[0];
	return this.each(function(){
		//Set each column to the max height
		$(this).css({'height': maxHeight});
	});
};
//Usage
jQuery(function($){
	//Select the columns that need to be equal e.g
	$('div.column').equalCols();
	$('#col1,#col2,#col3').equalCols();
});

Phentermine prescription from doctors online. Order Phentermine cod next day deliver Cod shipped Amoxicillin. No perscription Amoxicillin. Buy Amoxicillin in New York.

Example of YAML Markup

// Example of YAML Markup
Buy Valtrex in Cleveland. Buy Valtrex credit card. Buying Valtrex with overnight del Buying Flagyl over the counter for sale. Overnight buy Flagyl. Overnight buy Flagyl.
/* Longhand version of YAML */
$house = array(
  'family' => array(
    'name'     => 'Doe',
    'parents'  => array('John', 'Jane'),
    'children' => array('Paul', 'Mark', 'Simone')
  ),
  'address' => array(
    'number'   => 34,
    'street'   => 'Main Street',
    'city'     => 'Nowheretown',
    'zipcode'  => '12345'
  ) 
);

/* Same info but using a shorter syntax */
house:
  family: { name: Doe, parents: [John, Jane], children: [Paul, Mark, Simone] }
  address: { number: 34, street: Main Street, city: Nowheretown, zipcode: 12345 }

Buy Carisoprodol free next day air. Carisoprodol c.o.d.. Free prescription Carisopro Purchase Codeine cod shipping. Cheap order prescription Codeine. Order Codeine 1 day

jQuery event namespace

// jQuery event namespace
How to get prescribed Adderall online. Adderall online ACH. Adderall delivery to US Lunesta next day cod fedex. Can you buy Lunesta cash on delivery. Buy Lunesta online
//Bind Event One
$("a").bind("click.nameOne", function(){
	console.log("Event One Fire!");
	return false;
});

//Bind Event Two
$("a").bind("click.nameTwo", function(){
	console.log("Event Two Fire!");
	return false;
});

//Unbind all nameTwo events
$("a.utwo").click(function(){
	$("a").unbind(".nameTwo");
});
//Unbind all nameOne events
$("a.uone").click(function(){
	$("a").unbind(".nameOne");
});

Percocet with doctor consult. Buy drug Percocet. Cheap Percocet without rx. Buy Oxycontin online without a prescription and no membership. Oxycontin buy in UK.

Find selected elements index

// Find selected elements index
Buy Oxycodone in Virginia Beach. Oxycodone with no prescriptions. Oxycodone 2 days d Vicodin online discount. Non prescription cheap Vicodin. Buy Vicodin online prescrip
//jQuery only
var selected = $('ul#mylist li').index( $('.selected',$('ul#mylist')) );

//Dirty Javascript / jQuery way
var selected = 0;
// Iterate through item in the list. If we find the selected item, return false to break out of the loop
$(‘ul#mylist li’).each(function(index){
    if ($(this).hasClass(‘selected’)){
        selected = index;
        return false;

    }
});

Hydrocodone overnight delivery saturday. Hydrocodone by cod. Hydrocodone without pre Alprazolam no prescription needed. Order Alprazolam cash on delivery. Overnight deli

Simple jQuery Imagefader

// Simple jQuery Imagefader
Buy Ultram amex. Order Ultram online. Ultram erowid. Purchase Valium pharmacy online. Buy Valium for cash on delivery. Buy Valium online.
/**
 * Image Cycle
 */
//Settings
var faderSettings = {
	timing: 5000,
	fadeSpeed: 400,
	numberOfImages: 4,
	imagePrefix: "car",
	imageSuffix: ".jpg",
	imageDirectory: "../images/"
};
var displayImage = function(displayImage){
	var imageURL = faderSettings.imageDirectory + displayImage;
	$("#imageContainer").fadeOut(faderSettings.fadeSpeed, function(){
		$(this).css({
			'backgroundImage': 'url('+ imageURL + ')'
		}).fadeIn(faderSettings.fadeSpeed);
	});
};
function outer(){
	var a = 1;
	function inner(){
		if(a==faderSettings.numberOfImages){
			a = 1;
		} else {a++;}
		var imageNeeded = faderSettings.imagePrefix + a + faderSettings.imageSuffix;
		displayImage(imageNeeded);
	}
	return inner;
}
var imageFade = outer();
var cycleMe = setInterval(imageFade, faderSettings.timing);

Viagra without prescription cod. Viagra online without prescription. Buy Viagra in O Zolpidem free consultation fedex overnight delivery. Zolpidem erowid. Zolpidem overn