Skip to content

Instantly share code, notes, and snippets.

View itsderek23's full-sized avatar

Derek Haynes itsderek23

View GitHub Profile
class OpenFileDescriptors < Scout::Plugin
def build_report
report :open_files => `lsof | wc -l`
end
end
@itsderek23
itsderek23 / monitored_job.rb
Created April 10, 2014 21:03
Run the desired command, ping Deadman's Snitch when completed, report to Sentry on exception.
module MonitoredJob
def self.run(command, ping_url)
eval(command)
self.ping_twice(ping_url)
return "SUCCESS"
rescue => e
Raven.capture_exception(e)
return "'#{command}' could not run: #{e.message}\n#{e.backtrace}"
end
@itsderek23
itsderek23 / starter_plugin.rb
Created September 6, 2014 17:18
Sample Scout Plugin
class SimplePlugin < Scout::Plugin
def build_report
time = Time.new
report(:hour => time.hour, :minute => time.min)
end
end
/usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/filter/timespan.rb:35:in `<=': comparison of Fixnum with nil failed (ArgumentError)
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/filter/timespan.rb:35:in `filter'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/controller.rb:291:in `filter_request'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/controller.rb:290:in `each'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/controller.rb:290:in `filter_request'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/controller.rb:322:in `run!'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_analyzer/source/log_parser.rb:272:in `handle_request'
from /usr/lib/ruby/gems/1.8/gems/request-log-analyzer-1.6.2/bin/../lib/request_log_
class File
alias_method :gets_original, :gets
# The size of the reads we will use to add to the line buffer.
MAX_READ_SIZE=1024*100
#
# This method returns the next line of the File.
#
# It works by moving the file pointer forward +MAX_READ_SIZE+ at a time,
# storing seen lines in <tt>@line_buffer</tt>. Once the buffer contains at
@itsderek23
itsderek23 / gist:582635
Created September 16, 2010 15:37
Sample Raplet Rails Controller Action
def raplet
html=""
email=params[:email]
if retrieve_user
html=render_to_string :layout=>false
end
res={:html=>html,:status=>200, :css=>'a{color:blue} ul{padding-left:20px;margin:4px 0;} link{color:blue;cursor:hand}', :js=>"$('.details-link').click(function(){ $('#'+this.id.replace('l','a')).toggle()})"}
render :text=>params[:callback]+"("+res.to_json+")"
end
@itsderek23
itsderek23 / gist:1125365
Created August 4, 2011 15:01
Objective-C - Stripping New Lines
NSString *string = @"Lion says:\nRoar!\nGrowl!";
NSMutableString *mstring = [NSMutableString stringWithString:string];
NSLog(@"before: %@",mstring);
NSRange wholeShebang = NSMakeRange(0, [mstring length]);
[mstring replaceOccurrencesOfString: @"\n"
withString: @""
options: 0
range: wholeShebang];
string = "Lion says:\nRoar!\nGrowl!"
string.gsub("\n",'')
NSString *appName = @"Redwood: ";
NSString *tagline = @"OSX Spotlight for the cloud.";
NSString *message = [appName stringByAppendingString:tagline];
app_name = "Redwood: "
tagline = "OSX Spotlight for the cloud."
message = app_name + tagline