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 'ripper' | |
$VERBOSE = nil | |
tokens = <<'S'.split | |
def if true false nil + - = a A :: '' "#{ | |
class module ? : . ( [ { -> | & * , / % ! @ $ ; < << | |
S | |
loop do | |
code = (tokens.sample(9) + [' ']*5).shuffle.join | |
# code = tokens.sample(9).join(' ') |
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
# RDOC_USE_PRISM_PARSER=1 bundle exec rdoc --op foo/bar | |
path_a = 'prism' | |
path_b = 'legacy' | |
files_a = Dir.chdir(path_a){Dir.glob('**/*.html')} | |
files_b = Dir.chdir(path_b){Dir.glob('**/*.html')} | |
def red(s) = "\e[31m#{s}\e[m" | |
def green(s) = "\e[32m#{s}\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
require 'matrix' | |
def powsum_params(k) | |
Matrix[*(k+2).times.map{|a| | |
(k+2).times.map{|b|(a+1)**b} | |
}].lup.solve((k+2).times.map{|n|(1..n+1).sum{_1**k}}).to_a | |
end | |
def assign_params(params, x) | |
params.each_with_index.sum {|p,i|p*x**i} | |
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
require 'rbs' | |
require 'rbs/cli' | |
loader = RBS::CLI::LibraryOptions.new.loader | |
def loader.each_dir | |
@loaded_dirs ||= Set.new | |
super do |source, dir| | |
next if @loaded_dirs.include? dir | |
@loaded_dirs << dir | |
yield source, dir |
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 prime_test?(n, a) | |
a.pow(n-1,n)==1 | |
end | |
def ruby_mark(n,m,x,y) | |
0.5*x.abs+y.abs<n && y>-m | |
end | |
def pattern(ow, oh, iw, ih) | |
((1-oh)..ow).map{|y| |
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
username = '...' | |
commits = `git log | grep -n1 "#{username}"`.scan(/-commit ([0-9a-f]+)/).flatten | |
result = commits.map do |commit| | |
stat = `git show #{commit} --stat -- lib` | |
diff = stat[/(\d+) insertion/].to_i - stat[/(\d+) deletion/].to_i | |
[commit, diff] | |
end | |
add_deletes = commits.map do |commit| | |
stat = `git show #{commit} -- lib` |
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 'chunky_png' | |
img = ChunkyPNG::Image.from_file('okinawa_ishigaki_small.png') | |
alphas = img.height.times.map do |y| | |
img.width.times.map do |x| | |
((img[x,y] >> 8) & 0xff) / 255.0 | |
end | |
end | |
lines = Hash.new(0) | |
borders = Hash.new(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
files_rbreadline = Dir.glob('rb-readline/lib/**/*.rb') | |
files_reline = Dir.glob('reline/lib/**/*.rb') | |
K = 123456789 | |
P = (1 << 81) | 17 | |
def hashes(text, n) | |
output = {} | |
hash = 0 | |
hash2 = 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
return if ENV['WITHOUT_IRBRC'] | |
{ IRB: 'irb', Reline: 'reline', ReplTypeCompletor: 'repl_type_completor' }.each do |const_name, lib| | |
require lib | |
const = Object.const_get(const_name) | |
version = const::VERSION | |
dir = File.expand_path File.join(File.dirname(const.const_source_location(:VERSION).first), '../../') | |
if File.exist?(File.join(dir, '.git')) | |
Dir.chdir dir do | |
branch = `git branch`[/^\* .+/][2..] |
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
%w@state=32;(st@=>s;at_exit{eval( | |
c=s*'')};s+=%w@ate..).each{|s|a=64.ch | |
r;t=((-11..11).map{|iy|((-22..22).map{|ix | |
|x,y=((ix+iy*2i)*(1i**(s/16r))).rect;[x.abs+( | |
y-5).abs,y+10].max<23.4??X:32.chr}*'').rstrip |
NewerOlder