Skip to content

Instantly share code, notes, and snippets.

MACHINE_RULEBOOK = DTMRulebook.new([
TMRule.new(:delete_next_bit, '0', :increment_counter, 'X', :left), # cross out 0 from input
TMRule.new(:delete_next_bit, '1', :increment_counter, 'X', :left), # cross out 1 from input
TMRule.new(:delete_next_bit, '_', :clean_up, '_', :left), # clean up the tape
TMRule.new(:delete_next_bit, 'X', :delete_next_bit, 'X', :right), # scan right
TMRule.new(:delete_next_bit, 'Z', :delete_next_bit, 'Z', :right), # scan right
TMRule.new(:increment_counter, '1', :increment_counter, 'Z', :left), # increment counter, carry the 1
TMRule.new(:increment_counter, 'Z', :delete_next_bit, '1', :right), # increment counter
TMRule.new(:increment_counter, '_', :delete_next_bit, '1', :right), # increment counter (overflowed)
@tomstuart
tomstuart / highlight.rb
Last active December 10, 2015 16:38
Syntax highlighting around inline markup
#!/usr/bin/env ruby
require 'nokogiri'
def highlight(document)
document.xpath('descendant::*[self::programlisting or self::screen][attribute::language]').each do |element|
tokens_and_types = tokenize(element.content, element[:language])
next_token, next_type = tokens_and_types.shift
element.xpath('descendant::text()').each do |text|
-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][
@tomstuart
tomstuart / gist:1466504
Created December 12, 2011 10:40
FizzBuzz in the lambda calculus in Ruby
>> IF = -> b { b }
=> #<Proc:0x007fb4e4049cc8 (lambda)>
>> LEFT = -> p { p[-> x { -> y { x } } ] }
=> #<Proc:0x007fb4e403d680 (lambda)>
>> RIGHT = -> p { p[-> x { -> y { y } } ] }
=> #<Proc:0x007fb4e4028ff0 (lambda)>
>> IS_EMPTY = LEFT
@tomstuart
tomstuart / gist:1113745
Created July 29, 2011 12:50
Parametric modules in Ruby
class Printable < Module
def initialize(string)
super()
define_method :print do
puts string
end
end
end
>> class A; include Printable.new('Hello'); end
$('[id|=progress-item]').click(function(event) {
var id = $(this).attr('id');
reader.moveToArticle(id.substr(id.lastIndexOf('-') + 1));
event.stopPropagation();
});