Skip to content

Instantly share code, notes, and snippets.

View jodell's full-sized avatar

Jeffrey ODell jodell

View GitHub Profile
@jodell
jodell / stddev.rb
Created October 21, 2011 01:03
Standard Deviation
module Enumerable
def sum(&blk)
map(&blk).reduce(0) { |sum, element| sum + element }
end
def mean
sum.to_f / size.to_f
end
def variance
@jodell
jodell / gist:1299788
Created October 19, 2011 21:47
host availability
Timeout::timeout(@timeout) do
sleep 2 while rack_node.refresh && rack_node.status != 'ACTIVE'
sleep 2 while !(TCPSocket.new(rack_node.addresses[:public].first, 22) rescue nil)
end
@jodell
jodell / shmsetup.sh
Created October 13, 2011 18:54
kernel shared memory calculator
#!/bin/bash
# http://archives.postgresql.org/pgsql-admin/2010-05/msg00285.php
# Output lines suitable for sysctl configuration based
# on total amount of RAM on the system. The output
# will allow up to 50% of physical memory to be allocated
# into shared memory.
# On Linux, you can use it as follows (as root):
#
# ./shmsetup >> /etc/sysctl.conf
@jodell
jodell / class-ext.rb
Created September 14, 2011 15:44
private method testing (if you have to)
# http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
require 'rubygems'
require 'dust'
require 'test/unit'
class Ninja
private
def kill(num_victims)
"#{num_victims} victims are no longer with us."
@jodell
jodell / gist:1162991
Created August 22, 2011 17:37
Ignition Launch
var days = Math.floor((new Date(2011,9,26) - new Date()) / 1000 / 60 / 60 / 24);
var sprints = days / 14.0
"There are " + days + " days left until 10/26 (" + sprints + " 2-week sprints)";
@jodell
jodell / detach_for_UI_update.m
Created August 19, 2011 19:28
fork to update the UI (Activity Indicator, for example)
// Detach to update the UI, example takes a BOOL argument
[NSThread detachNewThreadSelector:@selector(setIsWaiting:)
toTarget:self
withObject:[NSNumber numberWithBool:YES]];
@jodell
jodell / disable_backups.rb
Created July 27, 2011 15:15
toggle itunes backups
#!/usr/bin/env ruby
# http://hboon.com/speeding-up-itunes-iphone-synchronization/
# defaults write com.apple.iTunes DeviceBackupsDisabled -bool true
# To re-enable backup:
# defaults write com.apple.iTunes DeviceBackupsDisabled -bool false
case ARGV[0]
when /on|true|1/i
`defaults write com.apple.iTunes DeviceBackupsDisabled -bool true`
puts "CAUTION: Disabling iTunes Backups!"
@jodell
jodell / bbr.txt
Created July 25, 2011 03:08
Breaking Bad Rhymes
Walter White's gotta push that blue
Til there ain't shit but red to do
That's no ice cream or a picnic
He's firecrackin' you're on the hitlist
Dexter's lost, to step to Albuquerque
I'm like the smoke monster, no way to merk me
What's your men so mad about Mr. Draper?
Yo got two Emmy's now, ain't that a caper?
Doctor's got his house, but now he's in mine
/* Sort Example */
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"createdAt"
ascending:NO] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [eventArray sortedArrayUsingDescriptors:sortDescriptors];
_events = [[NSMutableArray alloc] initWithArray:sortedArray];
@jodell
jodell / set_trace_func.rb
Created June 22, 2011 21:00
expensive function tracing
set_trace_func proc { |event, file, line, id, binding, classname|
#cpu = `ps auxfh | grep #{$$} | grep -v tracer | grep -v grep | awk '{print $3}'`.strip
fid ||= File.open("/tmp/tracer.#{$$}", 'a+')
fid.puts "[%s][%s] %8s %s:%-2d %10s %8s\n" % [Time.now, '', event, file, line, id, classname] if file.match(/srv/) && !file.match(/vendor\/|usr\/local\/lib/)
}