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
#By Robin Wellner (gvx) | |
#I hereby waive copyright and related or neighboring rights to this work | |
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/> | |
import sys | |
import subprocess | |
f = open (sys.argv[1], "r") | |
r = f.readline()[:-1] | |
f.close() |
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
#By Robin Wellner (gvx) | |
#I hereby waive copyright and related or neighboring rights to this work | |
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/> | |
#a simple way to create one object without having to maintain it's class | |
#only works in Python 3.x | |
@apply | |
class oneObject: | |
x = 6 |
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
def doc(f): | |
newdoc = f.__doc__ and [f.__doc__, ''] or [] | |
c = f.__code__ | |
ann = f.__annotations__ | |
max_i = c.co_argcount + c.co_kwonlyargcount | |
for arg_index in range(max_i): | |
name = c.co_varnames[arg_index] | |
if name in ann: | |
newdoc.append(name + ': ' + str(ann[name])) | |
else: |
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
func some function: | |
a test | |
catch handler: | |
some mistake | |
if this is wrong: | |
tell me why | |
elseif this should not fail: | |
hello | |
if hi: | |
bye |
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 tictactoe import * | |
class FluffHeuristic(Computer): | |
a = [0, 2, 8, 6] | |
b = [1, 5, 7, 3] | |
def play(self, board): | |
if not self.other.name: | |
for i in range(9): | |
x = board.get(i) | |
if x and x != self: |
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 itertools import product | |
def score(self, other): | |
first = len([speg for speg, opeg in zip(self, other) if speg == opeg]) | |
return first, sum([min(self.count(j), other.count(j)) for j in 'ABCDEF']) - first | |
possible = [''.join(p) for p in product('ABCDEF', repeat=4)] | |
results = [(right, wrong) for right in range(5) for wrong in range(5 - right) if not (right == 3 and wrong == 1)] | |
def solve(scorefun): |
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 Alias(object): | |
def __init__(self, initial): | |
self._set = {initial} | |
self.initial = initial | |
def add(self, alias): | |
self._set.add(alias) | |
def merge(self, other): | |
self._set.update(other._set) | |
def __iter__(self): | |
return iter(self._set) |
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
-- CC0, see http://creativecommons.org/publicdomain/zero/1.0/ etcetera, etcetera | |
function from(source, which) | |
local t = require(source) | |
local function import (which) | |
if which == '*' then | |
for k, v in pairs(t) do | |
if _G[k] == nil then | |
_G[k] = v | |
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
""" | |
formula.py - propositional formulas for Python | |
by Robin Wellner | |
Hereby, I waive all rights to this library, as described at <http://creativecommons.org/publicdomain/zero/1.0/> | |
Examples: | |
foo = Atom('foo') | |
bar = Atom('bar') |
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
-- kilobyte (and megabyte) constants | |
-- string like methods | |
-- implicit multiplication | |
-- successor function | |
debug.setmetatable(0, { __index = function(n, k) | |
if k == 'K' then | |
return n * 1024 | |
elseif k == 'M' then | |
return n * 1024 * 1024 | |
else |