Skip to content

Instantly share code, notes, and snippets.

View pocke's full-sized avatar
⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
@pocke
pocke / monkey.rb
Created April 8, 2024 16:34
Get core exts
module Monkey
extend self
MODULE_NAME = Module.instance_method(:name)
MODULE_SINGLETON_CLASS_P = Module.instance_method(:singleton_class?)
MODULE_SINGLETON_CLASS = Module.instance_method(:singleton_class)
MODULE_INSTANCE_METHODS = Module.instance_method(:instance_methods)
MODULE_INSTANCE_METHOD = Module.instance_method(:instance_method)
CLASS_ATTACHED_OBJECT = Class.instance_method(:attached_object) rescue nil
IS_A = Object.instance_method(:is_a?)
@pocke
pocke / git-coauthor
Last active January 25, 2024 07:27
Add GitHub's Co-authored-by to the latest commit from account name
#!/usr/bin/env bash
USAGE="Usage: git coauthor USERNAME
It adds the specified user as Co-authored-by into the latest commit.
Example:
$ git coauthor pocke"
@pocke
pocke / videos.csv
Created June 22, 2023 04:01
RubyKaigi 2023 video list CSV
title link
[JA] The future vision of Ruby Parser / Yuichiro Kaneko @spikeolaf https://www.youtube.com/watch?v=IhfDsLx784g&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&index=2&pp=iAQB
[EN] RuboCop's baddest cop / Genadi Samokovarov @gsamokovarov https://www.youtube.com/watch?v=n-D9uPOo_kc&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&index=3&pp=iAQB
[EN] Generating RBIs for dynamic mixins with Sorbet and Tapioca / Emily Samp @egiurleo https://www.youtube.com/watch?v=UpbVZ4Gqk3c&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&index=4&pp=iAQB
[JA] Make Regexp#match much faster / Hiroya FUJINAMI @makenowjust https://www.youtube.com/watch?v=IbMFHxeqpN4&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&index=5&pp=iAQB
[EN] Understanding the Ruby Global VM Lock by observing it / Ivo Anjo @KnuX https://www.youtube.com/watch?v=rI4XlFvMNEw&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&index=6&pp=iAQB
[JA] develop chrome extension with ruby.wasm / Yuma Sawai @aaaa777 https://www.youtube.com/watch?v=A2ziP8V9muE&list=PLbFmgWm555yYvWS7VGTFipF7ckduvSeT-&inde
@pocke
pocke / open-releases.rb
Created July 15, 2022 07:00
Open all rails/rails release between specified versions
# Usage:
# # Open all releases between 6.1 and 7.0
# $ ruby open-releases.rb 6.1 7.0
tags = `git tag`.lines(chomp: true).map { _1[/^v(.+)$/, 1] }.compact.map { Gem::Version.new _1 rescue nil }.compact
s, e = ARGV.map { Gem::Version.new _1 }
vs = tags.select { s < _1 && _1 <= e }
vs.each do |v|
require 'tmpdir'
require 'pathname'
Dir.mktmpdir('steep-playground-') do |dir|
dir = Pathname(dir)
dir.join('Steepfile').write(<<~END)
target :test do
signature "."
check "test.rb"
end
@pocke
pocke / parser-ractor.rb
Last active September 13, 2021 10:07
Run parser gem on a Ractor
require 'parser/current'
class Parser::Lexer
methods.grep(/^lex_en/).each do |m|
if m.end_with?('=')
singleton_class.undef_method m
else
v = __send__ m
singleton_class.undef_method m
eval <<~RUBY
# Print gems that contains `test_files` in gemspec with disk consumed order.
#
# Usage:
# bundle install --path /path/to/somewhere
# cd /path/to/somewhere/ruby/VERSION/gems
# ruby THIS_SCRIPT.rb
#
# Pro tip: The following links are useful when you open a PR to remove test_files.
# * https://github.com/rubygems/guides/issues/90
# * https://github.com/rubygems/bundler/pull/3207
@pocke
pocke / invert_where.rb
Created April 28, 2021 10:54
`invert_where` inverts all where clause (dangerous!)
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
@pocke
pocke / rbs
Created November 1, 2020 17:25
invalid new type introducing
class C
def self.new: (String) -> untyped
end
class C2 < C
end
module M
def initialize: (String, Integer) -> void
end
@pocke
pocke / ractor-by-thread.rb
Created September 18, 2020 09:48
Implement ractor by Thread
using Module.new {
refine ThreadGroup do
attr_accessor :fake_ractor
end
}
class FakeRactor
def initialize(*args, name: nil, &block)
@name = name
@incoming = Thread::Queue.new