Skip to content

Instantly share code, notes, and snippets.

View bluerabbit's full-sized avatar
🤠
spark joy

Akira Kusumoto bluerabbit

🤠
spark joy
View GitHub Profile
@bluerabbit
bluerabbit / processlist.md
Last active February 20, 2024 04:43
MySQLでプロセスリストから遅いクエリのセッションをKILLするSQLを生成するSQL
SELECT
  *,
  CONCAT(CONCAT('KILL ', id), ';') AS KILL_SQL,
  CONCAT(CONCAT('CALL mysql.rds_kill(', id), ');') AS KILL_SQL_FOR_RDS
FROM
  INFORMATION_SCHEMA.PROCESSLIST
WHERE
  db = 'your_db'
 AND info LIKE '%probrem_query%'
@bluerabbit
bluerabbit / calculator.rb
Last active January 13, 2021 04:56
rspecはシンプルなスタイルを好んだ方が読みやすいことが多い
# gem install rspec
# rspec calculator.rb
require "rspec"
class Calculator
def sum(value1, value2)
value1 + value2
end
end
%cat /usr/local/bin/rubymine
#!/bin/sh

open -na /Applications/RubyMine.app --args "$@"
chmod +x/usr/local/bin/rubymine
@bluerabbit
bluerabbit / extract_sql.rb
Created August 25, 2020 01:09
rubyファイルの中にあるSQL文字列を抜き取る
# ruby extract_sql.rb app.rb
require 'ripper'
$SQL_TEXTS = []
class ExtractSql < Ripper::Filter
def on_tstring_content(tok, _)
text = tok.strip.upcase
$SQL_TEXTS << text if text.index('SELECT') || text.index('UPDATE') || text.index('INSERT') || text.index('DELETE')
@bluerabbit
bluerabbit / method_rewriter.rb
Created August 25, 2020 01:08
Parser::TreeRewriterでrubyファイルの書き換え
# gem 'parser'
# bundle exec ruby-rewrite -l method_rewriter.rb -m app.rb
class MethodRewriter < Parser::TreeRewriter
def on_def(node)
padding = ' ' * (node.location.column + 2)
insert_start(node: node, args: node.children[1].location.expression, code: node.children[2], padding: padding)
insert_after(node.children.last.location.expression, "\n#{padding}#{puts_end}")
super
@bluerabbit
bluerabbit / method_rewriter.rb
Last active August 20, 2020 11:27
rubyでmethodの前後に文字列を差し込む
# bundle exec ruby-rewrite -l method_rewriter.rb -m app.rb
class MethodRewriter < Parser::TreeRewriter
def on_def(node)
padding = ' ' * (node.location.column + 2)
insert_start(node: node, args: node.children[1].location.expression, code: node.children[2], padding: padding)
insert_after(node.children.last.location.expression, "\n#{padding}#{puts_end}")
super
end
@bluerabbit
bluerabbit / gist:74faca93855bdf505b08f44d2d487252
Created August 20, 2020 00:29
pull requestのcommitページですべてのコミットのcherry-pickコマンドを作成する
let texts = [];
$$('.js-commits-list-item clipboard-copy').forEach(function (e, i){ texts.push("git cherry-pick " + e.value) })
copy(texts.join('\n'));

クリップボードに下記が入る

git cherry-pick fab98cd67eebcd95a6c7e305873ddc49485cf6dx
@bluerabbit
bluerabbit / .haml-lint.yml
Last active August 2, 2023 04:14
rubocop config
linters:
LineLength:
enabled: false
SpaceInsideHashAttributes:
enabled: false
ViewLength:
enabled: false
InlineStyles:
enabled: false
ClassesBeforeIds:
@bluerabbit
bluerabbit / mysql2_sql_log.rb
Created January 8, 2020 02:48
ActiveRecord(mysql2 gem)でSQLのログを出すパッチ
module Mysql2
class Client
orig_query = instance_method(:query)
define_method(:query) do |sql, options = {}|
Rails.logger.info("[#{Time.current}] SQL:[#{sql}]")
orig_query.bind(self).call(sql, options)
end
end
end
@bluerabbit
bluerabbit / github_pull_request.rb
Last active October 26, 2022 01:05
CircleCIにてrspecでテストが落ちてたらGitHubのPull RequestのDescriptionに落ちたテストファイルを列挙する
require "octokit"
require "json"
class GithubPullRequest
def initialize(access_token: ENV["GITHUB_TOKEN"], repository:)
@client = Octokit::Client.new(access_token: access_token)
@repository = repository
end
def update_description!(rspec_examples:, pull_request_number:, ci_build_url:)