Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
SmileyChris / conf.py
Created May 4, 2011 22:30
Django application specific settings configuration
from django.conf import settings as django_settings
class Settings(object):
DEFAULTS = {
# Define any default settings in here.
}
def __dir__(self):
return dir(django_settings)
@SmileyChris
SmileyChris / install.rst
Last active November 19, 2019 18:56
Better wrapping of docstring text with Sublime Text 2. Run: patch ~/.config/sublime-text-2/Packages/Default/paragraph.py < paragraph.diff

To install in Sublime Text 3, you'll need to extract the py file from the default package before patching it.

Here are short instructions to do it in Linux. First change to the directory that you have sublime text, unzip the file, and patch it:

cd /opt/sublime_text
unzip Packages/Default.sublime-package paragraph.py -d ~/.config/sublime-text-3/Packages/default
curl https://gist.githubusercontent.com/SmileyChris/4340807/raw/paragraph.diff | patch ~/.config/sublime-text-3/Packages/default/paragraph.py

Or if you've downloaded the diff, you can just patch it from that rather than `curl`ing:

import random
from typing import Optional, Any, List, Tuple
consonant_initial_digraphs = set(
["ch", "sh", "th", "thr", "ph", "wh", "ck", "kn", "wr"]
)
consonant_final_digraphs = set(["ch", "ng", "sh", "th", "tch"])
vowel_digraphs = [
"ai",
@SmileyChris
SmileyChris / urls.py
Last active June 18, 2018 22:23 — forked from rixx/urls.py
Delivering static files on fixed URL in Django
import os
import mimetypes
from django.contrib.staticfiles.storage import staticfiles_storage
from django.http import Http404, FileResponse
def static_file(request, path, content_type=None):
if not staticfiles_storage.exists(path):
raise Http404()
@SmileyChris
SmileyChris / ok.py
Last active May 29, 2018 00:35 — forked from converge/ok.py
class AccountsStatisticsDetail(TemplateView):
template_name = 'grow/accountsstatistics.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
username = self.kwargs.get('username')
if username:
context['username'] = username
context['account_stats'] = (
AccountsStatistics.objects
@SmileyChris
SmileyChris / filter.py
Created January 6, 2016 02:44
Hexchat plugin to filter joins/parts except for recent talkers. Put it in ~/.config/hexchat/addons
__module_name__ = 'Filter'
__module_version__ = '1.0.custom'
__module_description__ = 'Filters join/part/voice messages'
import hexchat
import collections
from time import time
last_seen = {} # For each entry: the key is the user's nickname, the entry
# is a list: element 0: last seen time
def user_in_group(user, group_id=None, group_id_list=None):
if group_id_list is None:
group_id_list = set(group_id]
if not hasattr(user, 'group_ids'):
user.group_ids = set(user.groups.values_list('pk', flat=True))
return user.group_ids.intersection(group_id_list)
@SmileyChris
SmileyChris / mail.py
Last active March 5, 2016 08:49
Handle template-base email messages in Django
from email.Utils import formataddr
import os
from django.conf import settings
from django.core import mail
from django import template
from django.template.loader import select_template, get_template
def template_email(template_name, extra_context=None, *args, **kwargs):
@SmileyChris
SmileyChris / base_dirs.py
Created February 4, 2013 21:40
This goes in a `settings` package, imported from settings modules with `from .base_dirs import PROJECT_DIR, VAR_ROOT`
"""
Calculates some project directory settings by assuming they are relative this
module's location.
``PROJECT_DIR``
The project module's path.
``VAR_ROOT``
A location to put run-time generated files (such as uploaded files, or the
collation of static files).
################entering some data the first time to my form doesnt work, it gives this error:
IntegrityError at /job/add/article/
(1048, "Column 'author_id' cannot be null")
Request Method: POST
Request URL: http://localhost:8000/job/add/article/
Django Version: 1.4.3