Skip to content

Instantly share code, notes, and snippets.

@zircote
zircote / ApiProblem.php
Last active December 18, 2015 05:19
A PHP Exception to provide the functionality of the `application/api-problem` RFC proposal. This class creates simple JSON [RFC4627] and XML [W3C.REC-xml-20081126] document formats to suit the purpose described in [Problem Details](http://tools.ietf.org/html/draft-nottingham-http-problem).
<?php
/**
* @link http://tools.ietf.org/html/draft-nottingham-http-problem
* @link http://tools.ietf.org/html/rfc5988
*
* @package ApiProblem
* @category Exception
*/
@zircote
zircote / cli.sh
Last active December 17, 2015 21:19
cli warehouseA place for me to keep snippets I like but can never readily remember
ls data/some_path_with_spaces_in_the_name/*.csv| while read name; do
./bin/load_csv.sh "$name" table_name
done
# Only show lines when the value in column number 6 changes.
tail -f some-logfile.log | awk '{if (last!=$6) {print $0}; last=$6}'
#generates php class properties from a tables columns
mysql -B -N -u root my_db -e 'describe table_to_use'|awk '{printf(" \"%s\" => null,\n", $1) }'
<?php
usort($unsortedObjectArray, function( $a, $b ) {
if ($a->weight == $b->weight) {
return 0;
}
return ($a->weight < $b->weight) ? -1 : 1;
});
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@zircote
zircote / ga-analytics.js
Created March 26, 2013 19:47
Get the clientId for the universal analytics
tracker = ga.getByName('tracker')
tracker.get('clientId')
mysql -u username dbname -e 'describe db_table'|awk '{print " protected $"$1";"};'
@zircote
zircote / r53-dyn-dns.sh
Created January 21, 2013 12:07
Automated DNS updates using Route53
#!/bin/sh
ZONE="my-tld.com"
RESOURCE="some-host"
INTERFACE="eth0"
ADDR=$(ifconfig $INTERFACE | grep "inet addr" | awk -F: '{print $2}' | awk '{print$1}')
cli53 rrcreate $ZONE $RESOURCE A $ADDR -x 3600 -r
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.zircote.headlessvm</string>
@zircote
zircote / nginx-marathon.py
Last active November 12, 2015 19:01
Marathon Config writer for NGINX
from jinja2 import Template
import json
import httplib2
import argparse
TEMPLATE = """
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
@zircote
zircote / composer.sh
Created December 13, 2012 16:54
Got tired of finding I was not running latest composer version.
#!/bin/bash
COMPOSER=$(type -p "composer.phar")
if [ -x "${COMPOSER}" ]; then
${COMPOSER} self-update > /dev/null
else
$(type -p "php") -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
fi
${COMPOSER} $@