Skip to content

Instantly share code, notes, and snippets.

use AnyEvent::Handle;
BEGIN {
my $push_write = \&AnyEvent::Handle::push_write;
*AnyEvent::Handle::push_write = sub {
if (@_ > 2) {
goto &$push_write;
} else {
if(utf8::is_utf8 $_[1]) {
@_ = (@_);
$_[1] = "$_[1]";
@Mons
Mons / defer.h
Created February 19, 2016 21:18
C DEFER
// (c) Roman Tokarev
#ifndef _DEFER_H_
#define _DEFER_H_
#define CONCAT(a_, b_) a_ ## b_
#define CONCAT2(a_, b_) CONCAT(a_, b_)
#define UNIQUE_TOKEN(var_) CONCAT2(var_, __LINE__)
#define DEFER \
@Mons
Mons / iproto.lua
Created August 13, 2015 15:22
IProto wireshark
local iproto_proto = Proto("iproto", "iproto protocol")
function iproto_proto.dissector(buffer, pinfo, tree)
pinfo.cols.protocol = "IPROTO"
local iprotree = tree:add(iproto_proto, buffer(), "IPROTO")
local buffer_len = buffer:len()
local offset = 0
while offset < buffer_len do
local len = buffer((offset + 4), 4):le_uint()
local sync = buffer((offset+8), 4):le_uint()
@Mons
Mons / pool.lua
Created July 29, 2015 23:56
Connection pool draft
local obj = require('obj')
local fiber = require('fiber')
local log = require('log')
local remote = require('net.box')
local pool = obj.class({},'pool')
function pool:_init(cfg)
local zones = {}
self.total = 0
@Mons
Mons / super-gc.lua
Created July 29, 2015 21:39
Class, super and gc
local weak = setmetatable({},{__mode = 'v'})
do
local Class = {}
-- function Class:super( class,method )
-- return function ()
-- print("work")
-- end
-- end
function Class:test()
self:super(Class,'method')()
local r,e = pcall(function ()
local res = peer:call('box.raise', tostring(box.error.ER_PROC_LUA), "Test die" )
end)
print("call res = ",r," ",e)
local r,e = xpcall(function ()
local res = peer:call('box.raise', tostring(box.error.ER_PROC_LUA), "Test die" )
end, function(...)
print("Error: ",...)
if box.sandbox then
box.sandbox = nil
end
local ffi = require 'ffi'
ffi.cdef [[
void exit(int)
]]
box.fiber.wrap(function()
@Mons
Mons / case.pl
Created April 25, 2015 13:50
CBOR::XS incr_parse die
use 5.010;
use CBOR::XS;
use Data::Dumper;
my $cbor = CBOR::XS->new();
my $data = "\x82\x01\xD9\x56\x52\x44test";
say Dumper $cbor->decode($data);
my $buf;
for (split //, $data) {
$buf .= $_;
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
#!/usr/bin/env perl
use EV;
use Scalar::Util 'weaken';
my @tasks = qw(1 2 3);
sub dbg(@) {
printf "[%0.06f] %s\n",EV::now(), "@_";
}