Skip to content

Instantly share code, notes, and snippets.

View tagomoris's full-sized avatar

Satoshi Tagomori tagomoris

View GitHub Profile
class X
NAME1 = "name1"
NAME2 = "name2"
NAME3 = "name3"
def replace_name_0(record, name)
record
end
def replace_name_1(record, name)
{:here=>"write0", :length=>124}
{:read=>
{:timekey=>24998551,
:tagkey=>"hoge.pos.moge.hogehogehogehoge",
:keys=>{:moge=>111},
:id=>"d0d71b3d-b680-4549-b805-a08825e0f71d",
:s=>1024,
:c=>1499913050,
:m=>1499913110}}
{:here=>"write1", :length=>102}
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby hoge.rb
{:here=>"rescue", :closed=>true, :error=>#<IOError: stream closed>}
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby -e 'puts RUBY_VERSION'
2.3.3
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux-gnu]
@tagomoris
tagomoris / console.out
Last active January 11, 2017 03:44
Trying to use SSLSocket for servers on Cool.io
$ ruby hoge.rb
{:here=>"creating socket"}
{:here=>"creating sslsocket"}
:here=>"socket.new"}
{:here=>"connecting"}
{:here=>"calling super"}
{:here=>"super called"}
{:here=>"on_connect"}
{:here=>"trying accept", :accepted=>false}
N=1_000
line = "a" * 200 + "\n"
body = line * 300
Benchmark.bm{|x|
x.report("splitonly") {
N.times{
buf = body.dup
lines = []
while !buf.empty?
lines << buf.slice!(0,201)
server_create(:title, proto: :tcp, port: @port, connection_callback: true) do |conn|
# on connection
source_addr = conn.addr
source_port = conn.port
conn.data do |data|
# on data
conn.write resp # ...
conn.disconnect
end
@tagomoris
tagomoris / name_error_or_nil.rb
Created November 7, 2016 09:54
variable not assigned by errors is nil.
def foo
raise "yay"
end
def hoge
tag = foo
rescue => e
{tag: tag, e: e}
end
# block and yield
[15] pry(main)> t = Time.now; 10_000_000.times{ myroot2{|t,r| t; r; 1} }; p(Time.now - t)
19.370526
=> 19.370526
# multi value return
[16] pry(main)> t = Time.now; 10_000_000.times{ myroot1{|t,r| t; r; 1} }; p(Time.now - t)
14.743976
=> 14.743976
@tagomoris
tagomoris / forward-protocol-spec-v1.md
Last active August 31, 2016 09:14
Fluentd Forward Protocol version 1 Draft

Fluentd Forward Protocol Specification (v1)

This is a protocol specification for Fluentd forward input/output plugins. This protocol is also used by fluent-logger software, and many other software in ecosystem (e.g., Docker logging driver for Fluentd).

This protocol version is v1. This spec is supported by Fluentd v0.14 (v0.14.5 and later), and v1 (in plan). Protocol version v0 is supported by v0.10 and v0.12, and protocol version v1 is compatible with v0 (All implementations which supports v1 also supports v0).

Changes

  • August 30, 2016: start to write this draft
class A
def foo
"a"
end
end
class B < A
def foo
v = super
"b#{v}"