Skip to content

Instantly share code, notes, and snippets.

View cbednarski's full-sized avatar

Chris Bednarski cbednarski

View GitHub Profile
@cbednarski
cbednarski / aminator.md
Last active August 29, 2015 13:56
Aminator Chef-Solo Setup Instructions

Aminator

You'll need to create / use a few security groups, IAM roles, etc. I recommend naming them all aminator to make it easy to remember what they're for. If you're following along, I've already set these up.

Security Configuration

Create a IAM Role for AWS EC2 with the following custom security policy:

{

"Statement": [

@cbednarski
cbednarski / mongo_doc.py
Created April 8, 2014 21:27
Lightweight MongoDB abstraction around python classes
class MongoDoc(object):
connection = None
__fields__ = {}
__required__ = []
__optional__ = []
__meta__ = ['_id', 'updated']
def set_data(self, data):
'''
You can set individual fields like this:
@cbednarski
cbednarski / replcheck.php
Created April 30, 2014 05:34
MySQL Replication Healthcheck
<?php
$username = '';
$password = '';
$servers = array(
'127.0.0.1',
);
class ReplicationCheck
{
@cbednarski
cbednarski / rest-routines.go
Last active August 29, 2015 14:13
A demo of goroutines in go.
package main
// This program makes HTTP requests to three different URLs using goroutines.
// You can think of a goroutine as a forked process, and what you should see is
// that slower HTTP calls will appear last in the output, even if they appear
// first in the code.
//
// In my case, bbc.co.uk takes longest to respond and appears last in the
// program's output, even though it appears first in the code.
2015/06/01 17:07:57 Running builder: foo
2015/06/01 17:07:57 ui: ==> test: Running post-processor: testPP
2015/06/01 17:07:57 Flagging to keep original artifact from post-processor 'testPP'
2015/06/01 17:07:57 Running builder: foo
2015/06/01 17:07:57 Running builder: foo
2015/06/01 17:07:57 ui: ==> test: Running post-processor: pp
2015/06/01 17:07:57 Deleting original artifact for build 'test'
2015/06/01 17:07:57 Running builder: foo
2015/06/01 17:07:57 ui: ==> test: Running post-processor: pp
2015/06/01 17:07:57 ui: ==> test: Running post-processor: pp
@cbednarski
cbednarski / gist:ab73a0a4e03ab1b6a37d
Created June 8, 2015 21:12
Test output fail from consul-template
ok github.com/hashicorp/consul-template 0.497s
2015/06/08 13:14:33 [DEBUG] ("file(/var/folders/mt/q5nyhg2x4hvg77ycy189g3g80000gn/T/235240652)") querying file
2015/06/08 13:14:33 [DEBUG] ("file(/var/folders/mt/q5nyhg2x4hvg77ycy189g3g80000gn/T/755766715)") querying file
2015/06/08 13:14:33 [DEBUG] ("file(/var/folders/mt/q5nyhg2x4hvg77ycy189g3g80000gn/T/755766715)") querying file
2015/06/08 13:14:33 [DEBUG] ("file(/var/folders/mt/q5nyhg2x4hvg77ycy189g3g80000gn/T/979158494)") querying file
2015/06/08 13:14:33 [DEBUG] ("file(/var/folders/mt/q5nyhg2x4hvg77ycy189g3g80000gn/T/979158494)") querying file
2015/06/08 13:14:33 [INFO] core: security barrier initialized (shares: 1, threshold 1)
2015/06/08 13:14:33 [INFO] core: post-unseal setup starting
2015/06/08 13:14:33 [INFO] rollback: starting rollback manager
2015/06/08 13:14:33 [INFO] core: post-unseal setup complete
@cbednarski
cbednarski / gist:1038932
Created June 21, 2011 21:21
Filter a file using a regex pattern
<?php
// This script filters the specified file over the specified regex pattern
// Each line that matches will be included in the new file
$source = fopen(__DIR__.'/sourcefile.csv', 'r');
$target = fopen(__DIR__.'/targetfile.csv', 'w');
while($line = fgets($source))
{
@cbednarski
cbednarski / gist:1038955
Created June 21, 2011 21:32
Truncates a string after n character, respecting word boundaries
<?php
/**
* Truncates $string after $length characters, without splitting words.
*
* Inspired by http://stackoverflow.com/questions/250357
*
* @param string $string
* @param integer $length
* @return string
@cbednarski
cbednarski / repro.py
Last active October 8, 2015 22:13
Script to rerun a test to catch a race condition
import re
import subprocess
import os
small_before_re = re.compile("(\w+) /tmp/small")
big_before_re = re.compile("(\w+) /tmp/big")
small_after_re = re.compile("(\w+) small")
big_after_re = re.compile("(\w+) big")
os.putenv("PACKER_LOG", "1")
@cbednarski
cbednarski / gist:3856190
Created October 9, 2012 02:13
Terminal colors with PHP
<?php
// Based on info from:
// - http://www.sitepoint.com/forums/showthread.php?398020-terminal-colors-in-PHP
// - http://www.dzone.com/snippets/colorized-text-php-unix
$colors = array(
'light_red' => "[1;31m",
'light_green' => "[1;32m",
'yellow' => "[1;33m",