Skip to content

Instantly share code, notes, and snippets.

View jgn's full-sized avatar
☂️
Messing around.

John Norman jgn

☂️
Messing around.
View GitHub Profile

Stuff I learned about Puppet

Chef vs Puppet

  • My blink is that in 2012 Puppet is safer and more productive.
  • Puppet is declarative, Chef procedural.
  • Puppet brings system into compliance (state), Chef "does" things (recipes).
  • Puppet has strong security practices; Chef has a toleration for loose security in Chef itself.
  • Puppet makes it very hard to get "outside the lines" or violate its strong opinions; in Chef this is routine.
@jgn
jgn / erbed_steps.rb
Created February 10, 2012 12:04
If you have ever wanted to run a step through ERB . . .
require 'erb'
When /\A\(erb\) (.*)\z/ do |*matches|
s = ERB.new(matches[0]).result(binding)
if matches.size > 1
s = <<-MULTI
#{s}
"""
#{ERB.new(matches[1]).result(binding)}
"""
@jgn
jgn / cached_hash.rb
Created February 7, 2012 13:59
Cached hash
class CachedHash
extend ActiveSupport::Memoizable
def initialize(cache_key)
@cache_key = cache_key
end
def [](key)
fetch[key]
end
@jgn
jgn / cached_sequence.rb
Created February 7, 2012 13:58
Cached sequence
class CachedSequence
extend ActiveSupport::Memoizable
def initialize(cache_key)
@cache_key = cache_key
ensure_value
end
def next
Rails.cache.increment(cache_key)
@jgn
jgn / upgrade_postgres_9.0-9.1.sh
Created January 16, 2012 14:43 — forked from databyte/upgrade_postgres_9.0-9.1.sh
Upgrade PostgreSQL from 9.0 to 9.1
#!/bin/sh
#
# Upgrade PostgreSQL from 9.0 to 9.1
#
# by David Sommers
#
brew update postgres
@jgn
jgn / gist:1326821
Created October 31, 2011 03:06 — forked from davist11/gist:1204569
Campfire sounds
crickets: "hears crickets chirping"
drama: "https://123.campfirenow.com/images/drama.jpg"
greatjob: "https://123.campfirenow.com/images/greatjob.png"
live: "is DOING IT LIVE"
pushit: "https://123.campfirenow.com/images/pushit.gif"
rimshot: "plays a rimshot"
secret: "found a secret area :key:"
tada: "ta-da! :flags:"
tmyk: ":sparkles: :star: The More You Know :sparkles: :star:"
trombone: "plays a sad trombone"
@jgn
jgn / test.txt
Created September 23, 2011 02:20
Test
@jgn
jgn / mrisc.rb
Created July 7, 2011 16:49 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
@jgn
jgn / reverse.js
Created July 1, 2011 17:36
"Extending" a native JavaScript "class"
<script>
(function(){
// http://webreflection.blogspot.com/2008/10/subclassing-javascript-native-string.html
function MyString(__value__) {
this.length = (this.__value__ = __value__ || "").length;
};
with(MyString.prototype = new String)
toString = valueOf = function() { return this.__value__ };
@jgn
jgn / OrderedSet
Created April 10, 2011 03:28
OrderedSet leveraging ActiveSupport::OrderedHash to get predictable behavior across 1.8.x, 1.9.x
# Force the underlying store for a Set to be an OrderedHash.
class OrderedSet < Set
def initialize(enum = nil, &block)
@hash ||= ActiveSupport::OrderedHash.new
super
end
end