Skip to content

Instantly share code, notes, and snippets.

View lox's full-sized avatar

Lachlan Donald lox

View GitHub Profile
@lox
lox / sysbench.sh
Created April 27, 2011 21:24
Running a sysbench test against MySQL
sudo aptitude install sysbench
echo "create database sbtest; grant all on sbtest.* to 'sbtest'@'localhost';" | mysql
sysbench --test=oltp --num-threads=10 prepare
sysbench --test=oltp --num-threads=10 run
@lox
lox / dns.rb
Created April 28, 2011 18:54
Creating easy domain references to EC2 instances
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
ACCESS_KEY_ID='BLARGH'
SECRET_ACCESS_KEY='BLARGH'
ZERIGO_EMAIL='BLARGH'
ZERIGO_TOKEN='BLARGH'
ZERIGO_ZONE='BLARGH'
@lox
lox / varnish.rb
Created May 11, 2011 03:34
Varnish plugin for Scout
class VarnishPlugin < Scout::Plugin
def build_report
stats = {}
`varnishstat -1`.each_line do |line|
#client_conn 211980 0.30 Client connections accepted
next unless /^(\w+)\s+(\d+)\s+(\d+\.\d+)\s(.+)$/.match(line)
stats[$1.to_sym] = $2.to_i
end
report(:hitrate => 1 - (stats[:cache_miss].to_f / stats[:cache_hit]))
counter(:backend_success, stats[:backend_conn], :per=>:second)
@lox
lox / pre-commit.php
Created May 17, 2011 23:38
A pre-commit hook that validates PHP and checks for typos
#!/usr/bin/php
<?php
$bannedWords = array_filter(array_map('trim',file('/Users/lachlan/.bannedwords')));
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
@lox
lox / config.ru
Created June 7, 2011 21:41
Rack to PHP bridge
require 'rubygems'
require 'json'
class RubyBridge
def call(env)
response = []
data = JSON.dump(env)
IO.popen("php ./rackup.php", 'r+') do |io|
io.write data
io.close_write
@lox
lox / mixin.php
Created August 24, 2011 01:10
Mixins in PHP
<?php
class Mixin
{
private $__map=array();
public function __call($method, $params)
{
if(!isset($this->__map[$method]))
throw new BadMethodCallException("$method not defined");
@lox
lox / mixin.php
Created September 14, 2011 23:59
An experiment with PHP mixins
<?php
namespace Mixin;
class Mixin
{
private $__map=array();
public function __call($method, $params)
{
@lox
lox / braintree_search_api.php
Created October 31, 2011 01:07
Braintree API
<?php
// original api using static classes
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::orderId()->startsWith('a2d'),
Braintree_TransactionSearch::customerWebsite()->endsWith('.com'),
Braintree_TransactionSearch::billingFirstName()->is('John'),
Braintree_TransactionSearch::status()->in(array(
Braintree_Transaction::AUTHORIZED,
Braintree_Transaction::SETTLED
@lox
lox / watch.rb
Created April 20, 2012 05:57
Watch a local folder and synchronize it with a remote folder over SCP
#!/usr/bin/env ruby
require 'rubygems'
require 'rb-fsevent'
require 'optparse'
require 'net/ssh'
require 'net/sftp'
def watch_directory(sftp, watch_dir, target_dir)
fsevent = FSEvent.new
@lox
lox / varnishtest.rb
Created May 6, 2012 06:26
Varnish::Test syntax
require 'test/unit'
require 'varnish/test'
class HelloWorldTest < Varnish::Test::TestCase
def test_it_says_hello_world
backend = Varnish::Test::Backend.new
backend.expect :get, '/', do |env|
[ 200, {}, "Hello World" ]
end