Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@jtarleton
jtarleton / crontab
Created January 25, 2013 10:47
Crontab for running jobs 1 minute after the hour
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
@jtarleton
jtarleton / form.html
Last active December 11, 2015 06:29
Renders a symfony sfForm object for Twitter's Bootstrap framework
<!DOCTYPE html>
<html>
<head></head>
<body>
<form class="form-horizontal" action="<?php echo url_for('module/action') ?>" method="post">
<h2>Set of fields</h2>
<?php foreach(array($formObj['field1'], $formObj['field2']) as $sfFormFieldObj): ?>
<?php printAsBootstrapForm($formObj, $sfFormFieldObj); ?>
<?php endforeach; ?>
</form>
@jtarleton
jtarleton / loadhelpers.php
Last active December 11, 2015 05:18
How to call "link_to" and "url_for" outside of the view in symfony 1.4
<?php
/******************************************************************************************
These helpers are required for either:
link_to()
or
url_for()
******************************************************************************************/
@jtarleton
jtarleton / mongobackup.sh
Created January 13, 2013 21:32
mongo backup bash script
#!/bin/bash
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="prod.example.com"
TIMESTAMP=`date +%F-%H%M`
S3_BUCKET_NAME="bucketname"
S3_BUCKET_PATH="mongodb-backups"
# Create backup
$MONGODUMP_PATH --host $HOST
@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
@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 / 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
<?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 / 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
@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...');