Skip to content

Instantly share code, notes, and snippets.

 ​[object Object] :trollface:

Aaron Patterson tenderlove

 ​[object Object] :trollface:
View GitHub Profile
View fiddle_hacks.rb
# Fiddle, passing a pointer to an int. This gets the current process command
module Hacks
include Fiddle
func = "_NSGetExecutablePath"
path_ptr = Fiddle::Handle::DEFAULT[func]
path = path_ptr, [TYPE_VOIDP, TYPE_INTPTR_T], TYPE_INT, name: func
define_singleton_method(func, &path.to_proc)
tenderlove / ruby_jit.rb
Last active Jun 16, 2021
Use fisk and fiddle to patch a Ruby method at runtime
View ruby_jit.rb
require "fisk"
require "fisk/helpers"
require "fiddle/import"
module Ruby
extend Fiddle::Importer
typealias "VALUE", "uintptr_t"
View break_dance.rb
# Have you ever wanted lldb to break in a certain place, but you weren't
# sure where to set the breakpoint? Look no further than this script!
# This script creates a chunk of executable code that uses the int3 x86
# instruction. This instruction is defined for use by debuggers, and you can
# read more about it here:
# When that instruction is executed, the debugger will halt and you can do
# what you need!
View thing.rb
require "objspace"
require "json"
def go x
count = GC.stat(:major_gc_count)
loop do
info = JSON.parse(ObjectSpace.dump(x))
break if info["flags"]["old"]
View profileyarv.rb
#!/usr/bin/env ruby
require 'pp'
files = {'' => [], 'insns.def' => []}
current_insn = nil
current_filename = ''
lineno_offset = 0
IO.foreach('') do |line|
case line
when /^INSN_ENTRY\((\w+)\)/
tenderlove / ngpng.rb
Last active Dec 12, 2020
Simple PNG generation example that only depends on zlib in Ruby
View ngpng.rb
# Not Great PNG class. This is a very simple example of writing a PNG. It
# only supports colors from the color palette stored in `@palette`. This is
# meant to be example code, but I am using it in a program for visualizing
# heap dumps from Ruby.
# This is free and unencumbered software released into the public domain.
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
tenderlove /
Last active Dec 4, 2020
muck with RbConfig before RubyGems can
[aaron@tc-lan-adapter ~]$ cat x.rb
require "rbconfig"
# Change the compiler to "aarons-compiler"
RbConfig::CONFIG["CC"] = "aarons-compiler"
[aaron@tc-lan-adapter ~]$ RUBYOPT='-I/Users/aaron -rx' gem install sqlite3
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
View right_side.stl
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View foo.c
page_body = (struct heap_page_body *)rb_aligned_malloc(HEAP_PAGE_ALIGN, HEAP_PAGE_SIZE);
/* cut.. */
page = calloc1(sizeof(struct heap_page));
/* cut.. */
assert((getpagesize() * 4) == HEAP_PAGE_ALIGN);
intptr_t page_body_end = (intptr_t)page_body + (getpagesize() * 4);
View foo.c
page_body = (struct heap_page_body *)rb_aligned_malloc(HEAP_PAGE_ALIGN, HEAP_PAGE_SIZE);
/* cut.. */
page = calloc1(sizeof(struct heap_page));