Skip to content

Instantly share code, notes, and snippets.

View 0x0dea's full-sized avatar

D.E. Akers 0x0dea

  • North Carolina, US
View GitHub Profile
require 'minitest/autorun'
require 'minitest/pride'
# Given a flat array of positive integers, partition it into three sub-arrays
# whose sums are 5, 7, and 5, respectively, or nil if doing so is impossible.
#
# The argument is the syllable (mora) count of each word in some phrase, and
# the purpose of this method is cutting (kiru) the phrase into chunks which
# satisfy the 5-7-5 rule imposed upon modern haiku.
def kiru morae
require 'open3'
i, o = Open3.popen2 'ruby repl.rb'
line = nil
puts 'Gimme Ruby expressions to evaluate (in another process).'
Thread.new do
i.puts line while line = gets
i.close
@0x0dea
0x0dea / process_gsub.rb
Created April 26, 2015 23:08
Process.gsub lets you search and replace within your process's live memory!
def Process.gsub pat, sub
mem = File.open('/proc/self/mem', 'r+')
maps = File.open('/proc/self/maps')
maps.each do |map|
from, to, perms, offset = map.scan(/(\h+)-(\h+) (\S+) (\h+)/)[0]
if perms['rw']
from, to = [from, to].map { |addr| addr.hex + offset.hex }
data = mem.tap { |m| m.seek from }.read(to - from) rescue next
class Fixnum
def call prog
return unless self == 4
unless prog = prog.delete(' ')[/\A3\.(\d*)4\z/, 1]
raise SyntaxError, "Program must begin '3.' and end '4'.", caller
end
arity = [3, 3, 3, 3, 0, 1, 2, 1, 1, 0]
cells = [i = pc = 0] * 100
insns, loops, stack = [], {}, []
@0x0dea
0x0dea / hspal
Last active June 10, 2021 03:46
This is a Ruby interpreter for Hexadecimal Stacking Pseudo-Assembly Language, an esolang devised by ‎SuperJedi224. With its single register and multitude of independent stacks, it feels a bit like Whitespace turned inside-out.
#!/usr/bin/env ruby
class HSPAL
# Enforce unsigned 16-bit data by clamping all entries.
class Stack < Array
def << val
super [0, val, 0xFFFF].sort[1]
end
end