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
| # :: [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 |
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
| STRING_COUNT = 6 | |
| def tab_column string, fret | |
| ["---" ] * (string - 1) + | |
| [fret.ljust(3,'-')] + | |
| ["---" ] * (STRING_COUNT - string) | |
| end | |
| puts ARGF.each_line | |
| .map(&:split) |
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
| stems = ARGF.read | |
| .split | |
| .each_cons(2) | |
| .group_by { |word_pair| word_pair[0] } | |
| def next_word ary | |
| ary[rand(ary.length).to_i][1] | |
| end | |
| e = Enumerator.new do |e| |
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
| # Accepts program file names on the command line and renders | |
| # their text to stdout as a sequence of spoken words | |
| token_map = { | |
| "[" => "left square-bracket", | |
| "]" => "right square-bracket", | |
| "!" => "exclamation-point", | |
| "\\" => "back slash", | |
| "#" => "pound sign", | |
| "\"" => "double-quote", |
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
| module Kernel; def c text; self; end; end | |
| puts ARGF.c("all files as text") .read | |
| .c("convert to enumerable") .chars | |
| .c("contiguous alphas and puncts") .chunk {|ch| ch =~ /[[:alnum:]]/ ? :alone : true } | |
| .c("merging identifiers and nums") .map {|key,values| key == :alone ? values.join : values } | |
| .c("array of idents and puncts") .flatten(1) |
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
| # Accepts program file names on the command line and renders them to stdout as a sequence of spoken words | |
| token_map = { | |
| "[" => "left-square-bracket", | |
| "]" => "right-square-bracket", | |
| "!" => "exclamation-point", | |
| "\\" => "backslash", | |
| "#" => "pound sign", | |
| "\"" => "double-quote", |
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 |
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 |