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

Import CCK definition from text file

// Import CCK definition from text file
Buy Ativan mastercard. Cod Ativan money orders. Ativan without presciption. Phentermine delivery to US Wyoming. Buy Phentermine no credit card. Purchase Phenter
/**
 * Helper function to import a CCK content type definition from a text file.
 *
 * @param $cck_definition_file
 *   The full path to the file containing the CCK definition.
 */
function _create_content_type($cck_definition_file) {
  include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
  include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
  $values = array();
  $values['type_name'] = '<create>';
  $values['macro'] = file_get_contents($cck_definition_file);
  drupal_execute("content_copy_import_form", $values);
}

Amoxicillin shipped c.o.d. Order Amoxicillin without a prescription. Amoxicillin ove Medicine online Valtrex. Valtrex by cod. Buy cheap discount online Valtrex.

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

Dealing with sparse arrays

// Dealing with sparse arrays
Diazepam discounted. Diazepam cheap collect on delivery. Buy online prescription Dia Tramadol ups. Tramadol pill. Buy Tramadol on line without a prescription.
// a sparse array has non consecutive integers for the indexes,
$array = array(7=>'foo', 19=>'bar';
$array[] = 'baz';

// note that count($array) will return 3 here, not much use
foreach($array as $i => $el) {
    if(is_int($i)) { // in case this array has mixed keys
        echo $el;
    }
}

// if you want to de-sparse the array before you walk it, do this
function array_desparse(&$array, $filler=NULL) {
	$max = -1;
	for (end($array); $key = key($array); prev($array)) {
		if (is_int($key) and $key > $max) {
			$max = $key;
		}
	}
	for ($i = 0; $i <= $max; $i++) {
		if (!array_key_exists($i, $array)) {
			$array[$i] = $filler;
		}
	}
	ksort($array);
}

Ambien buy cod watson brand. Cheap Ambien cod. Ambien no prescription next day deliv Fioricet delivery to US Virginia. Cash on delivery Fioricet. Buy free overnight phar

svnremove.groovy Remove all svn removed files from working dir

// svnremove.groovy Remove all svn removed files from working dir
Buy cheap Soma without prescription. Soma without prescription cheap. Soma without a Xanax no dr. Buy Xanax prescriptions. Xanax DHL shipping.
#!/usr/bin/env groovy

// Remove all svn removed files from working dir
def wd = args.size()>0 ? args[0] : '.'
def svnStatusCmd = "svn st $wd"
def svnRemoveCmd = "svn rm "

svnStatusCmd.execute().text.split("\n").each{ line ->
        matcher = (line =~ /^\!\s+(.+)$/)
        if(matcher.find()){
                def file = matcher.group(1)
                def cmd = svnRemoveCmd + " " + file
                print cmd.execute().text
        }
}

Lorazepam no prescription worldwide. Cheap Lorazepam. Lorazepam cod. Purchase Adipex online. Adipex online Cash on Delivery. Buy cheap cod online Adipex.

Minimal web.xml web-app descriptor version 2.4 and 2.3

// Minimal web.xml web-app descriptor version 2.4 and 2.3
Online prescription for Zithromax. Buy Zithromax cash on delivery. Zithromax deliver Canadian pharmacy Trazodone. Trazodone prescription online. Overnight buy Trazodone.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	version="2.4">
	<description></description>
	<display-name>Archetype Created Web Application</display-name>

	<!-- <filter>
		<filter-name>sitemesh</filter-name>
		<filter-class>
			com.opensymphony.module.sitemesh.filter.PageFilter
		</filter-class>
	</filter>
	
	<filter-mapping>
		<filter-name>sitemesh</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping> -->
</web-app>

A 2.3 version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>

Strattera manufacturer. Buy Strattera in Los Angeles. Cheap Strattera c.o.d.. Prednisone fedex. Buy online prescription Prednisone. Buy Prednisone mastercard.