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 jacobpledger on github. | |
* I am jacobpledger (https://keybase.io/jacobpledger) on keybase. | |
* I have a public key ASBiGUU0AiWBbCUDo5f1vQ6HIJXzanwL9ECfTKCp_Ctw7Qo | |
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
from typing import Any | |
def bfs(haystack: dict, needle: Any) -> Any: | |
""" | |
Breadth-first search in a dict for the specified key, for which the | |
value is returned. | |
:param haystack: The dictionary we want to search. | |
:param needle: the key, whose value we are searching for | |
:return: the value at the given key or None if not found. |
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 typing import Any | |
def dfs(haystack: dict, needle: Any) -> Any: | |
""" | |
Depth-first search in a dict for the specified key, for which the | |
value is returned. | |
:param haystack: The dictionary we want to search. | |
:param needle: the key, whose value we are searching for | |
:return: the value at the given key or None if not found. |
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/env python3 | |
import argparse | |
import os | |
import platform | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument( |
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
# copy this into your project and add the class to | |
# your MIDDLEWARE_CLASSES in your settings | |
from django.views.debug import technical_500_response | |
import sys | |
class UserBasedExceptionMiddleware(object): | |
def process_exception(self, request, exception): | |
if request.user.is_superuser: | |
return technical_500_response(request, *sys.exc_info()) |
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
# Copied from https://djangosnippets.org/snippets/10588/ | |
import fnmatch | |
import pyclbr | |
import os | |
import re | |
import logging | |
from django.conf import settings | |
from django.core.management.base import NoArgsCommand |
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
# https://djangosnippets.org/snippets/10591/ | |
from django.core.cache import cache | |
from django.utils.functional import cached_property | |
from django.core.paginator import Paginator, Page, PageNotAnInteger | |
class CachedPaginator(Paginator): | |
"""A paginator that caches the results on a page by page basis.""" | |
def __init__(self, object_list, per_page, orphans=0, allow_empty_first_page=True, cache_key=None, cache_timeout=300): |
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 | |
log=$HOME/Documents/log.txt | |
lm=$(date -r $log +%d) | |
now=$(date +%d) | |
if [ $now -gt $lm ]; then | |
echo '' >> $log | |
echo $(date -I) $(date +%A) >> $log | |
echo '' >> $log |
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 mimetypes | |
from os.path import splitext | |
from django.core.exceptions import ValidationError | |
from django.utils.translation import ugettext_lazy as _ | |
from django.template.defaultfilters import filesizeformat | |
class FileValidator(object): | |
""" |