Skip to content

Instantly share code, notes, and snippets.

View hanachin's full-sized avatar
🌺
OKA

Seiei Miyagi hanachin

🌺
OKA
View GitHub Profile
@hanachin
hanachin / list.rb
Last active December 20, 2019 16:47
ruby-signatureのディレクトリで実行して足りてなさそうな定義を調べたい人むけのスニペットです
klass_or_module = Object.constants.map(&Object.method(:const_get)).select {|klass| klass.is_a?(Class) || klass.is_a?(Module) }
tarinai = {}
klass_or_module.each do |klass|
tarinai[klass.name.to_s] = klass.public_instance_methods(false) - `exe/rbs methods #{klass.name} | cut -f1 -d" " | sort`.split.map(&:to_sym)
end
tarinai_singleton = {}
klass_or_module.each do |klass|
tarinai_singleton[klass.name.to_s] = klass.singleton_methods - `exe/rbs methods --singleton #{klass.name} | cut -f1 -d" " | sort`.split.map(&:to_sym)
end
@hanachin
hanachin / console
Last active September 1, 2019 15:43
time RUBOCOP_SPEC_URL=SECRET go run run-test.go | tee result.txt
% time RUBOCOP_SPEC_URL=SECRET go run run-test.go | tee result.txt
% cat result.txt | ruby -npe '~/summary_line":"([^"]*)"/;$_=$_.split(?:,2)[0]+":"+($1||"")+"\n"'
$<.map{|l,n=1|l[l.to_i.to_s n+=1]||redo;p n}
$<.map{|l,n=1|l[l.to_i.to_s n+=1]||redo;n}
#!ruby -n
$_[$_.to_i.to_s n=n.to_i+1]||redo;p n
__END__
#!ruby -n
$_[$_.to_i.to_s n=n.to_i+1]||redo;p n
$<.map{|l=n=1|$_[$_.to_i.to_s n+=1]||redo;p n}
__END__
$<.map{|l,n=1|l[l.to_i.to_s n+=1]||redo;p n}
// ==UserScript==
// @name Anarchy Golf reveal statics
// @namespace https://hanach.in/
// @version 0.1
// @description Automatically check code-statics
// @author hanachin
// @match http://golf.shinh.org/p.rb?*
// @grant none
// @run-at document-idle
// ==/UserScript==
using Module.new {
refine(Integer) do
def >(f)
f.call __method__
end
def <(f)
f.call __method__
end
@hanachin
hanachin / sequence0.satyg
Created June 7, 2019 05:30
stackoverflow
@stage: 0
let-rec seq-int s e =
let-rec r n =
&(
if ~n > ~e then
[]
else
~n :: ~(r &(~n + 1))
)
#!/home/sei/.rbenv/versions/2.6.3/bin/ruby --disable-gems
require "rbconfig"
$LOAD_PATH << "/home/sei/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib" << "/home/sei/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/msgpack-1.2.10/lib"
require 'bootsnap'
gem_name = 'rubocop'
exe_name = 'rubocop'
cache_dir = File.join(ENV['HOME'], '.cache', 'bootsnap', gem_name, exe_name, 'disable-gems')
Bootsnap.setup(cache_dir: cache_dir, load_path_cache: false, autoload_paths_cache: false)
require "rubygems.rb"
load "/home/sei/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.70.0/exe/rubocop"
module Hi
instance_methods_snapshot = []
TracePoint.trace(:class) do |tp|
next unless tp.self == self
# Hi.singleton_class.prepend Module.new { define_method(:method_added) { "ここで最小限のスナップショットを取ることも可能" } }
instance_methods_snapshot = instance_methods.map(&method(:instance_method))
end
TracePoint.trace(:end) do |tp|
diff --git a/exe/rubocop b/exe/rubocop
index abf88369e..9491ded7f 100755
--- a/exe/rubocop
+++ b/exe/rubocop
@@ -3,6 +3,9 @@
$LOAD_PATH.unshift("#{__dir__}/../lib")
+require 'bootsnap'
+Bootsnap.setup(cache_dir: '/tmp/rubocop/', load_path_cache: false, autoload_paths_cache: false)
@hanachin
hanachin / README.md
Last active May 19, 2019 04:42
Okinawa.rb Ruby Puzzles 2019/5/15 - #rubykaigi のRubyPuzzleが面白かったので真似しました。Ruby 2.7でしか動きません。