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 / .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)
// https://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
// 1. Enter sheet name where data is to be written below
var SHEET_NAME = "購入ログ";
// 2. Run > setup
//
// 3. Publish > Deploy as web app
// - enter Project Version name and click 'Save New Version'
// - set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously)
function sendMail() {
var today = new Date();
var MAIL_TO = "メールアドレス";
var cycles = (function() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("サイクル");
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
return values;