Skip to content

Instantly share code, notes, and snippets.

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
"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 April 25, 2011 22:08
ActiveModel module for elasticsearch indexing
# class Person
# include SearchableModel
# include SearchableModel::SearchMethods
#
# ...
#
# end
module SearchableModel
# 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 September 21, 2011 23:20
elasticsearch indexing chef
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 October 13, 2011 19:09
script to find rails 3 xss issues
# 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 October 23, 2011 16:43
naive timers in celluloid
module Celluloid
class OneShotTimer
include Celluloid
def initialize(timeout)
@timeout = timeout
end
def fire
puts "fired"
@grantr
grantr / timer_pool.rb
Created October 23, 2011 17:05
celluloid timers using Kernel.select
module Celluloid
class Scheduler
def initialize
read, @write = IO.pipe
@pool = TimerPool.new(read)
at_exit { stop }
end
def start
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 November 18, 2011 00:02
set node attribute status:UP when a chef run succeeds
require "chef/handler"
class StatusAttributeHandler < Chef::Handler
VERSION = "0.0.1"
DEFAULTS = {
:attribute_name => 'status',
:success_status => 'UP'
}