Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tagomoris's full-sized avatar

Satoshi Tagomori tagomoris

View GitHub Profile
@tagomoris
tagomoris / namespace.md
Created September 26, 2023 11:19
Namespace on read

"Namespace on read"とは

これは、Rubyに仮想的なトップレベル名前空間を導入するためのNamespaceを提案します。NamespaceはRubyスクリプトかネイティブ拡張ライブラリかを問わず、ライブラリをグローバル名前空間から独立した形でrequire/loadします。

動機

"Namespace on read"は次の2つの問題を解決し、また1つの問題について解決の道筋を提供します。

  • ライブラリ(等)間での名前の衝突を避ける
  • グローバルに共有されたライブラリ/オブジェクトの意図しない変更を避ける
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|
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"
[
{"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}
]
@tagomoris
tagomoris / fiber.rb
Created May 31, 2018 08:05
fiber hack
class Foo
def initialize
@closed = false
end
def close
@closed = true
end
def closed?
access-log: /dev/null
hosts:
"localhost":
listen: 8384
paths:
"/t":
mruby.handler: |
class Foo
def initialize(ch, a)
@ch = ch
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}