Skip to content

Instantly share code, notes, and snippets.

☕️

akira yamada arika

☕️
Block or report user

Report or block arika

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View select_rails_log.rb
#!/usr/bin/env ruby
require 'time'
require 'pp'
require 'optparse'
require 'ostruct'
request_id_regexp = /\h{8}-\h{4}-\h{4}-\h{4}-\h{12}/ # Rails 5.x
LOG_REGEXP = /\A., \[(?<time>\S+) #(?<pid>\d+)\] *(?<severity>\S+) -- :(?: \[(?<reqid>#{request_id_regexp})\])? (?<log>.*)/
ANSI_ESCAPE_SEQ_REGEXP = /\e\[(?:\d{1,2}(?:;\d{1,2})?)?[mK]/
@arika
arika / test_unit_profiling_for_rails.rb
Last active Nov 29, 2018
Test::Unitのtestやsetup/cleanup/teardownのプロファイルをとる(Rails編)
View test_unit_profiling_for_rails.rb
# test/test_helper.rbに書く
module TestProfiling
module TestCase
def run(result)
data = {
name: method_name,
owner_name: self.class.name,
source_location: method(method_name).source_location,
passed: passed?,
View pretty_print_sql.rb
require 'ostruct'
require 'anbt-sql-formatter/formatter'
module PrettyPrintSql
module ActiveRecord
def ppsql
to_sql.tap {|sql| ::PrettyPrintSql.pp(sql) }
end
end
@arika
arika / .spring.rb
Last active Aug 3, 2018
auto stop spring server
View .spring.rb
module DotSpringRb
MONITOR_INTERVAL = 10*60
SERVER_KEEP_PERIOD = 30*60
module_function
def env
@env ||= Spring::Env.new
end
@arika
arika / .vimrc
Last active Apr 27, 2018
https://github.com/janko-m/vim-test のtest-unit対応 .vim/autoload/test/ruby/testunit.vim (rails.vimとminitest.vimからのコピペ)
View .vimrc
let test#runners = {'Ruby': ['TestUnit']}
@arika
arika / .irbrc
Last active Feb 9, 2018
workaround to avoid suspending rb-readline by 'Ctrl-Y'. https://arika.org/2017/11/10/rb-readline-and-ctrl-y/
View .irbrc
# macOSでのrb-readline使用時の"\C-y"サスペンド問題の回避
if defined?(::RbReadline) && $".grep(/\/rbreadline.rb\z/)
stty = `stty -a`
stty_ccs = { 'dsusp' => '^Y', 'lnext' => '^V' }
stty_ccs.delete_if {|cc, key| /\b#{Regexp.quote("#{cc} = #{key}")};/ !~ stty }
unless stty_ccs.empty?
system('stty', *stty_ccs.keys.inject([]) {|opts, cc| opts << cc << 'undef' })
IRB.conf[:AT_EXIT] << proc do
View mini_magick_debug.rb
require 'shellwords'
class MiniMagickCommandExecutionTrace
OUTPUT = $stderr
TERM = {
green: "\e[32m",
red: "\e[31m",
yellow: "\e[33m",
reset: "\e[m",
}.freeze
@arika
arika / rails_erb_syntax_check.rb
Last active Dec 12, 2017
Rails(Action View) ERB template syntax checker
View rails_erb_syntax_check.rb
require 'action_view'
require 'ruby-beautify'
require 'ripper'
require 'tmpdir'
require 'fileutils'
require 'optparse'
def check_syntax(path, options = {})
erb = content(path)
code = ruby_code(erb)
View to_rouge.rb
# Usage:
#
# RUBYOPT='-r ./to_rouge' RI_ROUGE=monokai.sublime \
# ri --format=rouge Class.methods
require 'rdoc'
require 'rouge'
module RDoc
class Markup
@arika
arika / method_call_bm.rb
Created Nov 11, 2017
Ruby method call benchmark
View method_call_bm.rb
require 'benchmark/ips'
class Runner
def self.create(obj, method_name)
Class.new(self).class_eval do
eval <<-E
def run
@obj.#{method_name}
end
E
You can’t perform that action at this time.