This file contains 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 dump(s) | |
dumped = s == eval("'#{s}'") && s !~ /[\C-a-\C-z]/ ? "'#{s}'" : s.dump.gsub(/\\x\d\d/){ | |
"\\C-"+('a'.ord + _1[2..].to_i(16) - 1).chr | |
} | |
if dumped =~ /\u3099/ | |
dumped.gsub!("\u3099", "\\u3099") | |
dumped = ?" + dumped[1...-1] + ?" if dumped[0] == ?' | |
end | |
dumped | |
end |
This file contains 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 Generator | |
def generate_paren(level) | |
regexp, producer = multi(level - 1) | |
[['(', '(?:', '(?<a>'].sample + regexp + ')', producer] | |
end | |
ALPHABET = ('a'..'z').to_a | |
def generate_alphabet(_level) | |
c = ALPHABET.sample |
This file contains 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 'matrix' | |
module RegexpMatrixSolver | |
refine Array do | |
def ~ | |
keys = map(&:first).flat_map(&:keys).uniq | |
matrix = [] | |
binding = first.last | |
vec = map{_2} | |
each do |values, rhs| | |
matrix << keys.map { values[_1] || 0 } |
This file contains 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 run | |
$VERBOSE=nil | |
tokens = %w[1 + * ** a in ( ) [ ] = . .. => <<] | |
cnt = 0 | |
output = {} | |
(2..8).each do |n| | |
cnt = 0 | |
tokens.repeated_permutation(n).each do |tokens| | |
code = tokens.join('') # or join(' ') | |
# Ruby's bug already fixed in 3.3 |
This file contains 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 RequirePaths | |
class << self | |
def require_completions(path) | |
*dir, target = path.split(File::SEPARATOR, -1) | |
target ||= '' | |
with_cache [:require_completions, dir] do | |
gem_and_system_load_path.flat_map do |load_path| | |
base_dir = File.absolute_path(File.join(load_path, *dir)) | |
with_cache [:requireable_paths, base_dir] do | |
requireable_paths(base_dir).select { |p| p.start_with?(target) } |
This file contains 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
,,,;;;;''''';;;'';, | |
,,;'' ';;,;;; ', | |
,,'' ;;'';'''';;;;;; | |
,;' ;; ',, ; | |
,;' ,;' ';, ; | |
;' ,;; ',,,; | |
,' ,;;,,,,,,,,,,,;;;; | |
;' ;;';;;; ,;; | |
;' ,;' ;; '',, ,;;; | |
;; ,;' ; '';, ,; ;' |
This file contains 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 'io/console' | |
num_status_lines = 4 | |
$SYMBOLS = Symbol.all_symbols | |
def status | |
bold = "\e[1m" | |
red = "\e[31m" | |
green = "\e[32m" | |
reset = "\e[m" | |
[ |
This file contains 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
Dir.chdir File.dirname __FILE__ | |
katakata_dir = '../../../../../tompng/katakata_irb' | |
def replace_module_names(code) | |
code | |
.gsub('module KatakataIrb', 'module IRB::TypeCompletion') | |
.gsub('KatakataIrb::TypeAnalyzer', 'TypeAnalyzer') | |
.gsub('KatakataIrb::Types', 'Types') | |
.gsub('KatakataIrb::Scope', 'Scope') |
This file contains 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 'set' | |
require 'ripper' | |
end_of_input_pattern = /syntax error, unexpected end-of-input/ | |
end_of_file_pattern = /unterminated (?:string|regexp) meets end of file/ | |
errors = Set.new | |
$VERBOSE = nil | |
handle = ->(e, file, code) { | |
m = e.message.lines.first | |
next if m.match?(end_of_input_pattern) || m.match?(end_of_file_pattern) || m.match?(/anywhere before EOF/) | |
next if errors.include?(m) |
This file contains 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
* * | |
* * * * | |
* * | |
* * * | |
* * * | |
* * | |
* * * | |
* * | |
* * * | |
* * * |