Skip to content

Instantly share code, notes, and snippets.

View jtarleton's full-sized avatar

James Tarleton jtarleton

View GitHub Profile
@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 / 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 / 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 / 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 / getmysqlbak.sh
Created January 25, 2013 10:50
Shell script to back up MySQL to a Gzipped file
#!/bin/bash
mysqldump -h localhost -u foouser --password=foopass foodb | gzip > /var/db_backup.sql.gz
@jtarleton
jtarleton / getmongobak.sh
Created January 25, 2013 10:52
Shell script to backup mongoDB to "/dump" in the current working directory
#!/bin/bash
cd /var/ && mongodump
@jtarleton
jtarleton / array_fns.js
Created January 29, 2013 17:26
Two high-level functions, "array_search" and "array_unique" for good old Javascript.
function arrayUnique(ar)
{
if(ar.length && typeof ar!=='string')
{
var sorter = {};
var out = [];
for(var i=0,j=ar.length;i<j;i++)
{
if(!sorter[ar[i]+typeof ar[i]])
{
@jtarleton
jtarleton / git.txt
Created January 31, 2013 21:03
Initialize a local git repo, push to master branch of the "origin" repo on a remote server
mkdir prj1
cd prj1
git init
touch README
git add .
git commit -m "Added blank readme"
git remote add origin git@server:prj1.git
git push origin master
@jtarleton
jtarleton / redirect_with_id.js
Created February 14, 2013 20:47
URL redirect after prompt for a GET parameter
<script type="text/javascript">
function getPage(id)
{
id = prompt('Enter ID: ');
window.location.href='http://domain.com/module/action?id=' + id;
return false;
}
</script>
@jtarleton
jtarleton / gist:5541318
Created May 8, 2013 15:40
jQuery "Check All" / "Uncheck All" for an array of checkbox inputs
<script type="text/javascript">
function listen_for_uncheck_all($checkboxes)
{
jQuery('#uncheckalllink').unbind('click').bind('click', function(){
$checkboxes.removeAttr("checked");
jQuery('#uncheckalllink').html('Check All');
listen_for_check_all($checkboxes);