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 / 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
rules:
- id: sample.delete_all
pattern:
- delete_all
- update_all
message: |
これらはvalidationやcallbackをスキップするので危険かもしれません。
justification:
- どうしても高速に update/destroy したい場合
module ActiveRecord
def self.eager_load!: () -> untyped
def self.gem_version: () -> untyped
def self.version: () -> untyped
end
class ActiveRecord::ActiveRecordError < StandardError
end
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 = {

Rails.envを減らしたい

TL;DR

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

Kibelaの現状

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

@pocke
pocke / steep.rake
Created February 23, 2020 10:59
Steepで解析できる型定義ファイルを生成する 2020-02-23版
namespace :steep do
task gen: %i[base copy ar2rbs path_helper]
task :base do
require 'ruby/signature'
sig_base_path = Rails.root.join('sig/base.rbs')
files = Dir.glob(['app/**/*.rb', 'lib/**/*.rb']).sort
sh 'bundle', 'exec', 'rbs', 'prototype', 'rb', *files, :out => sig_base_path.to_s
@pocke
pocke / rurema-converter2.rb
Created March 1, 2020 12:38
For removing unnecessary indents
require 'ast'
require 'strscan'
class RuremaParser
def initialize(text, path: nil)
@text = text
@path = path
@index = 0
end
diff --git a/tmp/before.rbs b/tmp/after.rbs
index b67bb830f..49b9c3bdf 100644
--- a/tmp/before.rbs
+++ b/tmp/after.rbs
@@ -271,7 +271,7 @@ class RuboCop::AST::CaseNode < Node
# Returns the keyword of the `case` statement as a string.
#
# @return [String] the keyword of the `case` statement
- def keyword: () -> untyped
+ def keyword: () -> "case"