Skip to content

Instantly share code, notes, and snippets.

View larrywright's full-sized avatar

Larry Wright larrywright

View GitHub Profile

ChefDK, Test Kitchen Driven NTP Cookbook

This gist uses TK+Berkshelf to drive creating a vagrant virts and converging a simple recipe to install and configure NTPd. This is a simple cookbook that has one recipe, one template (for ntp.conf) and one attribute file. It works on Ubuntu 12.04 and CentOS 6.4 (and derviatives) and the attribute file is used to support both distros.

This should work on Mac (where I developed it) and any chef-supported Linux that you can get Vagrant onto (Ubuntu/CentOS).

Because I use ChefDK and Test Kitchen, I can largely ignore setting up Vagrant and Berkshelf and can get right to work on writing recipe code.

NOTE: Modern (7/6/2014) Recipe Generation

Chef 11 introduces event dispatching mechanism, which emits event at different milestones in Chef run (aka lifecycle) , and users can add their custom handlers to hook into these events. Chef formatters already uses this API. For a complete list of currently available events check this

Following is a bare minimal example for adding a custom handler:

chef_event_handler_foo.rb

require 'chef/event_dispatch/base'
class Foo < Chef::EventDispatch::Base
  # lets say hello world when chef run ends
 def run_completed(node)
@larrywright
larrywright / IPInsetLabel.h
Created May 4, 2012 17:59
IPInsetLabel: a simple UILabel subclass that adds padding insets and auto-height-resizing
//
// IPInsetLabel.h
// Instapaper
//
// Created by Marco Arment on 7/23/11.
// Copyright 2011 Instapaper LLC, released to the public domain.
//
#import <UIKit/UIKit.h>
@larrywright
larrywright / Procfile
Created February 25, 2012 16:29 — forked from ngauthier/Procfile
Heroku Serving a Directory
web: ruby serve.rb $PORT
@larrywright
larrywright / chat.rb
Created January 1, 2012 05:17 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@larrywright
larrywright / after_use.sh
Created July 6, 2011 15:33 — forked from dougalcorn/after_use.sh
~/.rvm/hooks/after_use for JRUBY_OPTS
case "$GEM_HOME" in
*jruby*)
# -J-Djruby.reify.classes=true
# JRUBY_OPTS="-J-Djruby.reify.classes=true -J-Xmx512M -J-XX:MaxPermSize=256m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled" ; export JRUBY_OPTS
JRUBY_OPTS="-J-Xmx1024m -J-XX:MaxPermSize=256m " ; export JRUBY_OPTS
;;
esac
@larrywright
larrywright / knife.rb
Created February 20, 2011 05:08 — forked from jbz/knife.rb
# This knife.rb orig. provided by jtimberman@opscode.com - but any mistakes are mine!
current_dir = File.dirname(__FILE__)
platform = "https://api.opscode.com/organizations"
require 'grit'
branch = Grit::Repo.new("#{current_dir}/..").head.name
case branch
function setGlobalFont(fontName) {
console.log('setting font to ' + fontName);
document.body.style.fontFamily = fontName + " !important";
}
$(document).ready(function() {
$.fonts = [
"Arial", "Verdana", "Geneva", "Helvetica", "Helvetica Neue",
"Georgia", "Palatino", "Times New Roman", "Times",
"Courier New", "Courier"
class AppBuilder < Rails::AppBuilder
include Thor::Actions
include Thor::Shell
def test
append_test_gems
rspec
cucumber
jasmine
end
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"