Skip to content

Instantly share code, notes, and snippets.

View msonnabaum's full-sized avatar

Mark Sonnabaum msonnabaum

  • Lithic
  • San Diego, CA
View GitHub Profile
#!/usr/bin/env ruby
require "optparse"
DEFAULT_QUANTILES = [0.25, 0.50, 0.75, 0.90, 0.95, 0.99, 0.999]
def quantile(values, p, presorted = false)
return values.first if values.size == 1
values = values.sort unless presorted
hh = (values.size - 1) * p + 1
h = hh.floor
#!/usr/bin/env php
<?php
$whitelist = [
"main()",
"MemcachePool::get",
"PDOStatement::execute",
"PDO::commit",
"DatabaseStatementBase::execute",
"InsertQuery_mysql::execute",
#!/usr/bin/env php
<?php
$file_contents = file_get_contents("php://stdin");
$data = unserialize($file_contents);
$results = [];
foreach ($data as $key => $values) {
list($caller, $callee) = explode('==>', $key);
def bsearch_index(ary)
low = 0
high = ary.length
smaller = 0
satisfied = 0
while low < high
mid = low + ((high - low) / 2)
val = ary[mid]
begin
#!/usr/bin/ruby
require "csv"
class Array
def sum
inject(nil) { |sum,x| sum ? sum+x : x }
end
def average
#!/bin/sh
MYSQLDUMP_DIR='/Users/blah/Sites/db_backups'
CURDATE=`date +%F`
for SITE in $(ls sites/)
do
if [[ -f sites/${SITE}/settings.php ]]
then
# Retreive DB information from settings.php file
DBURL=$(grep '^$db_url' sites/${SITE}/settings.php | sed "s#.*'\(.*\)'#\1#")
#!/usr/bin/env ruby
require 'statgrab'
require 'json'
sg = Statgrab.new
stats = {}
#puts "#{sg.memory[:free]/1024}m"
#puts sg.memory.to_json()
#!/bin/bash
LATEST=$(curl -o - http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/LATEST)
WGET=$(which wget)
${WGET} "http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/${LATEST}/chrome-mac.zip"
if [[ -f "chrome-mac.zip" ]]
then
unzip chrome-mac.zip
fi
#!/usr/bin/ruby
require 'rubygems'
require 'gdata'
require 'zlib'
require 'fastercsv'
require 'twitter'
=begin
This script was used at DrupalCamp Dallas 09 to post schedule changes made on a google spreadsheet to twitter.
=end
<?php
/**
* Implementation of hook_ctools_context_convert_list().
*/
function misc_ctools_context_convert_list($plugin, &$converters) {
if ($plugin['name'] == 'node') {
$converters = $converters + array('field_firstname' => t('First Name'), 'field_lastname' => t('Last Name'));
}
return $converters;
}