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
export function throttleDebouncePromise( | |
inner, | |
{ throttle, debounce, cache, immediateIfCached }, | |
) { | |
// Ordinary debounce functions cause issues with promises and react-select but this works well. | |
// Based on: https://stackoverflow.com/questions/35228052/debounce-function-implemented-with-promises | |
const resolveCallbacks = [] | |
const store = {} | |
let timeout = null | |
let time = new Date() |
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.staticfiles.storage import ManifestStaticFilesStorage | |
class ManifestStaticFilesStorageWithSourceMaps(ManifestStaticFilesStorage): | |
""" | |
Adds js and css source map support for ManifestStaticFilesStorage. | |
""" | |
patterns = ( | |
("*.css", ( |
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 generator_from_queryset(queryset, chunksize=2000, enumerate=False): | |
assert queryset.query.order_by is not None | |
offset = 0 | |
i = 0 | |
finished = False | |
while not finished: | |
finished = True | |
for row in queryset[offset:offset + chunksize]: | |
finished = False | |
if enumerate: |
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.db.models import ExpressionWrapper, FloatField, Func | |
class Cast(Func): | |
function = 'CAST' | |
template = '%(function)s(%(expressions)s AS %(db_type)s)' | |
def __init__(self, expression, db_type): | |
# convert second positional argument to kwarg to be used in function template | |
super(Cast, self).__init__(expression, db_type=db_type) | |
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
// ==UserScript== | |
// @name Hide status bar on Slack | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://*.slack.com/* | |
// @grant none | |
// ==/UserScript== |
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.db import connections | |
from django.db.models.query import QuerySet | |
def explain(self): | |
cursor = connections[self.db].cursor() | |
cursor.execute('set enable_seqscan = off') | |
query, params = self.query.sql_with_params() | |
print(query % params) | |
cursor.execute('EXPLAIN ANALYZE %s' % query, params) |
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
#!/bin/bash | |
# http://serverfault.com/questions/24428/monitoring-dmesg-output | |
MAILTO=root | |
LOG=/var/log/kern.log | |
OFFSET_FILE=$0.offset | |
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 functools import wraps | |
def update_page_and_or_revsion(func): | |
@wraps(func) | |
def func_wrapper(page): | |
if page.live: | |
if page.has_unpublished_changes: | |
# update live page without creating new revsions | |
func(page) | |
page.save() |
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
find templates/ -name *.html -exec sh -c "cat {}|grep '<script' | grep -v '{% static' | grep -v 'src=\"//' | grep -v '<script>' | grep -v 'src=\"http'" \; -print | |
find templates/ -name *.html -exec sh -c "cat {}|grep 'stylesheet' | grep -v '{% static' | grep -v 'href=\"//' | grep -v 'href=\"http' | grep -v -P 'href=\047//' | grep -v -P 'href=\047http'" \; -print |
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 sys | |
import json | |
import urllib2 | |
from distutils.version import StrictVersion | |
def versions(package_name): | |
url = "https://pypi.python.org/pypi/%s/json" % (package_name,) | |
data = json.load(urllib2.urlopen(urllib2.Request(url))) | |
versions = data["releases"].keys() | |
try: |
NewerOlder