Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
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がたくさん生えています。

@pocke
pocke / rurema-converter2.rb
Created Mar 1, 2020
For removing unnecessary indents
View rurema-converter2.rb
require 'ast'
require 'strscan'
class RuremaParser
def initialize(text, path: nil)
@text = text
@path = path
@index = 0
end
@pocke
pocke / steep.rake
Created Feb 23, 2020
Steepで解析できる型定義ファイルを生成する 2020-02-23版
View steep.rake
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
View literal-type.diff
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"
View ski.rb
expr_gen = -> (n) { "(?<expr#{n}>[^()]|\\(\\g<expr#{n}>+\\))" }
simple = '(?<simple>(?:[()]|[^ski])*)'
S = /^#{simple}s#{expr_gen.(1)}#{expr_gen.(2)}#{expr_gen.(3)}(?<rest>.*)/
K = /^#{simple}k#{expr_gen.(1)}#{expr_gen.(2)}(?<rest>.*)$/
I = /^#{simple}i(?<rest>.+)/
P = /^#{simple}\((?<content>#{expr_gen.(1)}*)\)(?<rest>.*)/
$s = '\k<simple>(\k<expr1>\k<expr3>)(\k<expr2>\k<expr3>)\k<rest>'
$k = '\k<simple>\k<expr1>\k<rest>'
View ruby3-signature-stdlib-test.patch
diff --git a/lib/ruby/signature/test/hook.rb b/lib/ruby/signature/test/hook.rb
index ef0cc31..4b05887 100644
--- a/lib/ruby/signature/test/hook.rb
+++ b/lib/ruby/signature/test/hook.rb
@@ -19,6 +19,7 @@ module Ruby
INSTANCE_EVAL = BasicObject.instance_method(:instance_eval)
INSTANCE_EXEC = BasicObject.instance_method(:instance_exec)
METHOD = Kernel.instance_method(:method)
+ INSTANCE_METHOD = Module.method(:instance_method).unbind
CLASS = Kernel.instance_method(:class)
@pocke
pocke / this-year-repos.rb
Last active Dec 31, 2019
Print repositories created this year
View this-year-repos.rb
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'octokit'
end
name = ARGV[0] || `git config --get github.user`.chomp
year = ARGV[1] || Time.now.year
View gh-sponsors.rb
require 'net/http'
require 'json'
class RequestError < StandardError
def initialize(errors)
@errors = errors
end
def message
View vimbench.rb
require 'pathname'
require 'fileutils'
LOG_PATH = Pathname('/tmp/vimbench.log')
RE = /(\d+\.\d+)\s*\d+\.\d+:\s*--- N?VIM STARTED ---/
N = 10
def prepare
FileUtils.rm LOG_PATH if LOG_PATH.exist?