Skip to content

Instantly share code, notes, and snippets.

@Asmod4n
Asmod4n / dispatch_echo_server.c
Created May 23, 2019 14:06
echo tcp server example with libdispatch in c
#include <dispatch/dispatch.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <signal.h>
#include <netinet/tcp.h>
@Asmod4n
Asmod4n / gist:2f53aab2643711a757ca91e060b73412
Last active April 24, 2017 18:38
Packing mruby blocks with MessagePack
hallo = lambda {|foo| puts foo}
proc = MessagePack.unpack hallo.to_msgpack
proc.call 1
1
// zproto_codec_mruby.gsl
// Generates a codec for a protocol specification.
.gsl from "zproto_codec_c.gsl"
.output "$(class.source_dir)/mrb_$(class.name)_body.h"
/* =========================================================================
$(class.name) - $(class.title:)
Codec class for $(class.name).
@Asmod4n
Asmod4n / phr.c
Last active August 29, 2015 14:13
picohttpparser for mruby
#include "picohttpparser.h"
#include <mruby.h>
#include <mruby/data.h>
#include <mruby/variable.h>
#include <mruby/array.h>
#include <mruby/string.h>
#include <mruby/class.h>
#define PHR_MAX_HEADERS 255
@Asmod4n
Asmod4n / example.c
Last active August 29, 2015 14:12
SecureBuffer for mruby
#include <stdio.h>
#include <sodium.h>
#include <mruby.h>
#include <mruby/data.h>
#include <mruby/class.h>
#include <mruby/string.h>
#include <mruby/array.h>
#include "picohttpparser.h"
static mrb_value
@Asmod4n
Asmod4n / .gitmodules
Last active August 29, 2015 14:08
czmq http_parser wslay ruby websockets
[submodule "picohttpparser"]
path = picohttpparser
url = https://github.com/h2o/picohttpparser.git
#include <czmq.h>
int main(void) {
zsock_t *server = zsock_new_stream ("@tcp://*:8080");
assert (server);
while (!zsys_interrupted) {
zmsg_t *msg = zmsg_recv (server);
if (!msg)
break;
@Asmod4n
Asmod4n / speed_test.rb
Last active August 29, 2015 14:07
Speed differences in FFI memory management
require 'ffi'
require 'benchmark'
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :malloc, [:size_t], :pointer
attach_function :free, [:pointer], :void
end
@Asmod4n
Asmod4n / Gemfile
Created August 18, 2014 12:40
First stab at a new high level czmq wrapper in ruby
source 'https://rubygems.org'
gem 'pry'
platforms :ruby do
gem 'msgpack'
end
platforms :jruby do
gem 'msgpack-jruby', :require => 'msgpack'
end
We couldn’t find that file to show.