Skip to content

Instantly share code, notes, and snippets.

View bradleybuda's full-sized avatar

Bradley Buda bradleybuda

View GitHub Profile
synchronized (JobTracker.this) {
synchronized (jobs) {
synchronized (taskScheduler) {
for (JobInProgress job: retiredJobs) {
removeJobTasks(job);
jobs.remove(job.getProfile().getJobID());
for (JobInProgressListener l : jobInProgressListeners) {
l.jobRemoved(job);
}
String jobUser = job.getProfile().getUser();
#optimizeContent{:class=>"{url: '#{url_for :overwrite_params =>{:action => action_state }}'}"}
@bradleybuda
bradleybuda / class_fu.rb
Created October 29, 2009 21:42
Ruby Class Redefinition
class Foo #v1
def initialize(value)
@value = value
end
def add
37 + @value
end
end
if true
foo = 1
else
bar = 2
end
puts foo.inspect # output is "1"
puts bar.inspect # output is "nil" - bar is defined even though the if statement always fails
puts baz.inspect # raises NameError
@bradleybuda
bradleybuda / cache_instrumentation.rb
Created January 22, 2010 06:25
simple performance stats on Rails cache usage
class CacheInstrumentation
def self.filter(controller)
begin
cache_timing = { :min => nil, :max => nil, :keys => [], :count => 0, :total => 0.0 }
# redefine Rails.cache.fetch for this request
real_fetch_method = Rails.cache.method(:fetch)
Rails.cache.metaclass.send(:define_method, :fetch) do |*args, &block|
begin
start_time = Time.now.to_f
@bradleybuda
bradleybuda / gist:312934
Created February 24, 2010 00:59
TMail very large attachment handling
# TMail was crashing trying to process very large messages in a regexp
# match to check to see if the message body is UTF-8 or something
# crazy like ShiftJIS or some other Japanese thing. Let's just go
# ahead and assume that we're always dealing with UTF8 messages to fix
# the crash.
#
# This will probably break lots of other things. I am going straight
# to hell for this.
class String
def isutf8
@bradleybuda
bradleybuda / xlsx_to_csv.rb
Created February 25, 2010 01:35
Extract CSVs from an XLSX file with roo
require 'rubygems'
# wow that's a lot of unnecessary dependencies
%w(builder nokogiri rubyzip google-spreadsheet-ruby spreadsheet roo).each { |g| gem g }
require 'roo'
in_file = ARGV.shift
spreadsheet = Excelx.new(in_file)
source /usr/local/share/doc/git-core/contrib/completion/git-completion.bash
# git status with a dirty flag
function __git_status_flag {
git_status="$(git status 2> /dev/null)"
remote_pattern="^# Your branch is (.*) of"
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="⚡"
spacer=" "
brad@brad-laptop:~ $ macirb
irb(main):001:0> framework 'Cocoa'
=> true
irb(main):002:0> app = NSApplication.sharedApplication
=> #<NSApplication:0x8003a8500>
irb(main):003:0> status_bar = NSStatusBar.systemStatusBar
=> #<NSSystemStatusBar:0x8003b8ec0>
irb(main):004:0> item = status_bar.statusItemWithLength(NSVariableStatusItemLength)
=> #<NSStatusItem:0x8003b7c00>
irb(main):005:0> item.title = "Hello MacRuby!"
@bradleybuda
bradleybuda / auto_histogram.rb
Created August 2, 2010 21:10
Friendlier histogram.rb with automatic width and height
require 'histogram'
class AutoHistogram
def initialize
@values = []
end
def push(values)
if values.kind_of? Numeric
@values << values