Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@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');
@jtarleton
jtarleton / BastardFinder.class.php
Created December 1, 2012 02:37
Finds bastard foreign keys in a database
<?php
if(!class_exists('Db'))
require_once( dirname(__FILE__) . '/Db.class.php');
class BastardFinder
{
public $mysql, $mongo, $BastardBars, $BastardFoos;
static private $instance;
@jtarleton
jtarleton / TinyMVC.php
Created December 1, 2012 22:36
An object-oriented dynamic web app in 150 lines
<?php
/* Tiny MVC, v.1.0.
Author: James Tarleton
System Requirements:
* PHP 5+
* Web server (Optional)
* PDO_MYSQL driver for PHP (Optional)
@jtarleton
jtarleton / csvimport.php
Created December 4, 2012 14:47
CSV Import Via PDO
<?php
require_once(dirname(__FILE__).'/model/DATABASE.class.php');
$adid = DATABASE::PDOCreate('mysql://root:123@localhost/db1');
$tablename = 'myawesometable';
$adid->exec(sprintf('DELETE from %s', $tablename));
@jtarleton
jtarleton / ColorCLI.php
Created December 7, 2012 04:36
Static methods for colors in bash
<?php
class ColorCLI
{
static $foreground_colors = array(
'black' => '0;30', 'dark_gray' => '1;30',
'blue' => '0;34', 'light_blue' => '1;34',
'green' => '0;32', 'light_green' => '1;32',
'cyan' => '0;36', 'light_cyan' => '1;36',
'red' => '0;31', 'light_red' => '1;31',
@jtarleton
jtarleton / php_lint.php
Created December 7, 2012 04:38
Lint all PHP source files in a directory
<?php
$dh = opendir('.');
while (false !== ($filename = readdir($dh)))
{
$files[] = $filename;
}
sort($files);
foreach( $files as $file)
{
if(
@jtarleton
jtarleton / super_unique.php
Created December 7, 2012 04:49
Two approaches to de-duping a multi-dimensional array
/*
* Super Unique
*/
public function super_unique(array $badarray)
{
$goodarray = array();
foreach( $badarray as $ba )
{
<?php
/**
*
*
* Factory to create database connections based on URI
*
* URI: dbtype://user:password@server/database
*
*
@jtarleton
jtarleton / paginated_links.php
Created December 9, 2012 21:17
Paginated Links Helper Function
@jtarleton
jtarleton / widgetthing.js
Created December 10, 2012 03:38
jQuery Yahoo-Widget Thing
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#clickme').bind('click', function(){
var q = random();
jQuery('.imgframe').hide();
jQuery('.imgframe').css('background-image', "url('mainpic"+ q +".jpg')" );