Skip to content

Instantly share code, notes, and snippets.

View judy2k's full-sized avatar

Mark Smith judy2k

View GitHub Profile
@judy2k
judy2k / the_importance_of_what_we_do.md
Created November 15, 2019 10:26
The Importance of What We Do
We couldn’t find that file to show.
@judy2k
judy2k / trim
Created March 26, 2019 11:13
trim - a useful (but tiny) script to trim surrounding whitespace from some output.
#!/usr/bin/env python3
import sys
def main():
i = sys.stdin.read()
sys.stdout.write(i.strip())
@judy2k
judy2k / dbag.py
Last active February 19, 2019 11:49
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
judy2k / phony.py
Created January 23, 2019 16:32
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
judy2k / post.md
Last active July 3, 2018 16:57
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
judy2k / know_thyself.py
Last active July 5, 2022 06:35
__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
judy2k / may_the_4th.json
Last active June 7, 2017 17:26
May the 4th be with you!
[{
"action": "talk",
"voiceName": "Brian",
"text": "May the fourth be with you!"
}]
@judy2k
judy2k / auto_args.py
Created April 18, 2017 13:48
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
judy2k / tweet-syntax
Last active March 30, 2017 09:36
Generate a syntax-highlighted code snippet for Twitter
#!/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
judy2k / parse_dotenv.bash
Created March 22, 2017 13:34
Parse a .env (dotenv) file directly using 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)