Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
@mark
mark / nonagram_row.rb
Created August 15, 2018 18:13
Fill in partial row clues for a nonagram row
CHAR_TO_CELL = { '_' => :unknown, 'x' => :empty, '#' => :full, '?' => :multiple }
CELL_TO_CHAR = { empty: 'X', full: '#', multiple: '_', unknown: '_' }
def expand_row raw_row
split = raw_row.split /([_X#]\d*)/
items = split.reject { |s| s == '' }
items.map do |item|
item[0] * [1, item[1..-1].to_i].max
end.join.split('').map { |c| CHAR_TO_CELL[c] }
@mark
mark / xkcd-tracery.json
Created December 18, 2017 19:02
Tracery implementation of XKCD #1930: https://xkcd.com/1930/
{
"origin": ["Did you know that #fact# #what# because of #reason#? Apparently #cause#."],
"fact": [
"the #odd-season# Equinox",
"the #even-season# #even-event#",
"the #timing# #sun-event#",
"Daylight #savings# Time",
"Leap #leap#",
"Easter",
require 'fiber'
require 'pp'
class MyWrapper
include Enumerable
def initialize
@fiber = fiber
@results = []
end
inputs = [[:sensor, "input1", 0], [:sensor, "input2", 1], [:sensor, "input3", 2], [:sensor, "input4", 3], [:sensor, "input5", 4], [:sensor, "input6", 5], [:sensor, "input7", 6], [:sensor, "input8", 7], [:sensor, "input9", 8], [:sensor, "input10", 9], [:sensor, "input11", 10], [:sensor, "input12", 11], [:sensor, "input13", 12], [:sensor, "input14", 13], [:sensor, "input15", 14], [:sensor, "input16", 15], [:sensor, "input17", 16], [:sensor, "input18", 17], [:sensor, "input19", 18], [:sensor, "input20", 19]]
outputs = [[:effector, "output1", 0], [:effector, "output2", 39], [:effector, "output3", 40], [:effector, "output4", 41], [:effector, "output5", 42], [:effector, "output6", 43], [:effector, "output7", 44], [:effector, "output8", 45], [:effector, "output9", 46], [:effector, "output10", 47], [:effector, "output11", 48], [:effector, "output12", 49], [:effector, "output13", 50], [:effector, "output14", 51], [:effector, "output15", 52], [:effector, "output16", 53], [:effector, "output17", 54], [:effector, "outp
@mark
mark / priority_n.rb
Created December 7, 2013 04:44
Priority/n generator
def priority(n)
WireMind::Circuits::Circuit.new.tap do |priority|
# I/O
inputs = (1..n).map { |idx| priority.input("input#{idx}") }
outputs = (1..n).map { |idx| priority.output("output#{idx}") }
# Nodes
@mark
mark / bash.shard.rb
Created October 24, 2013 04:20
Bash output helpers (stupid early)
module Bash
def self.clear
print "\e[H\e[2J"
end
end
@mark
mark / memstats.rb
Created October 18, 2013 15:52 — forked from kenn/memstats.rb
#!/usr/bin/env ruby
#------------------------------------------------------------------------------
# Aggregate Print useful information from /proc/[pid]/smaps
#
# pss - Roughly the amount of memory that is "really" being used by the pid
# swap - Amount of swap this process is currently using
#
# Reference:
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361
@mark
mark / object_count_change.shard.rb
Created October 15, 2013 19:29
A method for tracking the change in counts of objects in ObjectSpace
module Kernel
def object_count_change(root = ActiveRecord::Base)
before = Hash.new(0).tap { |hash| ObjectSpace.each_object(root) { |obj| hash[obj.class.to_s] += 1 } }
yield
after = Hash.new(0).tap { |hash| ObjectSpace.each_object(root) { |obj| hash[obj.class.to_s] += 1 } }
Hash.new.tap do |change|
all_keys = (before.keys + after.keys).uniq.sort
all_keys.each { |key| change[key] = after[key] - before[key] }
end
@mark
mark / bindings.rb
Created October 13, 2013 22:23
Unification in Ruby
require 'set'
class Bindings
################
# #
# Declarations #
# #
################