Skip to content

Instantly share code, notes, and snippets.

View frankwiles's full-sized avatar
💻
Artisanal bits built just for you!

Frank Wiles frankwiles

💻
Artisanal bits built just for you!
View GitHub Profile
@frankwiles
frankwiles / normal_way.py
Created March 7, 2023 01:55
Django string relationships to avoid circular imports
from django.db import models
from app1.models import ModelOne
from app2.models import ModelTwo
class ThingInThisApp(models.Model):
one = models.ForeignKey(ModelOne, related_name="things", on_delete.models.CASCADE)
two = models.ForeignKey(ModelTwo, related_name="things", on_delete.models.CASCADE)
# ...
@frankwiles
frankwiles / Usage in Ipython
Created July 12, 2019 21:10
Keeping Django Models Ordered Example
from tasks.models import *
t = Task.objects.create(name="Test1")
s1 = Step.objects.create(task=t, name="Testing1")
s2 = Step.objects.create(task=t, name="Testing2")
s3 = Step.objects.create(task=t, name="Testing3")
s4 = Step.objects.create(task=t, name="Testing4")
# Show the existing numbers/structure

Keybase proof

I hereby claim:

  • I am frankwiles on github.
  • I am frankwiles (https://keybase.io/frankwiles) on keybase.
  • I have a public key whose fingerprint is 782D A1E3 A547 E219 FD44 C7A0 BDE8 83DD D590 08CA

To claim this, I am signing this object:

@frankwiles
frankwiles / logbook-file-example.py
Created May 19, 2016 20:54
Logbook File Example
from logbook import Logger, FileHandler
FileHandler('./output.log').push_application()
log = Logger('my-example-logger')
log.info("Testing")
# Output in ./output.log
# [2016-05-19 20:53:53.095826] INFO: my-example-logger: Testing
@frankwiles
frankwiles / blocks.py
Created May 17, 2015 03:13
Code and Markdown blocks for Wagtail 1.0 StreamField
from django.utils.safestring import mark_safe
from markdown import markdown
from pygments import highlight
from pygments.formatters import get_formatter_by_name
from pygments.lexers import get_lexer_by_name
from wagtail.wagtailcore import blocks
class CodeBlock(blocks.StructBlock):
@frankwiles
frankwiles / gist:5101648
Created March 6, 2013 18:15
AWS CORS configuration
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
@frankwiles
frankwiles / gist:4024500
Created November 6, 2012 12:50
Rebuild a broken Python virtualenv on heroku
# Execute these commands in order to rebuild a virtualenv from scratch
$ heroku labs:enable user-env-compile
$ heroku config:set CLEAN_VIRTUALENV=yes
$ heroku config:set VIRTUALENV_DIRS=.heroku/venv
$ git push heroku master
$ heroku config:unset CLEAN_VIRTUALENV
$ heroku config:unset VIRTUALENV_DIRS
$ heroku labs:disable user-env-compile
@frankwiles
frankwiles / first-five.sql
Created September 14, 2012 18:54
Index on first 5 characters of a column
CREATE TABLE song (
title varchar(20),
);
CREATE INDEX firstfive_idx ON song WHERE substring(title, 0, 6);
SELECT * FROM song WHERE substring(title, 0, 6) = 'foobar1' AND title='foobar1bazbazwheeheee!';
@frankwiles
frankwiles / gist:3531321
Created August 30, 2012 15:45
vim trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
@frankwiles
frankwiles / gist:2051463
Created March 16, 2012 17:52
RFC valid E-mail address regular expression
[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\
xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xf
f\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\x
ff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015
"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\
xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80
-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*
)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\
\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\
x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x8