Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am mons on github.
  • I am mons (https://keybase.io/mons) on keybase.
  • I have a public key ASC3bELAJoi7ctVU4P64sjft5udPls8hIk5rVfrxSEUHyQo

To claim this, I am signing this object:

local ffi = require 'ffi'
ffi.cdef[[
typedef int mode_t;
char *strerror(int errnum);
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
ssize_t write(int fd, const char *buf, size_t count);
]]
@Mons
Mons / anyevent-scribe-server.pl
Created July 21, 2017 14:45
Simple debugging scribe server in perl
#!/usr/bin/env perl
use 5.010;
use strict;
use DDP;
use Data::Dumper;
# use Thrift;
# use Scribe::Thrift::scribe;
use Thrift::XS::MemoryBuffer;
use Thrift::XS::BinaryProtocol;
sub run {
my $url = shift;
my $cb = shift;
my @queue;
push @queue, $start_url;
my %seen;
my $cv = AE::cv; $cv->begin;
#!/usr/bin/env perl
use strict;
use AE;use EV;
use Guard;
use Time::HiRes;
use POSIX 'strftime';
sub ae_loop(&&$$);
package Local::Metric;
use 5.010;
use strict;
use warnings;
# 1 2 3 4 5 6 7 8 9 10 11
our @fields = qw{foo bar foobar baz quux bat xyzzy plugh qwe asd zxc};
sub new {
return { map { $_ => "".rand(100) } @fields };
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 \
--- LAPHLibs/MD5.lua 2013-09-14 17:35:11.195354277 +0400
+++ MD5.lua 2013-09-14 18:00:48.844139663 +0400
@@ -9,6 +9,8 @@
local lshift = bit.lshift
-require "memutils"
-require "stringzutils"
+dofile("memutils.lua")
+dofile("stringzutils.lua")
+--require "memutils"
$job = sub {
tcp_connect …, sub {
my $fh = shift or warn "failed: $!";
my $h = AnyEvent::Handle->new(
fh => $fh,
on_error => sub { ... },
);
my $id = int(rand(0xffffffff));
my $body = ...;
$h->push_write( pack('VVV',1,length $body, $id) );