This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Started with something like this | |
class GoKart | |
def initialize( strategy = nil ) | |
@strategy = strategy | |
end | |
def drive | |
if @strategy == :reverse | |
puts "Reverse" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Generate svg/png's from Graphviz dot diagrams" | |
task :dot | |
FileList[ '*.dot' ].each do |dot| | |
svg = dot.sub( /(\.dot)$/, '.svg' ) | |
png = dot.sub( /(\.dot)$/, '.png' ) | |
file svg => [ dot ] do | |
sh "dot -Tsvg -o #{svg} #{dot}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 (= #{#{}} |