Skip to content

Instantly share code, notes, and snippets.

View gaffneyc's full-sized avatar

Chris Gaffney gaffneyc

  • Dead Man's Snitch
  • Holland, MI
View GitHub Profile
user gaffneyc gaffneyc;
daemon off;
events {
worker_connections 1024;
}
http {
passenger_root /Users/gaffneyc/.rvm/gems/ruby-1.8.7-p330/gems/passenger-3.0.2;
passenger_ruby /Users/gaffneyc/.rvm/wrappers/ruby-1.8.7-p330/ruby;
# run with
# watchr .watchr
watch('^roles/.*\.rb') { |m| role(m[0]) }
watch('^cookbooks/(.+?)/.*') { |m| cookbook(m[1]) }
watch('^d.*bags/(.+?)/.*') { |m| dbags(m[1], m[0]) }
def role(file)
system "knife role from file #{file}"
end
#
# Cookbook Name:: yumrepo
# Definition:: yumrepo
#
# Copyright 2010, Tippr Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
require 'rubygems'
require 'benchmark'
require 'mongo_mapper'
require 'mongoid'
# With GC enabled
# Rehearsal -----------------------------------------------------------
# mongomapper creates 0.350000 0.010000 0.360000 ( 0.374451)
# Mongoid creates 0.210000 0.000000 0.210000 ( 0.224762)
class UserCodeSchedule < ActiveRecord::Base
def send_starting_schedule
send_command('set_schedule', options('start'))
end
def send_ending_schedule
send_command('set_schedule', options('end'))
end
def options(option_type)
# Would love to do this with chef
directory("/home/gaffneyc") do
uid "gaffneyc"
gid "gaffneyc"
mode "0700"
directory(".ssh") do
# implies uid, gid, and mode
template("authorized_keys") do
...
require "rubygems"
require "ffi-rzmq"
Thread.abort_on_exception = true
COUNT = 100
WORKER_COUNT = 2
context = ZMQ::Context.create
producer = Thread.new do
@gaffneyc
gaffneyc / bogon_list.rb
Created August 18, 2012 21:23
Simple ruby class for loading a list of unprovisioned IPv4 addresses and testing if an IP is in that range
require "ipaddr"
require "net/http"
# Q: What is a bogon?
# A: See http://www.team-cymru.org/Services/Bogons/
class BogonList
LIST_URL = "http://www.team-cymru.org/Services/Bogons/fullbogons-ipv4.txt"
def self.addresses
@addresses ||= self.load
@gaffneyc
gaffneyc / node_update_from_file.rb
Created September 28, 2012 16:54
Replace attributes, run_list, and chef_environment for an existing node without losing automatic attributes.
class NodeUpdateFromFile < ::Chef::Knife
deps do
require "chef/node"
require "chef/json_compat"
require "chef/knife/core/object_loader"
end
banner "knife node update from file FILE (options)"
def loader