Skip to content

Instantly share code, notes, and snippets.

View jfredett's full-sized avatar

Joe Fredette jfredett

View GitHub Profile
@jfredett
jfredett / bous.hs
Created July 1, 2011 02:30
Boustrophedon Transform in Haskell
-- Boustrophedon Transform in 1 line of haskell. Shove this in your GHCI, it will give you a function `pp`
-- which takes a function f :: Num a => (Integer -> a) and a depth v :: Num a => a, the former is the
-- sequence to transform, the latter is the depth of the tree to create.
-- I suggest running the results through mapM_ (putStrLn.show), it'll pretty print each level of the tree
-- in order.
let pp f v = let b s k n = if n==0 then s k else (b s k (n-1)) + (b s (k-1) (k-n)) in (\s k -> [[b s n' k' | k<-[1..n']]|n'<-[1..l]]) f v
@jfredett
jfredett / hack.sh
Created April 1, 2012 02:28 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
require 'minitest/autorun'
###
# Test to demonstrate TCO in Ruby. Tested in 1.9.2+
class TestTCO < MiniTest::Unit::TestCase
code = <<-eocode
class Facts
def fact_helper(n, res)
if n == 1
res
@jfredett
jfredett / gist:2400475
Created April 16, 2012 18:18 — forked from kevinzen/gist:2400225
Advice on DRYing this test up?
# Here's how I might do it, though I'd probably skip the shared_examples and just duplicate them. I feel
# like it hides things a bit too much otherwise. Given that it doesn't represent a _huge_ extraction, I wouldn't
# mind the duplication.
#
# I'm pretty sure that subject is preserved across shared example calls, if it's not, you might need to improvise.
#
shared_examples_for "Firefox browser" do
its(:browser) { should == "Firefox" }
its(:security) { should == :strong }
@jfredett
jfredett / 0001-add-specs-for-Time-round.patch
Created June 15, 2012 17:36
[PATCH] add specs for Time#round
From 91c5562dc68d2b9f067b4bce76c14eff9e216cfc Mon Sep 17 00:00:00 2001
From: Joe Fredette <jfredett@gmail.com>
Date: Fri, 15 Jun 2012 13:28:43 -0400
Subject: [PATCH] add specs for Time#round
---
spec/ruby/core/time/round_spec.rb | 54 ++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/spec/ruby/core/time/round_spec.rb b/spec/ruby/core/time/round_spec.rb
@jfredett
jfredett / gist:3986962
Created October 31, 2012 13:14
In-memory Software Transactions
lass TransactionalHash < Hash
def transaction
old = dup
begin
return tap { yield(self) }
rescue Exception => e
clear
old.each do |k,v|
self[k] = v
end
@jfredett
jfredett / assertion backtrace
Created November 8, 2012 13:59
dump from thread apply all bt
#0 0x00007fff918f2212 in __pthread_kill ()
#1 0x00007fff93f33b34 in pthread_kill ()
#2 0x00007fff93f77dfa in abort ()
#3 0x00007fff93f78dd5 in __assert_rtn ()
#4 0x0000000100248b07 in rubinius::MethodCacheEntry::create (state=0x101604d50, klass=0x108a4a0c0, mod=0x108a4a0c0, exec=0x1a, method_missing=rubinius::eNone, super=false) at cache.cpp:16
#5 0x000000010005e1c1 in rubinius::InlineCache::fill_private (this=0x108c1c910, state=0x101604d50, name=0x2fce, start=0x108a4a0c0, klass=0x108a4a0c0, mce=@0x7fff5fbadcf8, super=false) at inline_cache.cpp:165
#6 0x000000010005e9e3 in rubinius::InlineCache::empty_cache_private (state=0x101604d50, cache=0x108c1c910, call_frame=0x7fff5fbafde0, args=@0x7fff5fbaf290) at inline_cache.cpp:402
#7 0x000000010005f42c in rubinius::InlineCache::initialize (this=0x108c1c910, state=0x101604d50, call_frame=0x7fff5fbafde0, args=@0x7fff5fbaf290) at inline_cache.hpp:201
#8 0x000000010005bd35 in rubinius::InlineCache::check_cache (state=0x101604d50, cache=0x108c1c910, call_frame=
@jfredett
jfredett / gist:4043418
Created November 9, 2012 02:51
Replicate RBX Crash
#requires rspec gem to be available, that's it.
require 'rspec'
class FailingClass
def self.create
new
end
end
FailingClass.private_class_method :new, :allocate
# Version 2 -- the cool version
require 'redis'
require 'forwardable' #standard ruby library
class RedisTester
# this way, we create the instance and check to see it's running every time
# we ask for it automatically.
def redis
@redis ||= Redis.new
raise unless redis_is_running?
@redis
@jfredett
jfredett / gist:5039822
Created February 26, 2013 16:28 — forked from jgn/gist:2758806

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.