Skip to content

Instantly share code, notes, and snippets.

Grant Rodgers grantr

Block or report user

Report or block grantr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:577798
if node[:ec2][:ephemeral][:devices].include?("/dev/sdd")
# if we also have sdd and sde, raid0 them and put data there
data_raid_block_devs = [ "/dev/sdd", "/dev/sde" ]
data_raid_mountpoint = "/mnt/cassandra_data"
data_raid_dev = "/dev/md0"
data_file_dir = Array(node[:cassandra][:data_file_dirs]).first
package "mdadm" do
action :install
View gist:674619
"map": "function(doc) { if (doc.type == 'lock') { emit(doc.message_id, null) } else { emit(doc._id, doc) } }",
"reduce": "function(keys, values, rereduce) { if (values.length == 1) return values[0] }"
grantr / searchable_model.rb
Created Apr 25, 2011
ActiveModel module for elasticsearch indexing
View searchable_model.rb
# class Person
# include SearchableModel
# include SearchableModel::SearchMethods
# ...
# end
module SearchableModel
View oneshot.rb
# use for oneshot recipes
if node[:oneshot]
# clear oneshot and save node
oneshot, node[:oneshot] = node[:oneshot], []
oneshot.each do |recipe|
include_recipe recipe
grantr / gist:1233599
Created Sep 21, 2011
elasticsearch indexing chef
View gist:1233599
curl -XPUT localhost:9200/_river/couch/_meta -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "chef",
"filter" : null,
"script": "ctx._type = ctx.doc.chef_type"
"index" : {
grantr / xss_finder.rb
Created Oct 13, 2011
script to find rails 3 xss issues
View xss_finder.rb
# run from rails root
Dir.glob("app/views/**/*.*").each do |filename| do |f|
f.each_with_index do |line, i|
line.scan /[^"]"([^"]+)"/ do |match|
m = match.first
puts "#{f.path} :#{i+1} #{m}" if m =~ /(<[^%]|[^=%]>)/
grantr / timer.rb
Created Oct 23, 2011
naive timers in celluloid
View timer.rb
module Celluloid
class OneShotTimer
include Celluloid
def initialize(timeout)
@timeout = timeout
def fire
puts "fired"
grantr / timer_pool.rb
Created Oct 23, 2011
celluloid timers using
View timer_pool.rb
module Celluloid
class Scheduler
def initialize
read, @write = IO.pipe
@pool =
at_exit { stop }
def start
View spec.out
behaves like a Celluloid Mailbox
receives messages
raises system events when received
prioritizes system events over other messages
selectively receives messages with a block
looks up remote actors (FAILED - 1)
grantr / status_attribute_handler.rb
Created Nov 18, 2011
set node attribute status:UP when a chef run succeeds
View status_attribute_handler.rb
require "chef/handler"
class StatusAttributeHandler < Chef::Handler
VERSION = "0.0.1"
:attribute_name => 'status',
:success_status => 'UP'
You can’t perform that action at this time.