This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [], {}, [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
#/ Usage: mnemo [filename] | |
#/ | |
#/ Options: | |
#/ -h, --help Show this help message | |
#/ -v, --version Show application version | |
VERSION = "1.0.1" | |
LETTER_MAP = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Ova | |
# autovivifying map from [class][method][signature] to Method | |
@@Ova = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } | |
# Wrap #respond_to? for parity with Class#===. | |
Responder = Struct.new(:method) do | |
def === obj | |
obj.respond_to?(method) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Wanted to see if you were here today! yes/no? " | |
def handle_yes | |
puts "sweet! What time is good for you?" | |
time = gets.chomp | |
puts "Right on, I'll see you at #{time}!!" | |
end | |
def handle_no | |
puts "Sad. Next week it is!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'stringio' | |
def find_constant const | |
return nil unless Object.const_defined? const | |
value = Object.const_get const | |
$stderr = StringIO.new | |
Object.const_set const, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
s = TCPSocket.new 'irc.freenode.net', 6667 | |
s.puts "NICK slowlag" | |
s.puts "USER slowlag 0 * :slowlag" | |
s.puts "JOIN #ruby-offtopic" | |
all = File.read('all').split("\n") | |
can = all.dup |
NewerOlder