Skip to content

Instantly share code, notes, and snippets.

View superpermutation.rb
class SuperPermutation
CHARS = ('a'..'z').map(&:to_sym)
def initialize(size)
@size = size
@chars = CHARS.take(@size)
@used = {}
@index = Hash.new { |h, k| h[k] = [] }
@chars.permutation.each do |seq|
View folds.txt
rule Foldl-0 {
foldl $f $init ∅ = $init
}
rule Foldl-N {
$init $f $head = $init' / foldl $f $init' $tail = $res
------------------------------------------------------
foldl $f $init ($head $tail) = $res
}
View README.md

Haskell

There follows an extremely rough approximation to Haskell's type checker, written as a logic program. Mostly to explore type inference and syntactic sugar.

For the most part, we won't need a lot of syntactic checks in this implementation, but for terms with no internal structure, like variables and numbers, it's useful to specify their members.

View edit_message.rb
#!/usr/bin/env ruby
require "digest/sha1"
require "fileutils"
require "zlib"
GIT_DIR = ".git"
Commit = Struct.new(:id, :data) do
def self.path(id)
View package.json
{
"dependencies": {
"babel-core": "*",
"babel-loader": "*",
"babel-preset-env": "*",
"babel-preset-react": "*",
"css-loader": "*",
"react": "*",
"react-dom": "*",
"style-loader": "*",
View algorithmic_typing.pl
% vim: ft=prolog
% Parser
% ------
parse(S, T) :- atom_chars(S, C), expr(T, C, []).
expr(E) --> ws, (statement(E) ; type(E)), ws.
View blob.rb
Blob = Struct.new(:oid, :content) do
def type
Database::BLOB
end
def to_s
content
end
end
View git_index.rb
require "set"
class Index
SIGNATURE = "DIRC"
VERSIONS = [2, 3, 4]
HEADER_SIZE = 12
MIN_ENTRY_SIZE = 64
ENTRY_BLOCK = 8
View set.rb
require 'set'
class Foo
def ==(x)
true
end
def eql?(x)
false
end
View dcg.rb
require 'bundler/setup'
require 'infer'
program = Infer::Prolog.program <<-PL
s --> foo,bar,wiggle.
foo --> [choo].
foo --> foo,foo.
bar --> mar,zar.
mar --> me,my.
me --> [i].