Skip to content

Instantly share code, notes, and snippets.

View manfre's full-sized avatar

Michael Manfre manfre

View GitHub Profile
@manfre
manfre / Caddyfile
Last active October 2, 2022 10:38
Authentik forward auth to microbin
{$MICROBIN_EXTERNAL_DNS:paste.myapp.local} {
# always forward outpost path to actual outpost
reverse_proxy /outpost.goauthentik.io/* {$AUTHENTIK_CONTAINER_NAME:authentik-server-1}:{$AUTHENTIK_PORT:9000}
# forward authentication to outpost
forward_auth {$AUTHENTIK_CONTAINER_NAME:authentik-server-1}:{$AUTHENTIK_PORT:9000} {
uri /outpost.goauthentik.io/auth/caddy
# capitalization of the headers is important, otherwise they will be empty

Keybase proof

I hereby claim:

  • I am manfre on github.
  • I am manfre (https://keybase.io/manfre) on keybase.
  • I have a public key whose fingerprint is 50A3 DAC5 25A5 7C63 27EB 1E3E 74DE D158 BAD0 EDF8

To claim this, I am signing this object:

@manfre
manfre / manager.py
Created January 6, 2014 15:45
Django model manager that allows access and easy querying against read-only (computed) database fields.
class ComputedFieldsManager(models.Manager):
"""
Manager that can account for computed fields and fetch those fields, but
ensure they are not writeable.
Example usage:
objects = ComputedFieldsManager(computed_fields=['my_computed_field'])
objects = ComputedFieldsManager(computed_fields=[('my_computed_field', models.BooleanField())])
class ItemGroup(models.Model):
name = models.CharField(max_length=10)
group_type = models.CharField(max_length=10, default='test')
class Item(models.Model):
group = models.ForeignKey(ItemGroup,
related_name='items',
limit_choices_to={
'group_type__in': ('test'),
@manfre
manfre / subquerytests.py
Created September 25, 2013 21:12
Improved SubqueryTests to cover some potential problem areas for database backends that must do some trickery for slicing
class SubqueryTests(TestCase):
def setUp(self):
DumbCategory.objects.create(id=1)
DumbCategory.objects.create(id=2)
DumbCategory.objects.create(id=3)
DumbCategory.objects.create(id=4)
def test_ordered_subselect(self):
"Subselects honor any manual ordering"
try:
@manfre
manfre / gist:6691126
Created September 24, 2013 20:57
Django test suite run with sqlite on Python 2.7.5
======================================================================
FAIL: test_templates (template_tests.tests.TemplateTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\projects\django\django\tests\template_tests\tests.py", line 621, in test_templates
('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
AssertionError: Tests failed:
----------------------------------------------------------------------
Template test (Cached='False', TEMPLATE_STRING_IF_INVALID='', TEMPLATE_DEBUG=False): filter-timeuntil10 -- FAILED. Expected u'0\xa0minutes', got u'59\xa0minutes'
----------------------------------------------------------------------
class SQLCompiler(compiler.SQLCompiler):
def resolve_columns(self, row, fields=()):
# If the results are sliced, the resultset will have an initial
# "row number" column. Remove this column before the ORM sees it.
if getattr(self, '_using_row_number', False):
row = row[1:]
values = []
index_extra_select = len(self.query.extra_select.keys())
for value, field in map(None, row[index_extra_select:], fields):
@manfre
manfre / contentmiddleware.py
Created March 28, 2013 12:34
Django middleware to handle arbitrary Models that share common URL space. Found URLs matches will be cached and short circuited on subsequent requests.
import logging, os, os.path, re
from hashlib import md5
from django.http import Http404, HttpResponse, HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect, HttpResponseNotModified
from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.encoding import smart_str
from django.utils.http import http_date
from django.core.cache import cache
@manfre
manfre / gist:4502333
Last active December 10, 2015 22:28 — forked from Pharylon/gist:4502183
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)