Skip to content

Instantly share code, notes, and snippets.

View kachick's full-sized avatar
😋
😪

Kenichi Kamiya kachick

😋
😪
View GitHub Profile
@kachick
kachick / building_ruby_trunk_for_chruby.md
Created July 29, 2016 19:14
rubyのtrunkをさっくりbuildしてchrubyから使えるようにする時の僕のやり方

推奨できる物かは知らないけど個人的に楽

Mac OS X + zsh + chruby

ruby_version=$(grep '#define RUBY_VERSION' version.h | grep -o -E '[0-9.]+')
ruby_bin=ruby-${ruby_version}dev.$(git rev-parse --short trunk)
./configure --prefix="$HOME/.rubies/$ruby_bin" --disable-install-doc
make install
source /usr/local/share/chruby/chruby.sh
@kachick
kachick / rubinius.SIGSEGV.20160723.txt
Created July 22, 2016 19:09
`Array.new` with huge value makes SIGSEGV
☻ ./tmp/bin/rbx -e 'Array.new(2 ** 29)' ruby-2.3.0p0 spec-public-send-with-protected-method 3c32123
The Rubinius process is aborting with signal: SIGSEGV
--- begin system info ---
node info: MacBook-Pro-2.local Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64
--- end system info ---
--- begin rubinius info ---
process info: kachick rbx 6414 3.3.c713 2.3.1 2016-07-21 f0373ac0 3.6.2 JIT disabled
--- end rubinius info ---
--- begin system backtrace ---
0 rbx 0x000000010b9eda53 _ZN8rubiniusL20abandon_ship_handlerEi + 259
@kachick
kachick / hash-p_diff.rb
Created December 5, 2015 08:38
Hash#p_diff
class Hash
def p_diff(b)
merged_keys = keys | b.keys
merged_keys.each do |k|
case
when key?(k) && b.key?(k)
value = self[k]
if value == b[k]
puts "a,b: #{k.inspect} => #{value.inspect} == #{b[k].inspect}"
else
@kachick
kachick / utc_from_jst.rb
Last active December 5, 2015 08:39
頭の中では日本時間で考えたいが、実際にはUTCで扱わなきゃいけないというツラさを解消したい
def utc_from_jst(*args)
ActiveSupport::TimeZone.new('Asia/Tokyo').utc_offset.seconds.ago Time.zone.local(*args)
end
@kachick
kachick / arel_table_is_private-API_and_rails-5_AR-or.md
Created November 11, 2015 03:08
arel_table は private な APIだよ & Rails 5 から ActiveRecord::Relation#or が用意された
@kachick
kachick / rescue_with_module.md
Created November 4, 2015 12:03
例外のrescueにmoduleを使う

Ruby の beginrescueend 構文では例外クラスを指定しろという説明が多い気するけど、includeしているmoduleとかでも拾えるんでもっと柔軟だよねというアレ

module Role end

class Foo < Exception
  include Role
end

begin
@kachick
kachick / rubinius_build_maxosx_2015-09.md
Last active May 18, 2016 17:32
Rubinius build on Max OS X 2015-09 ~ 2016

久しぶりに Mac OS X で rubinius build しようとしたら躓いた。 ぐぐってさっくり解決したとこをすっ飛ばすと、時間かかったのがここ

$ ./configure
Checking clang: found
Checking clang++: found
  Checking for 'llvm-config': only LLVM 3.0-3.5 is supported
ABORT: unable to set up LLVM
@kachick
kachick / key-change.md
Created August 9, 2015 22:35
壊れたキーボードの凌ぎ方 in Linux

キーボードの調子おかしくなってきて掃除した時、UpAllow↑キーの中のふにゃふにゃとキーカバーが上手くはまらないままどっかいっちゃった ベテランは使わないキーな気もするけど自分にとっては慣れ親しんだキーなので結構困る。 幸い?すぐそばの右シフトは使わなかったんでこれを差し替えて凌いでる。

# まずはxenvで
xenv
# 差し替え対象と差し替え先のキーを叩いてキーコード確認する。それさえ出来ない時も「xmodmap -pke」でなんとなく読める一覧は得られる
# 変更コマンドファイル作ってxmodmapに読み込ませる
@kachick
kachick / all_combinations.rb
Created July 19, 2015 16:44
Ruby 全ての組み合わせ
# coding: us-ascii
# Copyright (c) 2015 Kenichi Kamiya
class Array
def all_combinations(&block)
return to_enum __callee__ unless block_given?
size.downto(1).map { |n| combination(n, &block) }
end
@kachick
kachick / ruby-versions-mkrbxpatch.sh
Created July 8, 2015 19:09
Support to make patch for newer rbx on ruby-versions
#!/bin/bash
# 2015 Kenichi Kamiya
# Support to make patch for newer rbx on ruby-versions
# Target to Mac OS X
# ./this.sh 2.5.7
LANG=C; export LANG
if [ $# != 1 ]; then
echo "usage: $0 version(ex: 2.5.7)" 1>&2