Skip to content

Instantly share code, notes, and snippets.

@hkdnet
hkdnet / main.rb
Last active October 1, 2016 10:56
オフラインリアルタイムどう書くE08(http://mtsmfm.github.io/2016/10/01/doukaku-e08.html) 回答
class Point
include Comparable
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def to_s
"(#{x}, #{y})"
@hkdnet
hkdnet / a.rb
Last active March 4, 2017 08:41
class Mino
# I L O S T
attr_reader :type
def initialize(type)
@type = type
end
def bottoms
case type
when "I"
@hkdnet
hkdnet / foo.rb
Created September 18, 2017 02:05
p (-1.3).abs
p = 2
p (-1.3).abs
@hkdnet
hkdnet / bash
Created September 18, 2017 08:53
vernacular
$ bundle exec ruby exec.rb
== disasm: #<ISeq:<compiled>@src.rb>====================================
0000 trace 1 ( 1)
0002 putself
0003 putobject 10
0005 putobject 2
0007 opt_plus <callinfo!mid:+, argc:1, ARGS_SIMPLE>, <callcache>
0010 opt_send_without_block <callinfo!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, <callcache>
0013 pop
0014 trace 1 ( 2)
3s 3sec
4s 4sec
@hkdnet
hkdnet / deconst.patch
Last active August 10, 2018 10:03
union の deconst 外すやつ
diff --git a/iseq.c b/iseq.c
index 997dd7f1f7..be9efb9aad 100644
--- a/iseq.c
+++ b/iseq.c
@@ -989,11 +989,8 @@ static const rb_data_type_t iseqw_data_type = {
static VALUE
iseqw_new(const rb_iseq_t *iseq)
{
- union { const rb_iseq_t *in; void *out; } deconst;
VALUE obj;
@hkdnet
hkdnet / patch.rb
Created August 15, 2018 05:50
rack middleware ごとの経過時間をはかるやつ
# ref: http://blog.mirakui.com/entry/2012/04/03/slow-middleware
module RackMiddlewareBenchmarker
module Benchmarker
def call(env)
result = nil
ms = Benchmark.ms { result = super }
puts "MIDDLEWARE END #{self.class.to_s} (#{ms.to_i}ms)"
result
end
end
require 'logger'
logger1 = Logger.new('/tmp/logger/1.log')
logger1.level = Logger::Severity::DEBUG
logger2 = logger1.dup
logger2.level = Logger::Severity::INFO
logger1.info('1 info')
logger2.info('2 info')
logger1.debug('1 debug')
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 3380720f47..744fadde92 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -1959,6 +1959,8 @@ Init_readline(void)
mReadline = rb_define_module("Readline");
rb_define_module_function(mReadline, "readline",
readline_readline, -1);
+ rb_define_module_function(mReadline, "readmultiline",
+ readline_readline, -1);