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
# 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) |
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
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") { |
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
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") -> |
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
# Based on https://github.com/pytorch/pytorch/pull/3740 | |
import torch | |
import math | |
class AdamW(torch.optim.Optimizer): | |
"""Implements AdamW algorithm. | |
It has been proposed in `Fixing Weight Decay Regularization in Adam`_. | |
Arguments: |
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 processBodyChunkwiseWithProgress(res, processChunk) { | |
const dummyEventTarget = document.createElement("div"); // why isn't EventTarget constructible? :( | |
const lengthComputable = res.headers.has("Content-Length"); | |
const total = res.headers.get("Content-Length") || 0; | |
let loaded = 0; | |
// Using http://underscorejs.org/#throttle | |
const fireProgressThrottled = _.throttle(fireProgress, 50, { trailing: false }); |
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
def tf_pca(x): | |
''' | |
Compute PCA on the bottom two dimensions of x, | |
eg assuming dims = [..., observations, features] | |
''' | |
# Center | |
x -= tf.reduce_mean(x, -2, keepdims=True) | |
# Currently, the GPU implementation of SVD is awful. | |
# It is slower than moving data back to CPU to SVD there |
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
# USAGE | |
# python image_diff.py --first images/original_01.png --second images/modified_01.png | |
# import the necessary packages | |
from skimage.measure import compare_ssim | |
import argparse | |
import imutils | |
import cv2 | |
# construct the argument parse and parse the arguments |
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.utils.functional import SimpleLazyObject | |
from django.contrib.auth.models import AnonymousUser | |
from rest_framework.request import Request | |
from rest_framework_jwt.authentication import JSONWebTokenAuthentication | |
def get_user_jwt(request): | |
""" | |
Replacement for django session auth get_user & auth.get_user for |
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
{ | |
"_links": { | |
"self": { "href": "/orders" }, | |
"next": { "href": "/orders?page=2" }, | |
"find": { "href": "/orders{?id}", "templated": true } | |
}, | |
"_embedded": { | |
"orders": [{ | |
"_links": { | |
"self": { "href": "/orders/123" }, |
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
# | |
# this script will convert the hdhomerun listings (channels) to | |
# m3u format for use with external media players. before running | |
# this script, be sure to modify the <<config>> variable settings | |
# below. | |
# | |
# Suggested Usage: This script should be run on a cron to keep | |
# the channel lineup to date. Below is an example of how to execute this script: | |
# python /path/to/script/hdhomerun-prime-listings-to-m3u.py > /path/to/playlist.m3u | |
# |
OlderNewer