I hereby claim:
- I am benjaoming on github.
- I am benjaoming (https://keybase.io/benjaoming) on keybase.
- I have a public key ASCa077dJpvd_GlrDxPvWAQUkdoRhqhU_mHh9eg1zSQxWgo
To claim this, I am signing this object:
import logging | |
from django.core.cache import cache | |
from django.utils import timezone | |
from datetime import timedelta | |
logger = logging.getLogger('name-your-logger') | |
class BruteForceMixin(): | |
""" | |
Use this in a FormView and call count_failure() in form_invalid |
""" | |
This code is public domain. | |
The original author is Bear Huang (http://bear330.wordpress.com/). | |
Uploaded to GIST and adapted for autopep8 by github/benjaoming | |
""" | |
# Guide for installing a code formatter (like this one) in PyDev: | |
# http://bear330.wordpress.com/2007/10/30/using-pythontidy-in-pydev-as-code-formatter/ | |
# Ensure that your autopep8.py is executable (chmod +x). |
""" | |
This command exports blog posts, categories and tags from django-blog-zinnia | |
to wagtail_blog. | |
Usage: | |
0. Carefully consider if you want custom models for wagtail_blog before | |
starting the import. You may for instance want to retain an FK relation in | |
the database between old Zinnia Entry objects and new BlogPage objects. | |
1. Copy this script to yourapp/management/commands/zinnia_to_wagtail.py |
#!/bin/bash | |
# Based on http://gagor.pl/2014/01/regenerate-thumbnails-in-shotwell-for-last-month/ | |
THUMB_ROOT=~/.cache/shotwell/thumbs | |
# Remove " > date('now','start of month','-1 month')" if you want to re-generate everything | |
sqlite3 ~/.local/share/shotwell/data/photo.db \ | |
"select id||' '||filename from PhotoTable where date(timestamp,'unixepoch','localtime') > date('now','start of month','-1 month') order by timestamp desc" | | |
while read id filename; do |
#!/usr/bin/env python | |
try: | |
import kolibri | |
except ImportError: | |
print( | |
"Could not find Kolibri in the system path, if you are using a PEX " | |
"file, please run `./file.pex manage shell` and then copy-paste all " | |
"contents of this script into the command line of Kolibri." | |
) |
#!/usr/bin/env bash | |
# get the upstream repository username | |
upstream_repo=$(git config remote.upstream.url | sed 's/^.*://' | sed 's/\/.*$//') | |
# open the PR against develop, or another branch specified as the first command-line argument | |
upstream_branch=${1:-develop} | |
# branch | |
branch=$(git symbolic-ref HEAD | sed 's/refs\/heads\///') |
I hereby claim:
To claim this, I am signing this object:
class ExceptionUserInfoMiddleware(object): | |
""" | |
Adds user details to request context on receiving an exception, so that they show up in the error emails. | |
Add to settings.MIDDLEWARE_CLASSES and keep it outermost(i.e. on top if possible). This allows | |
it to catch exceptions in other middlewares as well. | |
Origin: https://gist.github.com/646372 | |
""" | |
""" | |
Automatically suspend computer when the user has fallen asleep. But using your | |
own custom timing. | |
Add to your crontab with `crontab -e` | |
# m h dom mon dow command | |
0 2 * * * python3 /path/to/awake_or_suspend.py | |
This command either needs that your user can invoke `sudo` without a password or that it's launched with sude permissions. |
# -*- coding: utf-8 -*- | |
"""Refactor South migrations to use settings.AUTH_USER_MODEL. | |
Inserts a backwards-compatible code-snippet in all | |
your schema migration files and uses a possibly customized user | |
model as introduced in Django 1.5. | |
Please note that this has nothing to do with changing | |
settings.AUTH_USER_MODEL to a new model. If you do this, stuff | |
will very likely break in reusable apps that have their own | |
migration trees. |