Skip to content

Instantly share code, notes, and snippets.

View dryan's full-sized avatar
Black Lives Matter

Dan Ryan dryan

Black Lives Matter
View GitHub Profile
from django.views.defaults import page_not_found as django_page_not_found
from django.views.decorators.csrf import requires_csrf_token
from django.views.defaults import ERROR_404_TEMPLATE_NAME
@requires_csrf_token
def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
path = request.path.strip("/")
# custom logic goes here
# see if there's a lowercase match
#! /usr/bin/env bash
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-v | --version)
shift
PY_VERSIONS+=($1)
shift
@dryan
dryan / models.py
Created March 26, 2024 17:15
Django false-positive migration
from django.contrib.gis.db import models
from django.utils.translation import gettext_lazy as _
def validate_is_true(value):
if value is not True:
raise ValidationError(validate_is_true.error_message)
validate_is_true.error_message = _("This field is required")
@dryan
dryan / middleware.py
Created September 13, 2023 14:40
Django CSP Middleware
import random
import string
import typing
from django.conf import settings
# if you have a Report-To service, add it to settings.py along with
# adding ReportToMiddleware to settings.MIDDLEWARE
@dryan
dryan / ci.yml
Created December 22, 2022 19:44
GitHub Actions workflow that queries EC2 for a list of instances with a specified tag name and value, gets those IP addresses, then sends a command via ssh to them
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
deploy:
@dryan
dryan / requirements.txt
Last active December 22, 2022 20:12
Update and audit GitHub action workflow.yml files for outdated versions
-i https://pypi.org/simple
anyio==3.6.2; python_full_version >= '3.6.2'
certifi==2022.12.7; python_version >= '3.6'
click==8.1.3; python_version >= '3.7'
colorama==0.4.6
commonmark==0.9.1
h11==0.14.0; python_version >= '3.7'
httpcore==0.16.3; python_version >= '3.7'
httpx==0.23.1
idna==3.4
BEGIN MESSAGE.
8rHFJDMpGIA41B8 QZMupuT8RVyFhvW 84aINuZp5plhrwt nDpHtI8d7rLSWxi
0ADNh9uwFOaUwzs VX4X9sLPkqpTCKq 6Xr2MZHgg4NiRQQ 4XMdUxe3HLsLbpo
JRL4KlRGMOWl8V2 iUcX5KqbTuLBJQI SfV7gcNmjUYqQzj GyD0qJpNZNUPCKY
ZuoHGCv6LPULidT gBacYA6j2iUe5Eb MjJ7d.
END MESSAGE.
#! /bin/sh
# From https://medium.com/@jonathan.leitschuh/zoom-zero-day-4-million-webcams-maybe-an-rce-just-get-them-to-visit-your-website-ac75c83f4ef5
# turns off video by default for your local user account
defaults write ~/Library/Preferences/us.zoom.config.plist ZDisableVideo 1
# To prevent the vulnerable server from running on your machine
# (this does not impact Zoom functionality), run these two lines in your Terminal.
pkill "ZoomOpener"; rm -rf ~/.zoomus; touch ~/.zoomus && chmod 000 ~/.zoomus;
pkill "RingCentralOpener"; rm -rf ~/.ringcentralopener; touch ~/.ringcentralopener && chmod 000 ~/.ringcentralopener;
# (You may need to run these lines for each user on your machine.)

Keybase proof

I hereby claim:

  • I am dryan on github.
  • I am dryan (https://keybase.io/dryan) on keybase.
  • I have a public key whose fingerprint is 3285 D024 0131 7A03 7787 458A 6088 6B14 0A92 6029

To claim this, I am signing this object:

@dryan
dryan / post-merge
Created August 8, 2014 21:38
update dependencies on git merge
#!/bin/bash
if [ -f 'package.json' ];
then
npm install
fi
if [ -f 'bower.json' ];
then
bower install
fi
if [ -f 'requirements.txt' ];