Skip to content

Instantly share code, notes, and snippets.

View kachick's full-sized avatar
😋
😪

Kenichi Kamiya kachick

😋
😪
View GitHub Profile
@kachick
kachick / array-xor.rb
Created August 7, 2013 10:16
Array#^
# https://twitter.com/yuroyoro/status/365050923237638144
class Array
def ^(other)
(self | other) - (self & other)
end
end
[1, 2, 3] ^ [3, 4] #=> [1, 2, 4]
@kachick
kachick / multiple_yields_are_arrays.rb
Created July 28, 2013 14:46
yieldへ2つ渡しててもブロック無しで呼んだらただのArrayにしかならないから、真偽使ってるなら気をつけたほうがいいかもね的なアレ
# https://github.com/rubinius/rubinius/blob/7866fbd80db7fe6e1de2627f5442c8abe6ce51ad/kernel/common/enumerable.rb#L113
# https://github.com/rubinius/rubinius/blob/7866fbd80db7fe6e1de2627f5442c8abe6ce51ad/kernel/common/enumerable.rb#L428
class Foo
def each
yield false
yield nil
end
end
@kachick
kachick / time-jason.rb
Last active December 20, 2015 04:39
q(-::-)
class Time
def jason?
day == 13 && friday?
end
end
@kachick
kachick / 0.README.md
Last active December 19, 2015 03:39
Some metacharacters(\k, \g, \p, \P) crashed on some invalid examples - Rubinius

Some metacharacters(\k, \g, \p, \P) crashed on some invalid examples

ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]

>  ~  ruby -e '/\k/'
@kachick
kachick / rle.rb
Created June 28, 2013 08:35
Variety to resolve RLE by Ruby
#!/usr/local/env ruby
# coding: us-ascii
# RLEs in Ruby
# Tested Ruby 2.0
# 2013 - Kenichi Kamiya
$VERBOSE = true
example = 'AABBCCC'.freeze #from http://d.hatena.ne.jp/notogawa/20121201/1354389374
@kachick
kachick / 0.README.md
Created June 26, 2013 19:38
Uninitialized regexp crashes on some methods - rubinius

Uninitialized regexp crashes on some methods

MRI

  • ruby 1.8.7 (2012-10-12 patchlevel 371) [i686-linux]
  • ruby 1.9.3p429 (2013-05-15 revision 40747) [i686-linux]
uninitialized = Regexp.allocate
uninitialized.options #=> in `options': uninitialized Regexp (TypeError)
@kachick
kachick / README.md
Last active December 18, 2015 19:19
「任意の文字セットで進数変換するライブラリ」を言語別に集める

「任意の文字セットで進数変換するライブラリ」を言語別に集める

Ruby

integer-base

@kachick
kachick / try_webrick.rb
Created June 14, 2013 16:46
るりまから持ってきたwebrickのサンプル
# coding: us-ascii
# webricksample base from: http://doc.ruby-lang.org/ja/2.0.0/library/webrick.html
$VERBOSE = true
require 'webrick'
srv = WEBrick::HTTPServer.new({ :DocumentRoot => './',
:BindAddress => '127.0.0.1',
:Port => 20080})
srv.mount('/view.cgi', WEBrick::HTTPServlet::CGIHandler, 'view.rb')
@kachick
kachick / pathname-start_with_p.rb
Created June 6, 2013 12:20
Pathname#start_with?
# I've written at this commit.
# https://github.com/KitaitiMakoto/pathname-common_prefix/commit/904420faed7f73a758a35eafa74151fd7724918f
class Pathname
def start_with?(other)
to_enum(:descend).include?(Pathname(other))
end
end
@kachick
kachick / 1~31count.md
Created June 1, 2013 12:20
妙に出身県が偏ってる日本銀行総裁 http://www.boj.or.jp/about/outline/history/pre_gov/

31代まで

適当なワンライナー

ruby -e 'puts ARGF.group_by{|_|_.split.last}.map{|ken, lines|[ken, lines.count]}.sort_by(&:last).reverse.map(&:join)'

結果