Skip to content

Instantly share code, notes, and snippets.

@bengosney
bengosney / pyproject.toml
Last active June 23, 2023 07:54
Base pyproject.toml
[project]
name = "New-Project"
description = "Replace this with a description"
version = "0.0.1"
authors = [{name = "Ben Gosney", email = "bengosney@googlemail.com"}]
dependencies = []
[project.optional-dependencies]
dev = ["black", "mypy", "pip-tools", "pre-commit", "icecream"]
#!/bin/bash
for PY in $(ls /usr/bin/python3.* | egrep "3.[0-9]+$"); do
PRI=$(echo $PY | egrep -o "[0-9]+$")
echo "Installing 3.$PRI"
update-alternatives --install /usr/bin/python python ${PY} ${PRI}
update-alternatives --install /usr/bin/python3 python3 ${PY} ${PRI}
done
@bengosney
bengosney / mailhog.service
Last active September 14, 2022 11:16
Systemd service that will run mailhog in docker and setup iptable rules to redirect all outgoing on ports 25, 587 and 465 back to mailhog
[Unit]
Description=MailHog service
After=docker.service
Wants=network-online.target docker.socket
Requires=docker.socket
[Service]
TimeoutStartSec=120
Restart=on-failure
RestartSec=5
@bengosney
bengosney / .pre-commit-config.yaml
Last active June 23, 2023 07:40
My default pre-commit for python
exclude: migrations/.*\.py|Procfile|[aw]sgi\.py|node_modules|.git|\.polar|inputs/.*
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-toml
@bengosney
bengosney / horizontal-scroll-shadow.scss
Created January 6, 2022 15:53
Add horizontal scroll shadow to an element
$size: 15px;
$background: white;
background-image:
linear-gradient(to right, $background, $background),
linear-gradient(to right, $background, $background),
radial-gradient(ellipse closest-side, rgba(0,0,0,.25) 0%,rgba(0,0,0,0) 100%),
radial-gradient(ellipse closest-side, rgba(0,0,0,.25) 0%,rgba(0,0,0,0) 100%);
background-position: left center, right center, -($size / 2) center, right (-($size / 2)) center;
background-repeat: no-repeat;
background-color: $background;
@bengosney
bengosney / Makefile
Last active June 23, 2023 08:01
Python Makefile
.PHONY: help clean test install all init dev
.DEFAULT_GOAL := install
.PRECIOUS: requirements.%.in
HOOKS=$(.git/hooks/pre-commit)
REQS=$(wildcard requirements.*.txt)
PYTHON_VERSION:=$(shell python --version | cut -d " " -f 2)
PIP_PATH:=.direnv/python-$(PYTHON_VERSION)/bin/pip
WHEEL_PATH:=.direnv/python-$(PYTHON_VERSION)/bin/wheel
@bengosney
bengosney / Makefile
Last active May 3, 2021 13:17
serve current dir over https
.PHONY := serv, cleancd
.DEFAULT_GOAL := serv
SCRIPTFILE=simple-https-server.py
CERT=server.pem
IP=$(shell hostname -I | cut -f 1 -d " ")
DIR=$(shell pwd)
$(SCRIPTFILE):
@echo "" > $@
@bengosney
bengosney / commit-msg
Created August 15, 2019 09:51 — forked from romellem/commit-msg
Git hook - Post-commit spell check (using `aspell`)
#!/bin/bash
ASPELL=$(which aspell)
if [ $? -ne 0 ]; then
echo "Aspell not installed - unable to check spelling" >&2
exit
else
WORDS=$($ASPELL --mode=email --add-email-quote='#' list < "$1" | sort -u)
fi
if [ -n "$WORDS" ]; then
printf "\e[1;33m Possible spelling errors found in commit message:\n\e[0m\e[0;31m%s\n\e[0m\e[1;33m Use git commit --amend to change the message.\e[0m\n\n" "$WORDS" >&2
@bengosney
bengosney / node-mkdirp.js
Last active January 12, 2018 15:50
`mkdir -p` for node, will create all missing directories. Please don't install a full blown npm package for 19 lines of code!
// Copyright 2018 Ben Gosney - MIT licence - https://opensource.org/licenses/MIT
const fs = require('fs');
const mkdirp = (full_path) => {
while (!fs.existsSync(full_path)) { // loop untill the full path excists
let part_path = full_path;
while(!fs.existsSync(part_path)) { // this will be true after we find a dir we can make then loop and start again
try {
@bengosney
bengosney / click_email_type.py
Created March 15, 2017 17:17
Email validator type for the click package http://click.pocoo.org/6/
import re
class EmailParamType(click.ParamType):
name = 'email'
email_re = re.compile(r"[^@]+@[^@]+\.[^@]+")
def convert(self, value, param, ctx):
if self.email_re.match(value):
return value
else: