Skip to content

Instantly share code, notes, and snippets.

View michaelfeathers's full-sized avatar

Michael Feathers michaelfeathers

View GitHub Profile
@michaelfeathers
michaelfeathers / Server.java
Last active April 2, 2024 16:18
Scratch Refactoring Exercise
package server;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Date;
import java.util.Properties;
import java.util.Vector;
import javax.mail.*;
import javax.mail.internet.*;
@michaelfeathers
michaelfeathers / c11r.rb
Created September 22, 2020 22:43
Proof of Concept for interactive creation of characterization tests
# 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
package server;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Date;
import java.util.Properties;
import java.util.Vector;
class Command
def run line, session
return unless matches? line
process line, session
end
end
class FixView < Command
def matches? line
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 September 18, 2017 22:12
Find the number of calls in Ruby code that have happened no times, just once, or many times.
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
# http://c2.com/doc/SignatureSurvey/
require 'find'
def file_text file_name
IO.read(file_name).scan(/[{};]/).join
rescue
"error in file"
end
-- 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]]
class Array
def prefixes
result = []
(0..size).each {|n| result << take(n) }
result
end
def indices value
map {|v| v == value ? 0 : 1 }
def span_count ary
([0] + ary).lazy
.each_cons(2)
.count {|c,n| c == 0 && n != 0 }
end