Skip to content

Instantly share code, notes, and snippets.

@funkybob
funkybob / gist:49a9f40aad801f80b861e61baa8bc878
Created September 14, 2023 00:17
Code to dump list of default URL patterns for a Django app (run from manage.py shell)
from django.urls import get_resolver
res = get_resolver()
def get_patterns(m, prefix):
nprefix = prefix + (m.pattern.describe(),)
yield nprefix
for p in getattr(m, 'url_patterns', []):
yield from get_patterns(p, nprefix)
<svelte:options tag="my-todo" />
<h1>Todos Svelte</h1>
<section>
<TodoInput on:add={addTodo}></TodoInput>
<ul id="list-container">
{#each items as item, index (item.id)}
<TodoItem
bind:checked={item.checked}
bind:text={item.text}
FROM python/3.7
# Install system dev packages
RUN apt update -y && \
apt install -y libmariadbclient-dev gcc
# Build wheels of all our requirements
COPY requirements/requirements.txt requirements/requirements.txt
RUN mkdir wheels/ && \
pip install -U pip && \
@funkybob
funkybob / gist:5bceb85ddef4db3fe2bebbc69c69829a
Last active February 3, 2019 22:01
gilbert - an overview
A gilbert project is a directory with 5 sub directories:
- static/
- pages/
- content/
- templates/
- dest/
Upon calling render, the site will:
- create an index of files in static; only referenced files will be copied to the destination
@funkybob
funkybob / parse.py
Last active September 16, 2016 07:34
from __future__ import absolute_import
from uuid import uuid4
import parse
from django.urls.resolvers import RegexURLPattern, RegexURLResolver, ResolverMatch
def parse_uuid(text):
return uuid4(text)
(function () {
function Router() {
EventTarget.call(this);
this.rules = [];
window.addEventListener('hashchange', this.hashChange.bind(this));
window.addEventListener('popstate', this.hashChange.bind(this));
}
Router.prototype = Object.create(EventTarget);
Router.prototype.constructor = Router;
setup = '''
class prop:
def __init__(self, getter):
self.getter = getter
def __get__(self, instance, owner=None):
if instance is None:
return self
value = instance.__dict__[self.getter.__name__] = self.getter(instance)
import re
from gzip import GzipFile
from django.http import FileResponse
# TODO:
# - extra headers
# - expiration
@funkybob
funkybob / gist:6332718
Created August 25, 2013 08:36
My Vigenere ciper for CSRF
# If this were split out of the get_random_string def we
# we wouldn't need to repeat it here...
VALID_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
def mangle(token):
mask = get_random_string(len(token))
value = ''.join([
VALID_CHARS[ (VALID_CHARS.index(x) + VALID_CHARS.index(y)) % len(VALID_CHARS) ]
for x, y in zip(token, mask)
from django.contrib import admin
from django import forms
from .models import *
class ThroughInline(admin.TabularInline):
model = Through
raw_id_fields = ('unter',)
sortable_field_name = 'order'
formfield_overrides = {