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
| recursive_hash = lambda { |h,k| h[k] = Hash.new(&recursive_hash) } | |
| table = Hash.new(&recursive_hash) | |
| table['a']['x'] = 1 | |
| table['a']['y'] = 2 | |
| table['b']['x'] = 3 | |
| table['b']['y'] = 4 | |
| # {"a"=>{"x"=>1, "y"=>2}, "b"=>{"x"=>3, "y"=>4}} |
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
| # | |
| # Demo for how to | |
| # - use memoization with any cache | |
| # - set up invalidation rules | |
| # | |
| class Cache | |
| def initialize | |
| @data = {} | |
| 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
| x x x x x x x x | |
| o o . o o . | |
| o oo o oo |
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 A | |
| module B | |
| extend self | |
| def b | |
| "b0" | |
| end | |
| end | |
| module X | |
| extend self |
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
| "abcd".method(:length).to_proc.call | |
| # => 4 | |
| # --- | |
| def a(x,y) | |
| [x, y] | |
| end | |
| def b |
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 | |
| require 'json' | |
| STDIN.read.split("\n").each do |line| | |
| data = JSON.parse(line) | |
| puts JSON.pretty_generate(data) | |
| # puts ARGV.map { |k| data[k] }.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
| #!/usr/bin/env ruby | |
| def print_aligned(text, sep) | |
| lines = text.to_s.split("\n").map do |line| | |
| line.split(sep) | |
| end | |
| maxes = | |
| lines.inject([]) do |maxes, line| | |
| line.map(&:length).each_with_index do |length, index| | |
| if length > maxes[index].to_i |
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
| c(1,2,3,4,5,6,7)[1:1 + 4 -1] | |
| # => [1] 4 | |
| c(1,2,3,4,5,6,7)[1:(1 + 4 -1)] | |
| # => [1] 1 2 3 4 |
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
| ?- Whut. | |
| % ... 1,000,000 ............ 10,000,000 years later | |
| % | |
| % >> 42 << (last release gives the question) | |
| ?- |
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 rock | |
| { :snare '(_ O) | |
| :kick '(O _) }) | |
| (def dnb | |
| ; '(1 _ . _ 2 _ . _ 3 _ . _ 4 _ . _) | |
| { :snare '(_ _ _ _ O _ _ o _ o _ _ O _ _ _) | |
| :kick '(O _ _ _ _ _ _ _ _ _ O _ _ _ _ _) }) | |
| (def reggae |