Skip to content

Instantly share code, notes, and snippets.

@coderanger
coderanger / craft.py
Created January 9, 2022 03:20
FarmRPG crafting calculator
import math
from typing import Optional
import attr
from frozendict import frozendict
@attr.s(auto_attribs=True, frozen=True)
class Item:
name: str
@coderanger
coderanger / README.md
Last active August 18, 2023 18:33
How to patch Ubuntu for Heartbleed

How to patch Ubuntu for Heartbleed

  1. sudo apt-get update
  2. sudo apt-get install -y libssl1.0.0 openssl
  3. openssl version -a and confirm the "built on" date is >= 2014-04-07
  4. sudo lsof -n | grep ssl | grep DEL and restart all listed services.

Repeat #4 until no results are returned.

@coderanger
coderanger / README.md
Last active August 1, 2023 17:40
My incident report template

[My company] Incidents

This repository contains incident reports for all [my company] products and services.

How to document an incident?

Copy the template.md file to a new file named YYYY-mm-dd-title-of-incident.md, eg. 2021-09-08-database-outage.md. Make sure the date is correct for UTC rather than your local time zone, for California staff this might mean the incident happened "tomorrow". Then fill in all the fields in the template and create a Pull Request. The [my team] team will review and merge it.

What counts as an incident?

@coderanger
coderanger / login.py
Created June 5, 2021 22:19
DRF login view.
from typing import Optional
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import AbstractBaseUser
from rest_framework.exceptions import ParseError
from rest_framework.permissions import AllowAny
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.throttling import ScopedRateThrottle
from rest_framework.views import APIView
# This is the entire preseed config file used on an example Lucid system. See the preseed
# documentation for more information on the options here. This will use US English by default.
#
# https://help.ubuntu.com/10.04/installation-guide/amd64/preseed-contents.html
#
# This preseed will automatically install Ubuntu 10.04 with default options. Understand what
# it is doing before you use it.
#
# Boot Options line:
#
@coderanger
coderanger / __main__.py
Last active April 26, 2020 10:17
Django on Twisted with Prometheus
"""
Support for running `python -m myapp`.
"""
from myapp.wsgi import main
if __name__ == "__main__":
main()
@coderanger
coderanger / admin.py
Created August 31, 2010 22:45
Pagination for admin inlines
class MyInline(admin.TabularInline):
model = MyModel
extra = 0
template = 'admin/edit_inline/list.html'
def get_formset(self, request, obj=None, **kwargs):
FormSet = super(ActivationKeyInline, self).get_formset(request, obj, **kwargs)
class NewFormSet(FormSet):
def _construct_forms(self, *args, **kwargs):
qs = self.get_queryset()
@coderanger
coderanger / traefik.yaml
Created November 6, 2018 20:12
Traefik quick start
---
apiVersion: v1
kind: Namespace
metadata:
name: traefik
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik
@coderanger
coderanger / Dockerfile
Last active August 17, 2018 00:51
Dockerfile snippet for Caddy build
###################
# Caddy build image
FROM abiosoft/caddy:builder
ARG caddy_version="0.11.0"
ARG caddy_plugins="cors,realip,expires,proxyprotocol,prometheus"
ENV ENABLE_TELEMETRY="false"
# Disable a bunch of standard plugins we don't need.
RUN sed -i "/# build/a sed -Ei '/caddyhttp.(basicauth|browse|fastcgi|markdown|templates|websocket)/d' /go/src/github.com/mholt/caddy/caddyhttp/caddyhttp.go" /usr/bin/builder.sh
@coderanger
coderanger / email.md
Created June 9, 2018 23:19
Crazy good spam

From: 7N5C 7n5corp@gmail.com

Subject: Converstion with you

Noah,

My name is Stella Hughes and I would like to have a conversation with you about a project I have been trying to develop for the past several years.