This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Copyright (c) 2010, Almar Klein, Ant1, Marius van Voorden | |
# | |
# This code is subject to the (new) BSD license: | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# * Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Making kick-ass global objects for fun-and-profit DSLs. | |
module ScopeLifting | |
class Application | |
attr_accessor :options | |
def initialize | |
@options = Hash.new | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""`namedmatch` mimics `re.match` but also creates attributes based on the | |
values of the named captures. | |
Example | |
>>> string = 'foo bar baz' | |
>>> match = namedmatch(r'(?P<start>\w+) (?P<end>\w+)', string) | |
>>> print match.start | |
"foo" | |
>>> print match.end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mm import multimethod, symmultimethod | |
class Ship(object): | |
def __init__(self, name): | |
self.name = name | |
def __str__(self): | |
return self.name | |
class Asteroid(object): | |
def __init__(self, name): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
class Env(object): | |
"""Maintains the environment variables for local and global scope.""" | |
def __init__(self, env={}, parent=os.environ): | |
self.env = env.copy() | |
self.parent = parent.copy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pipeline import pipeline | |
@pipeline() | |
def foo(): | |
pass | |
@pipeline() | |
def baz(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pattern(r'^([a-zA-Z_\$\%][a-zA-Z_0-9\{\}]*)\s*:(?<=:)(?::([a-zA-Z_\$][a-zA-Z_0-9\{\}]*)?:)?\s*(.*)$') | |
def target(match, env=env): | |
labels = ('name', 'dep', 'components') | |
groups = dict(zip(labels, match.groups())) | |
for k, v in groups.iteritems(): | |
groups[k] = env.interp(v) if v else v | |
name, dep = groups['name'], groups['dep'] | |
components = re.findall('\w+', groups['components']) | |
makefile.addtarget(name, dep, components) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# $ gostart x | |
# vim x.go | |
FILENAME="$1" | |
cp "$GOROOT"/doc/Makefile . | |
sed -i '' -e "s/tmpltohtml/"$FILENAME"/g" -e 's/\.\./$\(GOROOT\)/' -e '/^#.*/d' Makefile | |
touch "$1".go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comonad w where | |
(=>>) :: w a -> (w a -> b) -> w b | |
extract :: w a -> a | |
data T a = L a | B (T a) a (T a) deriving (Eq, Show) | |
unit :: a -> T a | |
unit = L | |
counit :: T a -> a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Gabuzomeu a b = Gabu a | Zomeu b | |
deriving Show | |
shadok :: (a -> c) -> (b -> d) -> Gabuzomeu a b -> Gabuzomeu c d | |
shadok f _ (Gabu a) = Gabu (f a) | |
shadok _ g (Zomeu b) = Zomeu (g b) | |
newtype G b a = G {first :: Gabuzomeu a b} | |
deriving Show |