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
| 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 | |
| # 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
| 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
| 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
| # :: [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
| def span_count ary | |
| ([0] + ary).lazy | |
| .each_cons(2) | |
| .count {|c,n| c == 0 && n != 0 } | |
| 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 prefixes | |
| result = [] | |
| (0..size).each {|n| result << take(n) } | |
| result | |
| end | |
| def indices value | |
| map {|v| v == value ? 0 : 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
| # MF: Handle 'last method of class' case | |
| FileName = ARGV[0] | |
| MethodName = ARGV[1] | |
| def numbered_lines(file_name) | |
| lines = [] | |
| File.open(file_name).each_line {|line| lines << line } |
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
| #!/usr/bin/env ruby | |
| # Print the vaportrail of a ruby file in a git repo, i.e., | |
| # the complexity level at each commit. | |
| # | |
| # Requires: >= bash ?.? | |
| # >= git 1.7.1 | |
| # >= ruby 1.9.2 | |
| # >= flog 2.5.0 | |
| # |
OlderNewer