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
require 'net/http'
require 'json'
TEAM = ENV['TEAM'] or raise 'TEAM env is required'
TOKEN = ENV['KIBELA_ACCESS_TOKEN'] or raise 'KIBELA_ACCESS_TOKEN env is required'
def req(query)
http = Net::HTTP.new("#{TEAM}.kibe.la", 443)
http.use_ssl = true
header = {
# Devise
extension ApplicationController (Devise)
def current_user: () -> User
end
class DeviseController < ApplicationController
end
class Devise::SessionsController < DeviseController
module ActiveRecord
def self.eager_load!: () -> untyped
def self.gem_version: () -> untyped
def self.version: () -> untyped
end
class ActiveRecord::ActiveRecordError < StandardError
end
rules:
- id: sample.delete_all
pattern:
- delete_all
- update_all
message: |
これらはvalidationやcallbackをスキップするので危険かもしれません。
justification:
- どうしても高速に update/destroy したい場合
@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
@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 / 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.
# 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 / 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
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