Skip to content

Instantly share code, notes, and snippets.

View mattgreen's full-sized avatar

Matt Green mattgreen

View GitHub Profile
@cheery
cheery / cek.py
Created May 10, 2015 12:53
CEK abstract machine
# I glanced through the pycket paper, saw few rules there. Ended up to doing this.
class Var(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
class Lam(object):
@adamnew123456
adamnew123456 / arithmetic.py
Last active February 11, 2024 15:49
Pratt Parser For Arithmetic Expressions
"""
This implements a fairly simple expression language via a Pratt-style parser.
The language supports fairly standard floating point literals, such as:
5
1.09
.16
12e7
@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
@neel-krishnaswami
neel-krishnaswami / re.ml
Created November 7, 2013 12:20
Implementation of DFA-based regexp matching using Antimirov derviatives
type re = C of char | Nil | Seq of re * re | Bot | Alt of re * re | Star of re
let rec null = function
| C _ | Bot -> false
| Nil | Star _ -> true
| Alt(r1, r2) -> null r1 || null r2
| Seq(r1, r2) -> null r1 && null r2
module R = Set.Make(struct type t = re let compare = compare end)
let rmap f rs = R.fold (fun r -> R.add (f r)) rs R.empty
@istepanov
istepanov / lcs.py
Created September 10, 2013 08:23
Search longest common substrings using generalized suffix trees built with Ukkonen's algorithm, written in Python 2.7
#!/usr/bin/env python
# -*- coding: utf-8
"""
Search longest common substrings using generalized suffix trees built with Ukkonen's algorithm
Author: Ilya Stepanov <code at ilyastepanov.com>
(c) 2013
"""
@mislav
mislav / _readme.md
Last active April 24, 2025 10:07
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

@ijp
ijp / SECD2.hs
Created February 18, 2013 22:21
-- An implementation of Peter Landin's SECD machine, as described in
-- "The Mechanical Evaluate of Expressions"
import Prelude hiding (lookup)
type Name = String
data Expr a = ID Name
| Obj a
| Fun Name (Expr a)
| Apply (Expr a) (Expr a)
@bokmann
bokmann / ActiveRepository.rb
Created March 27, 2012 16:15
ActiveRepository Strawman
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks
# of the ActiveRecord pattern. Several apps I have seen, and several
# developers I have spoken to are looking towards other patterns for object
# persistence. The major drawback with ActiveRecord is that the notion
# of the domain object is conflated with what it means to store/retrieve
# it in any given format (like sql, json, key/value, etc).
#
# This is an attempt to codify the Repository pattern in a way that would
# feel comfortable to beginner and seasoned Ruby developers alike.
#
@sw17ch
sw17ch / indented_parsec_example.lhs
Created March 16, 2012 04:31
A full example demonstrating the use of the indentation parser provided by the 'indents' package: http://hackage.haskell.org/package/indents
> module Main where
First, import all the needed modules.
> import Text.Parsec hiding (State)
> import Text.Parsec.Indent
> import Control.Monad.State
Next, define our new Parser type. This replaces the Identity monad
with the (State SourcePos) monad.
// as NSObject
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
[mapping mapKeyPath:@"numbers" toAttribute:@"orderedSet"];
TestMappable* object = [[[TestMappable alloc] init] autorelease];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
id data = [parser objectFromString:@"{\"numbers\":[1, 2, 3]}" error:nil];
RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
BOOL success = [operation performMapping:nil];