This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 && \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from gzip import GzipFile | |
from django.http import FileResponse | |
# TODO: | |
# - extra headers | |
# - expiration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |