Skip to content

Instantly share code, notes, and snippets.

View nicklewis's full-sized avatar

Nick Lewis nicklewis

View GitHub Profile
@nicklewis
nicklewis / gist:d6a1988c0e651111b7dc
Created August 10, 2015 12:07
icfp 2015 power phrases
ei!
tsathoggua
r'lyeh
in his house at r'lyeh dead cthulhu waits dreaming.
ph'nglui mglw'nafh cthulhu r'lyeh wgah'nagl fhtagn.
yuggoth
yoyodyne
cthulhu fhtagn!
ia! ia!
yogsothoth
# Requires the redmine_client gem
#!/usr/bin/env ruby
require 'rubygems'
require 'redmine_client'
NORMAL = "\e[00;00m"
NORMAL_BOLD = "\e[00;01m"
YELLOW = "\e[00;33m"
BORING_CYAN = "\e[00;36m"
@nicklewis
nicklewis / gist:804871
Created January 31, 2011 21:38
An example of aliasing in a singleton class copying a method definition
class MyClass
def my_instance_method
:some_value
end
end
instance = MyClass.new
singleton_class = class << instance; self; end
@nicklewis
nicklewis / brew_completion.rb
Created February 3, 2011 07:15
A bash completion file for Homebrew
#!/usr/bin/env ruby
args = ENV["COMP_LINE"].split /\s+/
# "brew"
args.shift
subcommand = args.shift || ''
arg = args.last || ''
@nicklewis
nicklewis / gist:943824
Created April 27, 2011 06:55
Array#to_proc
class Proc
def *(g)
raise ArgumentError, "arity count mismatch" unless arity == g.arity
proc { |*a| self[*g[*a] ] }
end
end
class Array
def to_proc
map(&:to_proc).reverse.inject(&:*)
@nicklewis
nicklewis / puppet_report_schema.js
Created May 19, 2011 02:42
Puppet Report json_shape schema
{
"report":
[ "object",
{ "members":
{
"host": "string",
"time": "string",
"logs": ["array", {"contents": "log_entry"}],
"metrics": ["dictionary", {"contents": "metric"}],
"resource_statuses": ["dictionary", {"keys": "^[A-Z]\\w*\\[.+\\]$", "contents": "resource_status"}],
@nicklewis
nicklewis / if-puppet-was-more-like-lisp.pp
Created June 14, 2011 05:01
If Puppet was more like Lisp
((file /etc/apache2/apache2.conf
(ensure file)
(source puppet:///modules/apache/apache2.conf)
(notify
(service apache
(ensure running)
(enable true)
(require
(package apache
(ensure latest)))))))
@nicklewis
nicklewis / shuffle_spec.rb
Created September 14, 2011 19:00
Run specs in random order
#!/usr/bin/env ruby
if size_opt = ARGV.index('-s')
seed = ARGV[size_opt+1]
end
seed ||= Time.now.to_i
if clip_opt = ARGV.index('-c')
begin
@nicklewis
nicklewis / binary_search_specs.rb
Created September 14, 2011 20:09
Binary search for order-dependent test failures
#!/usr/bin/env ruby
specs_in_order = File.read('spec_order').split
failing_spec = ARGV.first
specs = specs_in_order[0...specs_in_order.index(failing_spec)]
suspects = specs
RubyFileStat.java:365:in `cmp': java.lang.ClassCastException: org.jruby.RubySymbol cannot be cast to org.jruby.RubyFileStat
from RubyFileStat$i$1$0$cmp.gen:65535:in `call'
from RuntimeHelpers.java:2513:in `invokedynamic'
from RubyComparable.java:117:in `callCmpMethod'
from RubyComparable.java:103:in `op_equal'
from RubyComparable$s$1$0$op_equal.gen:65535:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from EqCallSite.java:37:in `call'
from CallOneArgNode.java:57:in `interpret'