Skip to content

Instantly share code, notes, and snippets.

View jefftriplett's full-sized avatar
Living the dream

Jeff Triplett jefftriplett

Living the dream
View GitHub Profile
@vivgui
vivgui / bigger-tailwindcss-spacing-scale.js
Last active August 28, 2023 21:55
Here's a bigger spacing scale for TailwindCSS.
spacing: {
"13": '3.25rem',
"15": '3.75rem',
"17": '4.25rem',
"18": '4.5rem',
"19": '4.75rem',
"76": "19rem",
"84": "21rem",
"88": "22rem",
"92": "23rem",
@adamchainz
adamchainz / _base.html
Created January 8, 2021 14:34
Django HTMX CSRF setup
<script src="{% static 'app.js' %}" data-csrftoken="{{ csrf_token }}"></script>
@bmispelon
bmispelon / checkchoices.py
Last active December 6, 2020 17:39
A Django management command to find model fields where the declared choices doesn't match what's in the database
"""
When a model field defines a `choices` attribute, Django doesn't actually
generate a database constraint for that, which means it's possible to insert
data that doesn't match the choices.
See https://adamj.eu/tech/2020/01/22/djangos-field-choices-dont-constrain-your-data/
This command scans your database to try and find which fields have mismatched
data.
By default it scans all fields of all models of all installed apps, doing one
@williln
williln / drf-yasg-examples.py
Last active December 15, 2022 19:49
Some drf-yasg examples
from drf_yasg import openapi
from drf_yasg.utils import no_body, swagger_auto_schema
"""
For actions, a lot of times Swagger will pick up on the serializer you pass to serializer_class in the decorator.
But when you're using different input and output serializers or doing anything fancy, Swagger doesn't like it.
Swagger also isn't great at picking up on the status you return if you're not returning a 200 or 201.
"""
@seddonym
seddonym / durability.py
Last active September 13, 2024 09:24
Durable decorator
import functools
from django.conf import settings
from django.db import transaction, utils
def durable(func):
"""
Decorator to ensure that a function is not being called within an atomic block.
@tiran
tiran / python-on-debian.md
Last active May 21, 2024 08:46
Negative Python user experience on Debian/Ubuntu

Negative Python user experience on Debian/Ubuntu

The user experience of Python on a minimal Debian or Ubuntu installation is bad. Core features like virtual environments, pip bootstrapping, and the ssl module are either missing or do not work like designed and documented. Some Python core developers including me are worried and consider Debian/Ubuntu's packaging harmful for Python's reputation and branding. Users don't get what they expect.

Reproducer

The problems can be easily reproduced with official Debian and Ubuntu containers in Docker or Podman. Debian Stable (Debian 10 Buster) comes with Python 3.7.3. Ubuntu Focal (20.04 LTS) has Python 3.8.5.

Run Debian container

@elliottmorris
elliottmorris / election_night_live_model.R
Last active January 29, 2024 18:56
A live election-night prediction model using The Economist's pre-election forecast
#' Description
#' This file runs a live election-night forecast based on The Economist's pre-election forecasting model
#' available at projects.economist.com/us-2020-forecast/president.
#' It is resampling model based on https://pkremp.github.io/update_prob.html.
#' This script does not input any real election results! You will have to enter your picks/constraints manually (scroll to the bottom of the script).
#'
#' Licence
#' This software is published by *[The Economist](https://www.economist.com)* under the [MIT licence](https://opensource.org/licenses/MIT). The data generated by *The Economist* are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).
#' The licences include only the data and the software authored by *The Economist*, and do not cover any *Economist* content or third-party data or content made available using the software. More information about licensing, syndication and the copyright of *Economist* content can be fou
@SkYNewZ
SkYNewZ / Caddyfile
Created October 7, 2020 17:13
Example Caddyfile for using as load balancer
{
# Enable Debug mode
debug
# Disable admin API
admin off
}
localhost {
# https://caddyserver.com/docs/caddyfile/directives/push
@ruralocity
ruralocity / starship.toml
Created September 28, 2020 15:15
My current Starship.rs configuration file
# Don't print a new line at the start of the prompt
add_newline = false
# Disables the line_break module, making the prompt a single line.
[line_break]
disabled = true
# Replace the "❯" symbol in the prompt
[character]
symbol = "$"
from typing import cast
import libcst as cst
import libcst.matchers as m
from libcst.codemod import VisitorBasedCodemodCommand
from libcst.codemod.visitors import AddImportsVisitor, RemoveImportsVisitor
class DatetimeUtcnow(VisitorBasedCodemodCommand):