Skip to content

Instantly share code, notes, and snippets.

@kei-s
kei-s / check_unused_factory_bot.rb
Last active July 1, 2022 02:53
Check unused FactoryBot definitions
# brew install prce2
# RAILS_ENV=test bin/rails r check_unused_factory_bot.rb
FactoryBot.factories.each do |factory|
command = %!pcregrep -Mr "(build|build_list|create|create_list)\\(\\n? *:#{factory.name}(,|\\))" spec!
result = `#{command}`
puts factory.name if result.chomp.empty?
end
@kei-s
kei-s / covered-files-from-simplecov.rb
Last active January 18, 2022 04:23
Show covered files from SimpleCov result html
# Show covered files from SimpleCov result html
#
# Usage:
#
# ruby covered-files-from-simplecov.rb index.html
#
require 'nokogiri'
THRESHOLD = 100
@kei-s
kei-s / disable_cop_inline.rb
Last active November 25, 2021 03:53
Disable cop in line comment
# Usage:
# bundle exec rubocop --only #{cop} --format json | ruby disable_cop_inline.rb
#
require 'json'
require 'tempfile'
require 'fileutils'
result = JSON.parse($stdin.read)
result['files'].each do |res|
next if res['offenses'].empty?
@kei-s
kei-s / heat_the_nicovideo_up.user.js
Created May 15, 2010 15:36
Heat the nicovideo up (patched)
//// -*- mode: javascript; coding: utf-8 -*-
// ==UserScript==
// @name Heat the nicovideo up
// @author noriaki
// @namespace http://blog.fulltext-search.biz/
// @description Visualize comments upsurge for Nicovideo
// @license MIT License
// @version 0.4.0
// @released 2007-09-11 09:00:00
// @updated 2009-06-07 19:58:00
@kei-s
kei-s / .gdbinit
Last active February 28, 2018 06:22
mecab-python3 デバッグメモ
set breakpoint pending on
b _wrap_Tagger_parseToNode
# frozen_string_literal: true
require 'benchmark'
class SizeMatters
include Comparable
attr :str
def <=>(other)
str.size <=> other.str.size
end
def initialize(str)
@kei-s
kei-s / clamp_bench.rb
Last active September 19, 2017 02:00
Comparable#clamp improvement
require 'benchmark'
Benchmark.bmbm do |x|
v = Random.rand(-10..110)
x.report "minmax:" do
10000000.times { [99, [0, v].max].min }
end
x.report "clamp: " do
### Keybase proof
I hereby claim:
* I am kei-s on github.
* I am kei_s (https://keybase.io/kei_s) on keybase.
* I have a public key whose fingerprint is 6B52 13DA 6F4B 48F5 5B42 AE34 931D 3783 8649 E80C
To claim this, I am signing this object:
@kei-s
kei-s / hikisuu.rb
Created May 19, 2017 10:55
仮引数と実引数
@gomobako = 🗑
def gomibako_ni_suteru(gomi)
@gomibako.akeru
@gomibako.ireru(gomi)
@gomibako.shimeru
end
cd = 💿
if cd.wareta?
gomobako_ni_ireru(cd)
@kei-s
kei-s / elb_status.rb
Created November 18, 2013 04:11
ELB watch
require 'aws-sdk'
logger = Logger.new('elb_status.log')
ACCESS_KEY = 'foo'
SECRET_ACCESS_KEY = 'bar'
LB = 'baz'
health = AWS::ELB.new(access_key_id: ACCESS_KEY, secret_access_key: SECRET_ACCESS_KEY, elb_endpoint: 'elasticloadbalancing.ap-northeast-1.amazonaws.com').load_balancers[LB].instances.health