Skip to content

Instantly share code, notes, and snippets.

@Mons
Mons / cv.pl
Created Mar 18, 2014
AnyEvent cv
View cv.pl
#!/usr/bin/env perl
use strict;
use 5.010;
use AnyEvent;
use Time::HiRes 'time';
sub async (&) {
my $code = shift;
my $t;$t = AE::timer 0,0,sub { undef $t;$code->(); }
@Mons
Mons / loop.pl
Created Mar 18, 2014
AnyEvent loop
View loop.pl
#!/usr/bin/env perl
use strict;
use 5.010;
use AnyEvent;
use AnyEvent::HTTP;
use Time::HiRes 'time';
my $records = [ (1)x4e3 ];
my $i = 0;
View simple_loop.pl
#!/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(), "@_";
}
View portable_endian.h
// "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__
@Mons
Mons / case.pl
Created Apr 25, 2015
CBOR::XS incr_parse die
View case.pl
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 .= $_;
View init.lua
if box.sandbox then
box.sandbox = nil
end
local ffi = require 'ffi'
ffi.cdef [[
void exit(int)
]]
box.fiber.wrap(function()
View test.lua
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: ",...)
@Mons
Mons / iproto.lua
Created Aug 13, 2015
IProto wireshark
View iproto.lua
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()
View gist:596741
se uni::perl;
use Benchmark ':all';
use lib::abs;
BEGIN {unshift @INC, lib::abs::path 'kraih/lib' }
use Mojo::ByteStream 'b';;
say $INC{'Mojo/ByteStream.pm'};
my %results;
$results{old} = timethis -1 , sub { b('x'x1000) };
View gist:596742
use uni::perl;
use Benchmark ':all';
use lib::abs;
BEGIN {unshift @INC, lib::abs::path 'kraih/lib' }
use Mojo::ByteStream 'b';;
say $INC{'Mojo/ByteStream.pm'};
my %results;
$results{old1} = timethis -1 , sub { b("тестовая строка")->encode('utf8')->decode('utf8') };