Skip to content

Instantly share code, notes, and snippets.

>>> 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)
! 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
@justinfay
justinfay / pmd
Created November 23, 2017 13:05
Simple markdown file preview with firefox
#!/usr/bin/env bash
pandoc -t html $1 | firefox "data:text/html;base64,$(base64 -w 0 <&0)"
@justinfay
justinfay / fib.py
Last active February 8, 2017 11:35
from functools import wraps
def memo(fn):
c = {}
@wraps(fn)
def dec(*args):
if args not in c:
r = fn(*args)
"""
Quick POC for parsing a PHP array from python.
"""
from pyparsing import *
"""
array
( members )
()
"""
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.
# http://theorangeduck.com/page/you-could-have-invented-parser-combinators
stream = list('abcdefghijklmnopqrstuvwxyz')
def literal(char):
"""
Parser which matches a character.
"""
def parser(stream):
@justinfay
justinfay / curry.py
Created August 9, 2016 13:46
Simply curried functions in python
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
@justinfay
justinfay / gensieve.py
Last active July 29, 2016 10:39
generator sieve of eratosthenes
"""
A thought that came to me last night in bed.
A generator of erathomous!
"""
class Sieve:
def __init__(self):
def series():
i = 1
import re
odd_backslash = re.compile(r'((?<!\\)(\\\\)*\\(?!\\))')
def php_escape(value):
try:
return "'" + odd_backslash.sub(
r'\\\1', value.replace("'", r"\'")) + "'"