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 adder_and_reset(n): | |
... a = [n] | |
... def adder(y): | |
... return y + a[0] | |
... def reseter(y): | |
... a[0] = y | |
... return [adder, reseter] | |
... | |
>>> a, r = adder_and_reset(1) | |
>>> a(2) |
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
! urxvt | |
URxvt*geometry: 115x40 | |
!URxvt*font: xft:Liberation Mono:pixelsize=13:antialias=true:hinting=true | |
URxvt*font: xft:Inconsolata:pixelsize=18:antialias=true:hinting=true | |
URxvt*boldFont: xft:Inconsolata:bold:pixelsize=18:antialias=true:hinting=true | |
!URxvt*boldFont: xft:Liberation Mono:bold:pixelsize=13:antialias=true:hinting=true | |
URxvt*depth: 24 | |
URxvt*borderless: 1 | |
URxvt*scrollBar: false |
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 | |
pandoc -t html $1 | firefox "data:text/html;base64,$(base64 -w 0 <&0)" |
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 functools import wraps | |
def memo(fn): | |
c = {} | |
@wraps(fn) | |
def dec(*args): | |
if args not in c: | |
r = fn(*args) |
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
""" | |
Quick POC for parsing a PHP array from python. | |
""" | |
from pyparsing import * | |
""" | |
array | |
( members ) | |
() |
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
""" | |
Taken from: https://learnxinyminutes.com/docs/brainfuck/ | |
There are eight commands: | |
+ : Increments the value at the current cell by one. | |
- : Decrements the value at the current cell by one. | |
> : Moves the data pointer to the next cell (cell on the right). | |
< : Moves the data pointer to the previous cell (cell on the left). | |
. : Prints the ASCII value at the current cell (i.e. 65 = 'A'). | |
, : Reads a single input character into the current cell. |
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
# http://theorangeduck.com/page/you-could-have-invented-parser-combinators | |
stream = list('abcdefghijklmnopqrstuvwxyz') | |
def literal(char): | |
""" | |
Parser which matches a character. | |
""" | |
def parser(stream): |
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 curry(func, args=None): | |
args = args if args else [] | |
def curried(arg): | |
args.append(arg) | |
try: | |
return func(*args) | |
except TypeError: | |
return curry(func, args) | |
curried.__name__ = "curry(%s)" % func.__name__ | |
return curried |
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
""" | |
A thought that came to me last night in bed. | |
A generator of erathomous! | |
""" | |
class Sieve: | |
def __init__(self): | |
def series(): | |
i = 1 |
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 re | |
odd_backslash = re.compile(r'((?<!\\)(\\\\)*\\(?!\\))') | |
def php_escape(value): | |
try: | |
return "'" + odd_backslash.sub( | |
r'\\\1', value.replace("'", r"\'")) + "'" |