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
@mark
mark / def.shard.rb
Last active August 31, 2015 12:24 — forked from zobar/def.shard.rb
Nested function definitions are a bad idea in Ruby.
#!/usr/bin/env ruby -w
def defit
def ohai
puts "hello from #{self.class.inspect} #{self.inspect}"
end
puts "called defit in #{self.class.inspect} #{self.inspect}"
end
class MyClass
def foo
puts "MyClass -> foo"
bar
end
def bar
puts "MyClass -> bar"
end
end
cities = ('a'..'p').to_a
def generate_lists(cities)
pos = cities.combination(3).to_a.shuffle; nil
map = {}
cities.each do |c|
taken = []
while taken.length < 3
c3 = pos.shift
if c3.include? c
Marks-MacBook-Pro:code_scraps markjosef$ irb
irb(main):001:0> require './private_clobbering'
=> true
irb(main):002:0> obj = MyClass.new
=> #<MyClass:0x007ff8220fc680>
irb(main):003:0> obj.public_a
Public A
Private B
=> nil
irb(main):004:0> obj.public_b
@mark
mark / gist:12cb9f08bf943101aa69
Last active August 29, 2015 14:06
Paper Soccer rules

Paper Soccer

This is a pencil-and-paper version of the game soccer. Two players compete to get the ball into the opposing player's goal, scoring a point. Each point is played on a different field, and there are two fields per page.

The first player with 3 points wins the game.

How to play:

The ball starts at the center of the field (marked by a small circle). For the first point, flip a coin to decide who goes first; for later points, the player who just scored goes second.

@mark
mark / class_method_double.rb
Created August 1, 2014 18:51
Redefining a stubbed method, using Mocha
require 'minitest/spec'
require 'mocha/setup'
require 'minitest/autorun'
class MyClass
class << self
attr_accessor :bar
end