Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@jtarleton
jtarleton / drupalstuff.php
Last active August 29, 2015 14:06
A set of generic data structures for extending the Drupal 7 Database class
<?php
/**
* A set of generic data structures for extending the Drupal 7 Database class.
*
* For non-Drupal projects, you could also use this with PDO.
*
* Just re-write the BaseObject, BaseEntity, BaseCollection classes.
*
*
* Defining your own data types in PHP is as easy as:
@jtarleton
jtarleton / drupalhashing.php
Created September 4, 2014 20:17
Drupal-style password hashing routine
<?php
/**
* A general purpose password hashing routine (from Drupal)
*
* Requires two standard drupal "include" files (available for download at https://www.drupal.org/):
* 1. drupal_bootstrap.inc
* 2. drupal_password.inc
*
* You might also want to use it to manually "reset" a password in a Drupal site's "user" MySQL table
*
@jtarleton
jtarleton / gist:52941b676eb4ada9b290
Last active August 29, 2015 14:10
Drupal Form Builder class using ArrayAccess and Builder pattern
<?php
class DrupalFormBuilder implements ArrayAccess
{
private $data = array();
public function __construct(array $fieldsets = array('fs1'=>'fs1')) {
foreach($fieldsets as $key=>$fieldset){
$this->addFieldset($fieldset);
@jtarleton
jtarleton / JtXmlParser.class.php
Last active August 29, 2015 14:11
XML Parsing in PHP Tutorial
class JtXmlParser
{
const XML_PATH ='datasource.xml';
const START_NODE = 'ROW'; // the element identifying a new record
public $file,
$rows = array(),
$record = array(),
$fdata = '',
@jtarleton
jtarleton / JtCaptcha.class.php
Last active August 29, 2015 14:11
Simple Captcha Image
<?php
/*
* Based on SIMPLE CAPTCHA IMAGE SCRIPT by Constantin Boiangiu
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@jtarleton
jtarleton / gdtest.php
Last active August 29, 2015 14:14
Checking for GD Support in PHP
<?php
/* Displays details of GD support on your server */
echo '<div style="margin: 10px;">';
echo '<p style="color: #444444; font-size: 130%;">GD is ';
if (function_exists("gd_info")) {
@jtarleton
jtarleton / Helpers.class.php
Last active August 29, 2015 14:15 — forked from anonymous/Helpers.class.php
Sort an associative array of objects by any number of properties in any order, maintaining key association.
<?php
class HelperLibrary
{
/**
* Sort an associative array of objects by any number of properties in any order, maintaining key association.
*
* Example usage, for an array of users:
*
* $users = array();
*
@jtarleton
jtarleton / HelperLib.class.php
Created February 18, 2015 15:28
Helper function for array slicing
<?php
class HelperLibrary {
// Utility to slice an associative array
public static function assoc_array_slice($array, $offset, $count) {
$result = array();
$keys = array_keys($array);
$end = min($offset + $count, count($array));
@jtarleton
jtarleton / js-sort.html
Created April 16, 2015 16:44
Sorting an Array Objects in Javascript
<!DOCTYPE html>
<head>
<title>Javascript Object Sorting Exercise</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
.yella {
background-color: yellow;
}
.arrow-up {
@jtarleton
jtarleton / limetest.php
Created November 23, 2012 03:05
Lime Test
<?php
require_once('/lime/lime.php');
$t = new lime_test(1);
$arr = array('foo');
$t->isa_ok($arr, 'array', 'is an array');