Skip to content

Instantly share code, notes, and snippets.

View cho45's full-sized avatar

Satoh, Hiroh cho45

View GitHub Profile
@cho45
cho45 / worker.pl
Last active August 29, 2015 13:56
#!/usr/bin/env perl
use utf8;
use strict;
use warnings;
use lib lib => glob 'modules/*/lib';
use constant MAX_WORKER => 2;
use constant MAX_REQUEST_PER_CHILD => 100;
use constant INTERVAL => $ENV{INTERVAL} || 5;
use constant NAMESPACE => 'MyApp::Worker';
#!ruby
class Foo
def hello
puts "Hello"
end
end
def localize_method(klass, method, &block)
unbound = klass.instance_method(method)
require 'continuation'
class Guard
attr_reader :args
attr_reader :called
attr_reader :result
def initialize(&before_finish)
@args = nil
@guard_cc = nil
module Guard
@@guards = []
def guard(&block)
set_trace_func(lambda {|event, file, line, id, binding, klass|
# p [event, file, line, id, binding, klass]
case event
when "call", "c-call"
for g in @@guards
g[:count] += 1
end
def guard_scope(&block)
context = self
guards = []
context.define_singleton_method(:guard) do |&b|
guards << b
end
block.call
ensure
#!/usr/bin/env ruby
MRUBY_CONFIG = 'sketch_mruby_config.rb'
File.open(MRUBY_CONFIG, "w") do |f|
f.puts `git show HEAD:build_config.rb`
end
ENV['MRUBY_CONFIG'] = MRUBY_CONFIG
def enable_gems
warn "enable_gems"
#!./perl -Ilib
use v5.19;
use strict;
use warnings;
use feature 'signatures';
no warnings "experimental::signatures";
use Test::More;
@cho45
cho45 / c.c
Created February 27, 2014 14:46
//#!gcc -O0 -g3 -gdwarf-2 -Wall c.c -o /tmp/a.out && /tmp/a.out 1 2
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>
uint8_t* memory[255];
uint8_t program_counter;
/*#!as --gstabs+ -o sketch.o sketch.s && ld -o sketch -e _start sketch.o && objdump -d -j .text -j .data sketch && ./sketch
*/
.global _start
.macro sys_exit
mov r7, $0x01 /* set system call number to 1 (exit) */
svc $0x00 /* supervisor call */
.endm
/*#!as --gstabs+ -o sketch.o sketch.s && ld -o sketch -e _start sketch.o && objdump -d -j .text -j .data sketch && ./sketch
*/
.global _start
.macro sys_exit
mov r7, $0x01 /* set system call number to 1 (exit) */
svc $0x00 /* supervisor call */
.endm