Skip to content

Instantly share code, notes, and snippets.

Mark Smith judy2k

Block or report user

Report or block judy2k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
judy2k / trim
Created Mar 26, 2019
trim - a useful (but tiny) script to trim surrounding whitespace from some output.
View trim
#!/usr/bin/env python3
import sys
def main():
i =
judy2k /
Last active Feb 19, 2019
An Infinite Bag of Dice
import random
import re
import sys
def _roll_func(count, sides):
def _roll():
return sum(random.randint(1, sides) for _ in range(count))
return _roll
judy2k /
Created Jan 23, 2019
Phony! Fake phone number generator.
#!/usr/bin/env python3
import argparse
from random import randint, choice
def uk():
return randint(447700900000, 447700900999+1)
def us_area_code():
judy2k /
Last active Jul 3, 2018
EuroPython 2018: Women's Django Workshop

EuroPython 2018: Women's Django Workshop

EuroPython 2018 is pleased to host and sponsor a free Women's Django Workshop on Monday 23rd July, from 9am-6pm.

Would you like to learn about how to build websites, but don’t know where to start? A group of volunteers will lead you through HTML, CSS, Python & Django to build a blog in a one day workshop. No prior programming knowledge is needed to participate! If you would like to take part, apply for a spot by filling in our application form

EuroPython 2018 sponsors this event, providing space and catering, together with other facilities.

EuroPython ticket sales are picking up

judy2k /
Last active Jul 17, 2017
__qualname__ implementation in Python 2
from inspect import isclass
import __builtin__
# We're going to overwrite object, so we need to squirrel away the old one:
obj = object
# Metaclass, overriding the class' __getattribute__,
# so that __qualname__ can be generated and cached on access:
class QualnameMeta(type):
judy2k / may_the_4th.json
Last active Jun 7, 2017
May the 4th be with you!
View may_the_4th.json
"action": "talk",
"voiceName": "Brian",
"text": "May the fourth be with you!"
judy2k /
Created Apr 18, 2017
Save constructor arguments on self without writing self.x = x etc...
from inspect import signature
def auto_args(f):
sig = signature(f) # Get a signature object for the target:
def replacement(self, *args, **kwargs):
# Parse the provided arguments using the target's signature:
bound_args = sig.bind(self, *args, **kwargs)
# Save away the arguments on `self`:
for k, v in bound_args.arguments.items():
if k != 'self':
judy2k / tweet-syntax
Last active Mar 30, 2017
Generate a syntax-highlighted code snippet for Twitter
View tweet-syntax
#!/bin/bash -e
# tweet-syntax - Create a syntax-highighted PNG file of your code and save in /tmp
# Prerequisites:
# pip install --upgrade pygments pillow
# 'Source Code Pro' font (or change the script below)
# Usage: cat code.ext | tweet-syntax [<syntax>]
judy2k / parse_dotenv.bash
Created Mar 22, 2017
Parse a .env (dotenv) file directly using BASH
View parse_dotenv.bash
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
judy2k /
Created Mar 16, 2017
Monkey Patching Functions
# So, a bit like mocking/patching, it depends on how the thing you're patching is imported *where it's used*.
# If the code that uses it is in a module called `client`, you'd want to do one of the following:
# If looks like this:
from django.things import victim
def useful_function():
You can’t perform that action at this time.