Skip to content

Instantly share code, notes, and snippets.

View jespada's full-sized avatar

jespada jespada

View GitHub Profile
@ranjib
ranjib / chef_validator_migration.md
Last active December 18, 2015 11:59
Migrating chef-validator client

Grab the validation client in json format from old chef server

knife client show chef-validator -c knife-chef-server-10.rb -Fj > chef-validator.json

Upload the validation client to new chef server, delete the existing validation client from new chef server first, as update(PUT) is not allowed, only create(POST) is allowed

knife client delete chef-validator -y -c knife-chef-server-11.rb
require 'chef'
Chef::Config.from_file('knife.rb')
envs = Chef::Environment.list.keys
q = Chef::Search::Query.new
envs.each do |e|
constrained_cookbooks = Chef::Environment.load(e).cookbook_versions.keys
all_cookbooks =[]
nodes = q.search(:node, "chef_environment:#{e}").first.reject(&:nil?)
nodes.select{|n| n.attribute?(:recipes)}.each do |n|
n.recipes.map{|r| r.split('::')[0]}.each do |cookbook|
@aphyr
aphyr / gist:5494135
Last active December 16, 2015 20:39
This is a postgres app which inserts 800 unique rows into a table, one per transaction. There are no conflicts. We cause a partition around write #32, which causes some connections to fail during a transaction. If Postgres has committed the transaction, but the message acknowledging that commit to the client is dropped, the client has no knowled…
Writes completed in 26.395 seconds
800 total
765 acknowledged
770 survivors
5 unacknowledged writes found! ヽ(´ー`)ノ
(30 31 32 33 34)
0.95625 ack rate
0.0 loss rate
0.006535948 unacknowledged but successful rate
@fnichol
fnichol / shell.sh
Created April 23, 2013 16:41
Test Kitchen with bats - A Lightning Guide
SUITE_NAME=default
# create a bats subdirectory under your desired suite
mkdir -p test/integration/$SUITE_NAME/bats
# create an initial "canary" bats test file
# more examples at:
# * https://github.com/fnichol/chef-rvm/tree/master/test/integration/rubies/bats
# * https://github.com/fnichol/chef-ruby_build/tree/master/test/integration/alltherubies/bats
# * https://github.com/sstephenson/bats
@logikal
logikal / speakernotes.md
Created March 29, 2013 17:43
Monitorama Speaker notes list
@aphyr
aphyr / gist:5198654
Created March 19, 2013 18:17
Thoughts on configuration file complexity.

Some people think that configuration should not be "Turing complete"; others think the configuration language should be as expressive as possible--so much so that it amounts to a programming language itself.

I assert that configuration files which are not Turing complete (or, perhaps a more useful distinction, are not "sufficiently complex languages") are in practice extended to be that complex; and when that happens, the result is often more difficult to understand than if the language were more powerful to start with.

@fujin
fujin / ruby.el
Created March 15, 2013 22:36 — forked from chrisroberts/gist:5173018
Fix the fucking indentation rules for ruby-mode
(setq ruby-deep-indent-paren nil)
(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))
@kixorz
kixorz / aws_iam_policy.json
Last active May 5, 2026 07:20
Update Route53 DNS records from your EC2 instance using this simple Ruby script. You can call it from rc.local after setting your hostname locally. First parameter is the desired <hostname>.<domain> Domain and other parameters are hardcoded. This script is useful for handling internal DNS changes in your systems after instance changes. Attached …
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [
# My take on Mike's source_for method.
# (see http://pragmaticstudio.com/blog/2013/2/13/view-source-ruby-methods)
#
# (1) I named it 'src' rather than source_for (ok, I'm a lazy typer).
# (2) The edit function was broken out as a separate function.
# (3) The edit function is for emacs
# (4) If the method is not defined on the object, and the object
# is a class, then see if it is an instance method on the class.
#
# The fourth point allows my to say:
require 'connection_pool'
require 'redis'
require 'metriks'
class RedisClientWrapper
def initialize(options)
@options = options.delete(:pool)
@pool = ConnectionPool.new(@options) do
::Redis.new(options)
end