Skip to content

Instantly share code, notes, and snippets.

View sarogers's full-sized avatar
🎗️

Spencer Rogers sarogers

🎗️
View GitHub Profile
@sarogers
sarogers / gist:2306906
Created April 5, 2012 00:37
ps | grep /term/ and kill matched lines
#!/bin/bash
PIDS=$(ps | grep $1 | awk '{print $1}')
echo PIDS: $PIDS
for p in $PIDS
do
echo Killing pid $p
kill -9 $p
@sarogers
sarogers / Monit to the Resque
Created April 29, 2012 04:11
Monit script for restarting our Resque workers.
check process resque_worker
with pidfile /home/USER_NAME/dp20/current/tmp/pids/resque_worker.pid
start program = "/usr/bin/env HOME=/home/USER_NAME RACK_ENV=production PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd /home/USER_NAME/dp20/current; nohup bundle exec rake environment resque:work RAILS_ENV=production QUEUES=record_event,update_counter_cache VERBOSE=1 PIDFILE=tmp/pids/resque_worker.pid & >> log/resque_worker.log 2>&1'" as uid USER_NAME and gid USER_NAME
stop program = "/bin/sh -c 'cd /home/USER_NAME/dp20/current && kill -9 $(cat tmp/pids/resque_worker.pid) && rm -f tmp/pids/resque_worker.pid; exit 0;'"
if totalmem is greater than 300 MB for 10 cycles then restart # eating up memory?
group resque_workers
@sarogers
sarogers / In-Place Ruby Quicksort
Created May 6, 2012 03:45
An in-place implementation of quicksort in Ruby.
def my_quicksort(array)
left = 0
right = array.length - 1
quicksort(array, left, right)
end
def quicksort(array, left, right)
if left < right
pivot_index = ((right + left).to_f / 2).ceil
@sarogers
sarogers / in-place-quicksort.clj
Last active January 20, 2016 18:27
An in-place implementation of quicksort in Clojure.
(use '[clojure.contrib.math :as math])
(defn my_quicksort [array]
; Create a new mutable data structure
(def transientArray (transient array))
(quicksort transientArray 0 (- (count array) 1))
; Return an immutable data structure
(persistent! transientArray)
@sarogers
sarogers / gist:5773303
Created June 13, 2013 12:29
Ruby 2.0.0 mountain lion rbenv install with brew OpenSSL
RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p195
# Complete the "my_each" method.
def my_each
end
describe "my_each" do
it "should let us iterate over a collection of objects and do stuff" do
students = [
{ name: 'Rachael' },
{ name: 'Josephina'},
# Complete the "my_each" method.
def my_each(collection)
length = collection.length
i = 0
while i < length
yield(collection[i])
i = i + 1
end
require_relative './jukebox'
RSpec.configure do |config|
config.color_enabled = true
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
def capture_stdout(&block)
require 'rspec'
# # Binary Secret Handshake
# > There are 10 types of people in the world: Those who understand binary, and those who don't.
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake".
# ```
# 1 = wink
# 10 = double blink
@after_blocks = []
def after_bundler(&block); @after_blocks << block; end
gem_group :development, :test do
gem "rspec-rails"
gem "factory_girl_rails"
gem "pry"
end
after_bundler do