Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
@pocke
pocke / parser-ractor.rb
Last active Sep 13, 2021
Run parser gem on a Ractor
View parser-ractor.rb
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
View list_gems_with_test_files.rb
# 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 Apr 28, 2021
`invert_where` inverts all where clause (dangerous!)
View invert_where.rb
# 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 Nov 1, 2020
invalid new type introducing
View rbs
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 Sep 18, 2020
Implement ractor by Thread
View ractor-by-thread.rb
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
View bitjourney-querly.yaml
rules:
- id: sample.delete_all
pattern:
- delete_all
- update_all
message: |
これらはvalidationやcallbackをスキップするので危険かもしれません。
justification:
- どうしても高速に update/destroy したい場合
View active_record.rbs
module ActiveRecord
def self.eager_load!: () -> untyped
def self.gem_version: () -> untyped
def self.version: () -> untyped
end
class ActiveRecord::ActiveRecordError < StandardError
end
View ext.rbs
# Devise
extension ApplicationController (Devise)
def current_user: () -> User
end
class DeviseController < ApplicationController
end
class Devise::SessionsController < DeviseController
View kibela-public-api-tester.rb
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 = {
View Rails.env.md

Rails.envを減らしたい

TL;DR

  • if Rails.env.production?をやめて、if ENV['ENABLE_HOGEHOGE_FEATURE']のように書いていこう

Kibelaの現状

Rails.envがたくさん生えています。