Skip to content

Instantly share code, notes, and snippets.

class TreeNode
attr_accessor :nodeType, :value, :children
def initialize(nodeType, value, children=[])
raise Exception unless children.is_a?(Array)
@nodeType = nodeType
@value = value
@children = children
end
end
@chuckg
chuckg / spec_helper.rb
Created December 3, 2012 22:29 — forked from pauljamesrussell/spec_helper.rb
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
require 'rack/test'
describe SampleMiddleware do
include Rack::Test::Methods
let(:inner_app) do
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All good!'] }
end
let(:app) { SampleMiddleware.new(inner_app) }
#!/usr/bin/env python
'''\
Usage: cookbookdiff COOKBOOK_NAME COOKBOOK_VER LOCAL_PATH [--nocolor]
Diff your LOCAL_PATH against what is on the chef server for a
given cookbook and version.
--nocolor: don't pipe output through 'colordiff' (in case you want to pipe to something else)
Examples:
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit
@chuckg
chuckg / 0_reuse_code.js
Created November 28, 2013 19:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@chuckg
chuckg / include_recipe_helper.rb
Last active October 19, 2017 07:33 — forked from hartmantis/spec_helper.rb
ChefSpec/RSpec 3 stubs for testing a recipe in isolation
# Updated for rspec 3.0:
module IncludeRecipeHelper
def enable_stubbed_include_recipe
# Don't worry about external cookbook dependencies
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends)
# Test each recipe in isolation, regardless of includes
@included_recipes = []
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?).and_return(false)
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |recipe, included_recipe|