Skip to content

Instantly share code, notes, and snippets.

View koic's full-sized avatar

Koichi ITO koic

View GitHub Profile
@koic
koic / tokens_of_heredocs.md
Last active March 26, 2024 18:33
tokens of heredocs
@koic
koic / rubocop.yml.md
Last active January 18, 2018 03:07
Enable autocorrect for Lint/EndAlignment cop
% g diff .rubocop.yml
diff --git a/.rubocop.yml b/.rubocop.yml
index a04de4b497..3b4dd79e81 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -26,6 +26,9 @@ Layout/CaseIndentation:
 Layout/CommentIndentation:
   Enabled: true
@koic
koic / bench.rb
Created July 14, 2017 10:17
Is `casecmp?` faster? -> No
require 'benchmark/ips'
Benchmark.ips do |x|
x.report('upcase') { 'String'.upcase == 'string' }
x.report('downcase') { 'String'.downcase == 'string' }
x.report('casecmp') { 'String'.casecmp('string').zero? }
x.report('casecmp?') { 'String'.casecmp?('string') }
x.compare!
end
@koic
koic / document_structure_refactoring.md
Last active March 12, 2017 11:39
Document Structure Refactoring

Document Structure Refactoring

Pattern 1: Prefer headings rather than list items.

Prior Structure

Use the list items.

* foo
@koic
koic / oss_gate_meetup_20170330_timetable.md
Created March 3, 2017 06:10
OSS Gate Meetup 2017-03-30 Timetable (Draft)
### 初参加の「ビギナー」

|時間|やること|
|---|---|
|19:15-19:30|開場|
|19:30-19:40|アイスブレイク|
|19:40-20:10|OSS開発手順を説明|
|20:10-21:10|対象OSSを動かす|
- |21:10-21:20|ふりかえり|
@koic
koic / result.md
Last active January 27, 2017 02:41
bundle exec rake test:sqlite3_mem
% bundle exec rake test:sqlite3_mem
(snip)
Finished in 55.514131s, 87.2030 runs/s, 244.2982 assertions/s.

  1) Error:
QueryCacheTest#test_cache_is_not_available_when_using_a_not_connected_connection:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: tasks: SELECT  "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT ?
    /Users/koic/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `initialize'
 /Users/koic/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `new'
@koic
koic / string.rb
Created November 29, 2016 04:00
A patch for Rails 5 (with Oracle) and Enumerize
#
# activemodel-5.0.0.1/lib/active_model/type/string.rb
#
module ActiveModel
module Type
class String < ImmutableString # :nodoc:
...
def serialize(value)
@koic
koic / commit-msg
Last active November 14, 2016 07:38
git hook for an anti patterns of commit message
#
# コミットメッセージアンチパターン: 「コメント対応」メッセージ
#
# 「コメント対応」というコミットメッセージではコミットをできないようにする hook です。
# gitメッセージのサマリとなる1行目が対象です。
#
# このファイルの内容を .git/hooks/commit-msg に配置することで有効になります。
#
if [ "$(head -1 $1 | grep 'コメント対応')" ]; then
echo "\033[0;31m[ABORT] コミットメッセージには変更に対する「なぜ」を書きましょう。\033[0;39m" 1>&2
@koic
koic / yaml_case_study.rb
Created September 29, 2016 02:34
YAML case study
require 'yaml'
puts YAML.load(DATA.read) # => {"name"=>"Bob"}
__END__
---
name: Alice
name: Bob
@koic
koic / sort_vs_sort_by.md
Last active December 29, 2016 06:00
Enumerable#sort vs Enumerable#sort_by

Enumerable#sort without block

# http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-sort
require "benchmark"

a = (1..100000).map { rand(100000) }

Benchmark.bm(10) do |b|
 b.report("Sort") { a.sort }