Skip to content

Instantly share code, notes, and snippets.

View zbyte64's full-sized avatar

Jason Kraus zbyte64

View GitHub Profile
@lovevn
lovevn / django.vcl
Last active July 25, 2017 22:59 — forked from 10p-freddo/django.vcl
sub vcl_recv {
# unless sessionid/csrftoken is in the request, don't pass ANY cookies (referral_source, utm, etc)
if (req.request == "GET" && (req.url ~ "^/static" || (req.http.cookie !~ "sessionid" && req.http.cookie !~ "csrftoken"))) {
remove req.http.Cookie;
}
# normalize accept-encoding to account for different browsers
# see: https://www.varnish-cache.org/trac/wiki/VCLExampleNormalizeAcceptEncoding
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
@Nagyman
Nagyman / workflows-in-django.md
Last active November 20, 2024 01:08
Workflows in Django

Workflows (States) in Django

I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)
# the following is a basically functional but probably broken for some cases (just tested for basic login ATM) implementation of a flask-security UserDataStore for RethinkDB.
#
# This is released as open source under the MIT license and comes with no warranty, yada yada. TODO: actual license header
from flask_security import UserMixin, RoleMixin
from flask_security.datastore import UserDatastore
import rethinkdb as r
class Bunch(object):
def __init__(self, obj, **kws):
self.__dict__.update(obj)
@kevinswiber
kevinswiber / hal.json
Created July 7, 2012 14:56
JSON Siren vs. HAL Representations
{
"_links": {
"self": { "href": "/orders" },
"next": { "href": "/orders?page=2" },
"find": { "href": "/orders{?id}", "templated": true }
},
"_embedded": {
"orders": [{
"_links": {
"self": { "href": "/orders/123" },
@issackelly
issackelly / signing.coffee
Created September 17, 2011 14:31
Experimental implementation of Django Signing in JavaScript
base64 = require 'base64'
crypto = require 'crypto'
gzip = require 'gzip'
class BadSignature extends Error
constructor: (msg="Signature does not match") ->
super msg
class SignatureExpired extends BadSignature
constructor: (msg="Signature timestamp is older than required max_age") ->