Skip to content

Instantly share code, notes, and snippets.

Avatar

Satoshi Tagomori tagomoris

View GitHub Profile
View multi_thread_server.rb
require 'socket'
PORT = 8088
server = TCPServer.open(PORT)
children = []
puts "server.0 starting children"
9.times do |i|
num = i + 1 # 0 is for main
children << Thread.start(server) do |s|
View msgpack_180_1.rb
require 'msgpack'
# x = "\x82\xA9condition\xA2OR\xA6groups\x92\x82\xA9condition\xA2or\xA7filters\x91\x83\xA3col\xAAbirth_date\x
# A3ope\xA5month\xA3val\xA12\x82\xA9condition\xA2or\xA7filters\x91\x83\xA3col\xADshare_capital\xA3ope\xB3greater_or_equal_
# th\xDD\x98[)\x8DL\f\v\x8C\f"
# MessagePack.unpack x
x2 = "\x82\xA9condition\xA2OR\xA6groups\x92\x82\xA9condition\xA2or\xA7filters\x91\x83\xA3col\xAAbirth_date\xA3ope\xA5month\xA3val\xA12\x82\xA9condition\xA2or\xA7filters\x91\x83\xA3col\xADshare_capital\xA3ope\xB3greater_or_equal_th\xDD\x98[)\x8DL\f\v\x8C\f"
View 0_sourece_name_country_city_quantity.json
[
{"name": "Amina Frost", "country": "US", "city": "Hammond", "amount": 30},
{"name": "Mehak Flowers", "country": "US", "city": "Kansas City", "amount": 41},
{"name": "Angharad Davie", "country": "AU", "city": "Queenstown", "amount": 31},
{"name": "Hannah Robins", "country": "UK", "city": "Langport", "amount": 1},
{"name": "Romilly Lowe", "country": "US", "city": "Kansas City", "amount": 10},
{"name": "Komal Donaldson", "country": "UK", "city": "Langport", "amount": 19},
{"name": "Florence Andrew", "country": "US", "city": "Kansas City", "amount": 7}
]
View fiber.rb
class Foo
def initialize
@closed = false
end
def close
@closed = true
end
def closed?
View h2o.conf.yml
access-log: /dev/null
hosts:
"localhost":
listen: 8384
paths:
"/t":
mruby.handler: |
class Foo
def initialize(ch, a)
@ch = ch
View 01_hash_access.rb
class X
NAME1 = "name1"
NAME2 = "name2"
NAME3 = "name3"
def replace_name_0(record, name)
record
end
def replace_name_1(record, name)
View result.txt
{: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}
View ruby_2.3.3_linux.txt
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 Jan 11, 2017
Trying to use SSLSocket for servers on Cool.io
View console.out
$ 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}
View bench_to_split_lines.rb
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)