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
end
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
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], []
node.save
oneshot.each do |recipe|
include_recipe recipe
end
end
@grantr
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
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|
File.open(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 =~ /(<[^%]|[^=%]>)/
end
end
@grantr
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
end
def fire
puts "fired"
@grantr
grantr / timer_pool.rb
Created Oct 23, 2011
celluloid timers using Kernel.select
View timer_pool.rb
module Celluloid
class Scheduler
def initialize
read, @write = IO.pipe
@pool = TimerPool.new(read)
at_exit { stop }
end
def start
View spec.out
Celluloid::ZMQ::Mailbox
behaves like a Celluloid Mailbox
receives messages
raises system events when received
prioritizes system events over other messages
selectively receives messages with a block
DCell::Node
looks up remote actors (FAILED - 1)
@grantr
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"
DEFAULTS = {
:attribute_name => 'status',
:success_status => 'UP'
}
You can’t perform that action at this time.