Skip to content

Instantly share code, notes, and snippets.

View caius's full-sized avatar
👻

Caius Durling caius

👻
View GitHub Profile
class CucumberExternalResqueWorker
DEFAULT_STARTUP_TIMEOUT = 1.minute
COUNTER_KEY = "cucumber:counter"
class << self
attr_accessor :pid, :startup_timeout
def start
# Call from a Cucumber support file so it is run on startup
return unless Rails.env.cucumber?
@caius
caius / gist:723293
Last active September 24, 2015 08:58
~/bin/rinse_cpus
#!/usr/bin/env ruby
# Only works on OS X
# Spins up enough `yes > /dev/null` instances inside a
# `screen` to use 100% of all your cpu cores
#
# This just starts screen eating your cores, currently
# when you're done you need to kill the screen manually.
require "tempfile"
anonymous
anonymous / gist:731854
Created December 7, 2010 14:52
# monit starts with a blank path, so need to declare full paths to stuff
check process beefeating_unicorn_rails with pidfile /home/paul/public/beefeatingmonkeys.com/shared/pids/unicorn.pid
start program = "/bin/su - paul -c 'cd /home/paul/public/beefeatingmonkeys.com/current;/home/paul/.rvm/gems/ree-1.8.7-2010.02@beefeatingmonkeys/bin/unicorn_rails -D -E production -c config/unicorn.rb'"
stop program = "/usr/bin/killall -9 unicorn_rails" as uid paul and gid paul
if totalmem is greater than 300 Mb for 5 cycles then alert
if cpu is greater than 50% for 2 cycles then alert
if cpu is greater than 80% for 3 cycles then restart
if loadavg(5min) greater than 10 for 8 cycles then restart
@ahoward
ahoward / net-http-debug.rb
Created December 10, 2010 20:06
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
<phoenixrises> tamonten: you is dad nao?
<tamonten> phoenixrises: not yet, but today
<Will|> tamonten 2.0 planned for release today?
<Will|> I hope everything goes well, no last minute bugs :)
<phoenixrises> Will|: child birth isn't like your code ;)
<tamonten> well the release date has already slipped, so I'm hoping there was some extra QA done during that time
<phoenixrises> tamonten: would hope so, after failing the penetration test 9months ago, you never know what could be going on
<tamonten> I think you'll find the penetration test was very successful :P
<phoenixrises> tamonten: considering in pen testing you /dont/ want to be able to get in, I think not :P
<tamonten> lets leave that analogy before someone mentions backdoors in the system shall we?
desc "Start the resque web interface"
task "resque:web" do
`rake isolate:sh['resque-web']`
end
# Task used to preload what's needed for the workers to run properly
task "resque:setup" do
require File.expand_path(File.join(File.dirname(__FILE__), "../../loaders/gem_sandboxing"))
require File.expand_path(File.join(File.dirname(__FILE__), "../../loadpath_initializer"))
require File.expand_path('../../../core/loaders/console_initializer', File.dirname(__FILE__))
#kch: Do we really not have a helper method for array.inject({}){|h,(k,v)|h[k]=v;h}? Not a day goes by that I don't type this.
array = [[1, 2], [3, 4]]
array.inject({}) {|h,(k,v)| h[k]=v; h } # => {1=>2, 3=>4}
Hash[*array.flatten] # => {1=>2, 3=>4}
@tenderlove
tenderlove / campfire.rb
Created February 16, 2011 23:43
This only works on 1.9.2
require 'uri'
require 'psych'
require 'net/http'
require 'meme' # Install meme_generator
module Campfire
class API
attr_reader :uri, :token, :pass
@alloy
alloy / status_bar_view.rb
Created March 30, 2011 09:10
A MacRuby example of a custom view in the status bar, with selection highlight.
class StatusBarView < NSView
attr_reader :progressIndicator, :statusBarItem
def initWithStatusBarItem(item)
bar = item.statusBar
if initWithFrame([[0,0], [bar.thickness, bar.thickness]])
@statusBarItem = item
@highlight = false
origin, size = frame.origin, frame.size