Skip to content

Instantly share code, notes, and snippets.

View judy2k's full-sized avatar

Mark Smith judy2k

View GitHub Profile
@judy2k
judy2k / next_weekday.py
Created January 9, 2016 11:54
Find the next weekday after the given date.
from datetime import date, timedelta
def next_weekday(d):
wd = d.weekday()
return d + timedelta(days=1 if wd < 4 else 7 - wd)
@judy2k
judy2k / do-stuff-with-found-files.bash
Last active September 28, 2015 11:08
Bash tricks and tips
# The following allows working with files with spaces in the names that come back from find:
find . -name 'names-with-spaces-maybe' -print0 | while read -d $'\0' file; do
do-stuff-with "$file"
done
@judy2k
judy2k / gradually_worse_pi.py
Created August 20, 2015 08:53
A module to hide in a codebase. Each time math.pi is requested its value will change by a tiny amount, gradually drifting away from the correct value.
import sys
import math as _math
__doc__ = _math.__doc__
class NewMath(object):
_pi = _math.pi
@property
def pi(self):
@judy2k
judy2k / list_branches.sh
Created March 13, 2015 10:11
List git branches
for f in `ls`; do
if [ -d $f/.git ]; then
fb=$(git --git-dir=$f/.git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* //")
echo $f: $fb
fi
done
def call_me(names=[]):
names.append('Stupid')
print ' '.join(names)
for _ in range(10):
call_me()
@judy2k
judy2k / fizz_buzz_decorator_abomination.py
Last active August 29, 2015 14:13
A bunch of attempts to create a really horrible fizz buzz implementation in Python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from functools import wraps
def test(condition):
def test_decorator(f):
@wraps(f)
def test_wrapper(n):
@judy2k
judy2k / uc.py
Created October 15, 2014 14:09 — forked from anonymous/uc.py
Traceback (most recent call last):
File "./uc.py", line 7, in <module>
u += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 1: ordinal not in range(128)
@judy2k
judy2k / writeable_closures.py
Last active August 29, 2015 14:07
Writeable Closures
#!/usr/bin/env python
def outer():
i = [0]
def inner():
i[0] += 1
print i[0]
return inner
f = outer()

Keybase proof

I hereby claim:

  • I am judy2k on github.
  • I am judy (https://keybase.io/judy) on keybase.
  • I have a public key whose fingerprint is 1F8A C55A EC5F F23B 013A DDD2 F298 5834 FAE5 4325

To claim this, I am signing this object:

@judy2k
judy2k / one_line_regex.py
Created May 12, 2014 10:22
Python regex matching and capturing in one line
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re, sys
def magic_match(pattern, target):
frame = sys._getframe(1)
result = re.match(pattern, target)
# This is properly, properly evil. Don't do this: