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
### Keybase proof | |
I hereby claim: | |
* I am jneight on github. | |
* I am petrillo (https://keybase.io/petrillo) on keybase. | |
* I have a public key ASCCdy_7casBx81D9nFTjg5T88GU6JwGSQAQLLEarSEWkAo | |
To claim this, I am signing this object: |
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
#!/usr/bin/python3 | |
import re | |
import os | |
import subprocess | |
import logging | |
from systemd.journal import JournalHandler | |
logger = logging.getLogger('check_vpn') |
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 | |
import os | |
import subprocess | |
def get_vpn_names(path): | |
with open(path, 'r') as f: | |
return re.findall(r'conn ([\w]+)', read) | |
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
SELECT | |
nspname AS schemaname,relname,reltuples | |
FROM pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
WHERE | |
nspname NOT IN ('pg_catalog', 'information_schema') AND | |
relkind='r' | |
ORDER BY reltuples DESC; |
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.core.urlresolvers import ( | |
reverse, get_script_prefix, resolve, Resolver404) | |
prefix = get_script_prefix() | |
chomped_uri = uri | |
if prefix and chomped_uri.startswith(prefix): | |
chomped_uri = chomped_uri[len(prefix) - 1:] | |
# resolve will split cleaned uri and get PK | |
view, args, extra_venue = resolve(chomped_uri) |
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 http://stackoverflow.com/questions/569754/how-to-tell-for-which-object-attribute-pickle-fails | |
""" | |
Show which fields cannot be pickled | |
""" | |
import pickle | |
def get_pickling_errors(obj,seen=None): | |
if seen is None: | |
seen = [] |
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
# coding=utf-8 | |
import datetime | |
import logging | |
logger = logging.getLogger('djangoapp') | |
from django.views.debug import CLEANSED_SUBSTITUTE | |
from django.conf import settings | |
from tastypie.utils.mime import determine_format |
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
""" | |
USE: | |
photo = models.ImageField( | |
_(u'Rating photo'), upload_to=path_and_rename('ratings/pictures'), | |
blank=True) | |
""" | |
import os | |
from uuid import uuid4 |
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
# coding=utf-8 | |
from tastypie.bundle import Bundle | |
from tastypie import fields | |
from tastypie.exceptions import ApiFieldError | |
class OptimizedToOneField(fields.ToOneField): | |
def dehydrate(self, bundle, **kwargs): | |
""" |
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
# XHR CrossDomain Middleware by robtotheb | |
# https://gist.github.com/1164697 | |
from django import http | |
XS_SHARING_ALLOWED_ORIGINS = '*' | |
XS_SHARING_ALLOWED_METHODS = 'POST, GET, OPTIONS, PUT, DELETE' | |
XS_SHARING_ALLOWED_HEADERS = 'Accept, Accept-Charset, Accept-Encoding, Accept-Language, Connection, ' \ | |
'Content-Type, Authorization, Cache-Control, Referer, User-Agent, Origin' | |
XS_SHARING_ALLOWED_CREDENTIALS = 'true' |