Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@jtarleton
jtarleton / GenericSymfonyForm.class.php
Created December 14, 2012 23:56
Generic Symfony 1.x Form
<?php
class GenericSymfonyForm extends sfForm
{
static public $choices;
public function configure()
{
$this->disableCSRFProtection();
@jtarleton
jtarleton / examplevhost
Created December 14, 2012 23:47
Example virtual host for Apache2
<VirtualHost *:80>
ServerAdmin foo@localhost
ServerName foo.domain.net
DocumentRoot /home/foouser/project/web
<Directory />
Options FollowSymLinks
@jtarleton
jtarleton / dumptables.sh
Created December 14, 2012 23:28
Shell script to dump MySQL as a gzipped file for each table
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 <database> [output-path]"
exit 1
fi
TABLES=`mysql -h localhost -u someuser -p somepasswd "select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='$1'"`
OUT="$2"
@jtarleton
jtarleton / GenericWebTest.class.php
Created December 13, 2012 18:46
Functional Web Tests using Selenium Framework / PHPUnit
<?php
/*
Selenium Testing Requirements:
- phpunit 3.7+
- Selenium test case extension to PHPUnit installed with pear:
~ pear install phpunit/Selenium_Test_Case
@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')" );
@jtarleton
jtarleton / paginated_links.php
Created December 9, 2012 21:17
Paginated Links Helper Function
<?php
/**
*
*
* Factory to create database connections based on URI
*
* URI: dbtype://user:password@server/database
*
*
@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 )
{
@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 / 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',