This file contains hidden or 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
| # :: [[a,b]] -> (a..a) -> b -> [[a,b]]] | |
| def spread mappings, range, default_value = 0 | |
| occupied = Hash[mappings] | |
| range.map { |index| [index, occupied[index] || default_value] } | |
| end | |
| # :: String -> [event] -> [[date, Int]] | |
| def class_commit_monthly_timeline class_name, events | |
| class_month_dates = events.select {|e| e.class_name == class_name }.map(&:date).map(&:month_start) | |
| spread(class_month_dates.freq, month_range(class_month_dates.min, class_month_dates.max)) |
This file contains hidden or 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
| Vector vList = new Vector(10); | |
| BufferedReader listFile = new BufferedReader(new FileReader(emailListFile)); | |
| String line = null; | |
| while ((line = listFile.readLine()) != null) { | |
| vList.addElement(new InternetAddress(line)); | |
| } | |
| listFile.close(); | |
| if (ls.debugOn) | |
| log.put(new Date() + "> " + "Found " + vList.size() + " email ids in list"); | |
| ls.toList = new InternetAddress[vList.size()]; |
This file contains hidden or 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
| def field_names | |
| @field_names ||= @expression.flatten | |
| .each_cons(2) | |
| .select {|marker, _| marker == :@ivar } | |
| .map {|_,name| field_name(name) } | |
| end |
This file contains hidden or 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
| require 'ap' | |
| require 'ripper' | |
| CLASS_TEXT = "class A; end; class B; end" | |
| CLASS_SEXP = Ripper.sexp(CLASS_TEXT) | |
| BIG_TEXT = "class A; def a; @a = b; end; def b; @d = a; @e = a; end; end; module B; def b; end; end" | |
| BIG_SEXP = Ripper.sexp(BIG_TEXT) |
This file contains hidden or 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
| ENCODER = Hash[('a'..'z').map {|x| [x,x] }].merge(Hash["aeiouya".chars.each_cons(2).to_a]) | |
| DECODER = ENCODER.invert | |
| def encode string | |
| string.chars.map {|c| ENCODER[c] || c }.join | |
| end | |
| def decode string |
This file contains hidden or 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
| class Object | |
| def ary?; is_a? Array; end | |
| def str?; is_a? String; end | |
| def nonempty_ary? | |
| ary? && (not empty?) | |
| end | |
| end | |
| def sexp_select sexp, symbols |
This file contains hidden or 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
| FIELDS_TEXT = "class A; def a; @a = @b; end; end" | |
| FIELDS_SEXP = Ripper.sexp(FIELDS_TEXT) | |
| [:program, [[:class, [:const_ref, [:@const, "A", [1, 6]]], nil, | |
| [:bodystmt, [[:def, [:@ident, "a", [1, 13]], [:params, nil, nil, nil, nil, nil], | |
| [:bodystmt, [[:assign, [:var_field, [:@ivar, "@a", [1, 16]]], | |
| [:var_ref, [:@ivar, "@b", [1, 21]]]]], nil, nil, nil]]], nil, nil, nil]]]] |
This file contains hidden or 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
| class Array | |
| def freq_by &block | |
| group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first) | |
| end | |
| def freq | |
| freq_by {|e| e } | |
| end | |
| end |
This file contains hidden or 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
| class Array | |
| def freq_by &block | |
| group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first) | |
| end | |
| def freq | |
| freq_by {|e| e } | |
| end | |
| end |
This file contains hidden or 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
| saddle :: (a->Bool) -> [a] -> [(a,a)] | |
| saddle f [] = [] | |
| saddle f (x:xs) = saddle' f x xs | |
| saddle' :: (a->Bool) -> a -> [a] -> [(a,a)] | |
| saddle' f initial [] = [] | |
| saddle' f initial (x:xs) = (x, sideValue x) : saddle' f (sideValue x) xs | |
| where sideValue x = if f x then x else initial |