Skip to content

Instantly share code, notes, and snippets.

@bawNg
bawNg / instruction_sequence_classes.rb
Last active January 19, 2018 22:14
Getting class names from precompiled Ruby byte code with RubyVM::InstructionSequence
queued_classes = []
queued_classes << [@instructions.to_a[13].select! {|item| item.is_a? Array }]
while true
iterations += 1
instructions, super_class, parent_class = queued_classes.shift
break unless instructions
if instructions[0] == :defineclass
next if instructions[1] == :singletonclass
class_name = parent_class ? :"#{parent_class}::#{instructions[1]}" : instructions[1]
class_info = instructions[2]
{
"Type": "Simple",
"Hook": {
"IgnoredIndexes": [],
"InjectionIndex": 0,
"LastInjectionIndex": 0,
"ReturnBehaviour": 1,
"ArgumentBehaviour": 2,
"ArgumentString": null,
"HookTypeName": "Simple",
BindingFlags = {
Default = 0,
IgnoreCase = 1,
DeclaredOnly = 2,
Instance = 4,
Static = 8,
Public = 16,
NonPublic = 32,
FlattenHierarchy = 64,
InvokeMethod = 256,
@bawNg
bawNg / console.coffee
Last active August 29, 2015 13:57
Simple embedded REPL development console for sinatra/coffeescript/haml/stylus web applications
$(document).ready ->
highlight_json = (json) ->
output = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
output = output.replace /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, (match) ->
type = 'number'
if /^"/.test(match)
if /:$/.test(match)
type = 'key'
else
type = 'string'
@bawNg
bawNg / gist:9542641
Created March 14, 2014 05:38
strace of test case for em-http-request issue #266
This file has been truncated, but you can view the full file.
$ strace ruby ./em_test.rb
execve("/usr/local/bin/ruby", ["ruby", "./em_test.rb"], [/* 22 vars */]) = 0
brk(0) = 0xc21000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa855a75000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/x86_64/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls/x86_64", 0x7fffedc2a150) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/libpthread.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/tls", 0x7fffedc2a150) = -1 ENOENT (No such file or directory)
@bawNg
bawNg / lib_callbacks.rb
Created March 5, 2014 15:54
EventMachine based process spawning module
module Callbacks
def self.included(base)
base.class.send :attr_reader, :_defined_callbacks
def base.def_callbacks(*names)
@_defined_callbacks ||= []
@_defined_callbacks |= names
names.each do |name|
define_method(name) {|*args, &block| _handle_callback(name, *args, &block) }
end
@bawNg
bawNg / mongo.rb
Last active December 25, 2015 20:59
Patch for the mongo-1.9.2 driver which includes fiber based connection pool support
class EventMachine::Synchrony::MongoTimeoutHandler
def self.timeout(op_timeout, ex_class, &block)
f = Fiber.current
timer = EM::Timer.new(op_timeout) { f.resume(nil) }
res = block.call
timer.cancel
res
end
end
#!/usr/bin/env ruby
require 'ffi'
module FFI::Library
attr_reader :arg_types
alias_method :ffi_attach_function, :attach_function
def attach_function(name, func, args, returns = nil, options = nil)
mname, a2, a3, a4, a5 = name, func, args, returns, options
# Generated by ffi-gen. Please do not change this file by hand.
require 'ffi'
module Krad
extend FFI::Library
ffi_lib '/usr/local/lib/libkradradio_client.so'
def self.attach_function(name, *_)
begin; super; rescue FFI::NotFoundError => e
In file included from /home/defi/git/krad_radio/lib/krad_radio/krad_radio.h:40,
from /home/defi/git/krad_radio/lib/krad_mixer/krad_mixer.h:18,
from /home/defi/git/krad_radio/lib/krad_audio/krad_audio.h:26,
from ../lib/krad_alsa/krad_alsa.h:1,
from ../lib/krad_alsa/krad_alsa.c:1:
/home/defi/git/krad_radio/lib/krad_v4l2/krad_v4l2.h:21:28: error: linux/uvcvideo.h: No such file or directory