Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@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 / 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 / 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 / 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 / CliParseXml.php
Created December 15, 2012 01:21
Simple CLI script calling an XML parser
<?php
define('XML_PATH', 'foodata.xml');
global $rows, $record, $fdata;
$rows = array();
echo sprintf('Reading XML...');
@jtarleton
jtarleton / sec2hms.php
Created January 2, 2013 16:34
Helper to convert seconds to hours, minutes, and seconds
<?php
//credit: Jon Haworth at laughing-buddha.net (I added the $asArray param)
function sec2hms ($sec, $padHours = false, $asArray = false)
{
// start with a blank string
$hms = "";
// do the hours first: there are 3600 seconds in an hour, so if we divide
<?php
//see helper sec2hms https://gist.github.com/4435891
$start = (float) array_sum(explode(' ', microtime()));
$end = (float) array_sum(explode(' ', microtime()));
$out = sprintf('Execution time: %s %s %s', sec2hms($end - $start), PHP_EOL, PHP_EOL);
@jtarleton
jtarleton / breakdown.sql
Created January 4, 2013 20:13
Distinct values and their occurances
# Break down values of a table by distinct field with the number of times the value occurs
# (e.g. breakdown of distinct users and the number of successful logins for each user)
SELECT session_user, COUNT( session_user ) AS NumOccurrences
FROM sessions
GROUP BY session_user
ORDER BY NumOccurrences DESC
@jtarleton
jtarleton / datatable.html
Last active December 10, 2015 22:38
Basic datatables ajax implementation w/ JSON
<html>
<head>
<script type="text/javascript" src="datatables.js"></script>
</head>
<div class="well box">
@jtarleton
jtarleton / sfFormBootstrapHelper.php
Created January 10, 2013 21:32
Helpers to render Bootstrap HTML for a symfony sfFormField object
<?php
/*
Helpers to render Bootstrap HTML for a symfony sfFormField object.
default input type is text
pass an array of field/widget names for each of the other different input types