Skip to content

Instantly share code, notes, and snippets.

View judy2k's full-sized avatar

Mark Smith judy2k

View GitHub Profile
@judy2k
judy2k / run.fish
Created September 14, 2024 10:31
Fish Shell: Expand 'run' to an appropriate 'run' command, depending on the files in the current directory.
function _expand_run
-d "Expand the 'run' abbreviation into a project-specific run command.";
if test -e Justfile;
echo just run
else if test -e Makefile;
echo make run
else if test -e Cargo.toml
echo cargo run
else if test -e package.json
echo npm run dev
@judy2k
judy2k / atlas-uri
Last active June 27, 2024 11:38
A script to generate a user for a MongoDB Atlas project.
#!/bin/bash
# Create a database user with a random password, and print out a MongoDB connection string for that database.
#
# Requires: python >= 3.6, jq, and atlas-cli
set -e
CLUSTER='Sandbox'
@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':