Instantly share code, notes, and snippets.

View const-benchmark.rb
#!/usr/bin/ruby
# Adapted from https://github.com/bbatsov/ruby-style-guide/issues/328#issuecomment-227967489
require 'benchmark'
n = 5000000
$priv_const = ( ARGV[0] == 'priv_const' )
View kernel.spec
# We have to override the new %%install behavior because, well... the kernel is special.
%global __spec_install_pre %{___build_pre}
Summary: The Linux kernel
# For a stable, released kernel, released_kernel should be 1. For rawhide
# and/or a kernel built from an rc or git snapshot, released_kernel should
# be 0.
%global released_kernel 1
View gist:4171049
(ns powerset.core-test
(:use (clojure set test)))
(defn powerset [s]
(apply union
#{s} ;the complete set of all s
(map (fn [i] (powerset (disj s i))) s)))
(deftest test-powerset
(is (= #{#{}}
View gist:193769
# GoKart becomes a module
module GoKart
# GoKart.new becomes a factory method for strategy classes
def self.new( strategy = nil )
( strategy == :reverse ) ? ReverseStrategy.new : ForwardStrategy.new
end
class ForwardStrategy
def drive
View gist:193768
# Started with something like this
class GoKart
def initialize( strategy = nil )
@strategy = strategy
end
def drive
if @strategy == :reverse
puts "Reverse"
else