Skip to content

Instantly share code, notes, and snippets.

require "pp"
require "singleton"
class Multiton
include Singleton
class << Singleton
def __init__(klass)
klass.instance_eval {
@multiton__instances__ = {}
@niamster
niamster / actor-gc.rb
Created February 21, 2015 19:00
Test if celluloid actor is properly GCed once terminated
#!/usr/bin/env ruby
require 'celluloid'
require 'weakref'
class Test
begin
include Celluloid
finalizer :shutdown
rescue
@niamster
niamster / zmq-test-router.rb
Created March 14, 2015 23:58
Celluloid 0MQ router
require 'celluloid/zmq'
Celluloid::ZMQ.init
class Server
include Celluloid::ZMQ
def initialize(address)
@socket = RouterSocket.new
@socket.set ::ZMQ::SNDHWM, 0
@niamster
niamster / zmq-test-dealer.rb
Created March 14, 2015 23:59
Celluloid 0MQ dealer
require 'celluloid/zmq'
Celluloid::ZMQ.init
class Client
include Celluloid::ZMQ
def initialize(address)
@socket = DealerSocket.new
@socket.set ::ZMQ::SNDHWM, 0
class Visitor(ast.NodeVisitor):
def visit_Call(self, node):
if node.func.id == 'export':
if len(node.args) < 1:
raise Exception, 'Invalid number of argumets to export at line %d' % node.lineno
doc = ''
for kw in node.keywords:
if kw.arg == 'doc':
doc = kw.value
if isinstance(kw.value, ast.Str):
@niamster
niamster / futures-args-gc-463.rb
Last active August 29, 2015 14:17
test for celluloid issue #463
#!/usr/bin/env ruby
require 'celluloid'
require 'weakref'
class Bar
attr_reader :bar
def initialize(bar)
@bar = bar
#!/usr/bin/env ruby
require 'weakref'
foo = 'toto'
weak = WeakRef.new foo
f = Fiber.new do
p foo
# if fiber yield is not called the fiber context is never released
@niamster
niamster / block-leak.rb
Created April 6, 2015 20:13
Undead blocks
#!/usr/bin/env ruby
require 'weakref'
class Proxy < BasicObject
attr_reader :cls
def initialize(cls)
@cls = cls
end
@niamster
niamster / method-missing-leak.rb
Created April 6, 2015 20:38
Method missing leak
#!/usr/bin/env ruby
require 'weakref'
$LEAK = true
class Hidden
def initialize(cls)
@cls = cls
end
@niamster
niamster / hmac-bench.c
Last active November 4, 2015 10:27
hmac-bench.c
#include <stdio.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <assert.h>
#include <getopt.h>