Skip to content

Instantly share code, notes, and snippets.

What is this?

This is a ruby C extension that defines a global method named current_iseq. It returns the instruction sequence of the context it was called from.

I couldn't find any other way to get a reference to the method being called from within the method itself. The closest you can get is probably __callee__ which just gives you the name of the method. There's no guarantee that getting a method object using something like method(__callee__) will actually give you the method it's being called from.

@benolee
benolee / 00 README.md
Last active April 13, 2023 23:48
arg_scanner gem

terminal 1

$ brew install glib
$ C_INCLUDE_PATH=/usr/local/opt/glib/include/glib-2.0/ gem install arg_scanner
$ mkfifo /tmp/ruby-type-inference-pipe-42
$ arg-scanner --type-tracker --pipe-file-path=/tmp/ruby-type-inference-pipe-42 bundle exec rails console
[1] pry(main)> app.get('/')

terminal 2. sample output. this is prettified and truncated, btw.

@benolee
benolee / 00_NES_DOOM.mkd
Last active April 13, 2023 23:47
NES DOOM

NES DOOM

https://www.youtube.com/watch?v=gCWhWBtu0LA

21_various_games

The NES is connected to the graphics memory on the cartridge via groups of signals called buses. There's the Address Bus and the Data Bus. When the NES wants to access graphics memory on the cartridge, it puts the memory address it wants in the Address Bus. The memory chip then grabs the data at this address and transfers it to the NES via the Data Bus.

10_address_bus_data_bus

RbStringIndices

What is this?

rb_string_indices is a rust native extension for ruby String that returns all indices for matches of a given substring.

How does it work?

It's using a ruby and rust interop library called rutie.

N8Pro SAV Map:

N8Pro Sav            Nes / Cart
0000:07FF            CPU 0000:07FF (ram)
0800:17FF            PPU 2000:2FFF (nametables)
1800:187F            Mapper Registers
1880:189F            APU Registers                      
18A0:18BF            PPU 3F00:3F1F (palettes)
18C0:18C7            Ppu Registers (CTRL, MASK, Scroll_HI, Scroll_LO)
const workerHandler = `function (e) {
if (e.data === 'ping') {
self.postMessage('pong')
} else {
self.setTimeout(function () {
self.postMessage('tack')
}, 1000/60)
}
}`
const worker = new Worker(
@benolee
benolee / ninja-gaiden-ii.lua
Last active April 13, 2023 23:46
Mesen port of Scumtron's Lua Script for Ninja Gaiden II
-- Q, W, I, A keys while unpaused or frame-advancing toggles stuff
-- for Mesen 0.9.9
local bit = require "bitop_funcs".bit
local function BIT(x)
return bit.bor(0, 2^x)
end
function tobitstring(n,m)

vedis bash loadable

what is this?

Loadables in bash are exactly like builtins, but you enable or disable at runtime. They're shared libraries whose main interface is receiving the WORD_LIST, which is basically the last command.

For this loadable, I want to provide nice data structures directly to bash.

Vedis is an embeddable self-contained library with commands and data structures from Redis, but without the networking.

require 'zlib'
module (Module.new)::Digest
ROT13 = 'a'.upto('z').zip('a'.upto('z').lazy.cycle.drop(13)).then { |r| r.concat r.map { |a| a.map(&:upcase) } }.to_h
def rot13_digest(s)
String.new(encoding: Encoding::BINARY).tap { |buffer|
Zlib
.deflate(s, Zlib::NO_COMPRESSION)
.each_char
.map { |c| ROT13[c] }
using System;
using System.IO;
using ICSharpCode.SharpZipLib.NotThreadSafe.Zip;
using Sang.Common;
using Sang.Utility;
using Sang.Voxel;
namespace Sang.Map
{
// Token: 0x02000271 RID: 625