Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Feathers michaelfeathers

View GitHub Profile
@michaelfeathers
michaelfeathers / c11r.rb
Created Sep 22, 2020
Proof of Concept for interactive creation of characterization tests
View c11r.rb
# Written by Michael Feathers July 10th, 2020
class Command
def run line, session
return unless matches? line
process line, session
end
end
class FixView < Command
View Server.java
package server;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Date;
import java.util.Properties;
import java.util.Vector;
View c11r.rb
class Command
def run line, session
return unless matches? line
process line, session
end
end
class FixView < Command
def matches? line
View churn.sh
find . -name "*.rb" |xargs -n1 -I file sh -c 'echo `git log --oneline file | wc -l`: file'|sort -nr
@michaelfeathers
michaelfeathers / zom.rb
Last active Sep 18, 2017
Find the number of calls in Ruby code that have happened no times, just once, or many times.
View zom.rb
require 'set'
require 'find'
class Array
def to_h; Hash[self]; end
def to_set; Set.new(self); end
def freq; group_by {|e| e }.map {|k,v| [k,v.count] }.to_h; end
end
View wardish.rb
# http://c2.com/doc/SignatureSurvey/
require 'find'
def file_text file_name
IO.read(file_name).scan(/[{};]/).join
rescue
"error in file"
end
View linebreak.hs
-- code from https://www.infoq.com/presentations/Type-Functional-Design with bug related to
-- assumption of trailing spaces after words
import Data.List;
lineBreak :: String -> String
lineBreak = joinedLines . wordJoinedLines . brokenLines . words
brokenLines :: [String] -> [[String]]
View words.rb
class Array
def prefixes
result = []
(0..size).each {|n| result << take(n) }
result
end
def indices value
map {|v| v == value ? 0 : 1 }
View gist:47183550dd10914e147b
def span_count ary
([0] + ary).lazy
.each_cons(2)
.count {|c,n| c == 0 && n != 0 }
end
@michaelfeathers
michaelfeathers / gist:1e2934ebb95560cddc3b
Created Apr 3, 2015
return a string that represents increases, decreases, and stable changes in a method's length
View gist:1e2934ebb95560cddc3b
# :: [event] -> String -> String
def method_delta_line es, method_name
es.select {|e| e.method_name == method_name }
.map(&:method_length)
.each_cons(2)
.map {|c,n| ["^","v","-"][(c <=> n) + 1] }
.join
end