Skip to content

Instantly share code, notes, and snippets.

@zircote
zircote / test-before-observing.php
Created June 18, 2013 16:08
ProTip: Test the key exists before accessing the value in the switch.
<?php
switch (isset($headers['content-type']) && $headers['content-type']) {
case 'application/xml':
$format = 'XML';
break;
case 'application/json':
default:
$format = 'JSON';
}
@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')
@zircote
zircote / cake-example.php
Created March 22, 2013 20:14
I am not familiar with cake; however based on the example I was given this should produce the desired result.
<?php
use Swagger\Annotations as SWG;
App::uses('AppController', 'Controller');
/**
* Users Controller
* @SWG\Resource(
* apiVersion="0.2",
* swaggerVersion="1.1",
* basePath="http://api.myhost.local/api",
* resourcePath="/users"
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>