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.*;
import Data.List
lineBreak :: String -> String
lineBreak = joinBrokenLines . joinWordsInBrokenLines . brokenLines . words
brokenLines :: [String] -> [[String]]
brokenLines [] = []
brokenLines wordList = brokenLine : brokenLines remainingWords
where (brokenLine, remainingWords) = splitAt (brokenLineWordCount wordList) wordList
@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
@michaelfeathers
michaelfeathers / gist:1855765
Created February 17, 2012 22:19
Five lines that turn Ruby into a different language
class Object
def method_missing m, *args
Object.respond_to?(m, true) ? Object.send(m, self, *args) : super
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]]