Skip to content

Instantly share code, notes, and snippets.

🍀
Simplifying things for fun and profit.

Vincent Driessen nvie

Block or report user

Report or block nvie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .gitmodules
[submodule "vim/bundle/vim-characterize"]
path = vim/pack/nvie/start/vim-characterize
url = https://github.com/tpope/vim-characterize.git
View b.py
# Define types of building blocks
SUBDOMAIN = STRING.set('validate', validate_subdomain)
...
@schema({
'data': NESTED({
'type': WEBSPACE_TYPE,
'attributes': NESTED({
'subdomain': SUBDOMAIN,
View huh.md

Here's my config:

$ cat Procfile.test
foo: python -u foo.py

$ cat foo.py
import logging
logging.basicConfig()
logging.warn('A log line\nWith a line break')
logging.warn('Second log')
View lookup_table.py
def lookup_table(values, key=None, keyval=None, unique=False, use_lists=False):
"""
Builds a dict-based lookup table (index) elegantly.
Supports building normal and unique lookup tables. For example:
>>> lookup_table(['foo', 'bar', 'baz', 'qux', 'quux'],
... lambda s: s[0])
{
'b': {'bar', 'baz'},
'f': {'foo'},
'q': {'quux', 'qux'}
@nvie
nvie / magic.awk
Last active Aug 29, 2015
Different highlights of this piece of code that is valid C, C++, awk, perl, Python, sh, bash and tcl: https://github.com/stedolan/hax/blob/master/twisty_code/megascript.c
View magic.awk
#ifdef _not_defined
#\
"exit`[ -z $BASH ] && t=sh; [ -z $BASH ] || t=$(basename $BASH); echo Hello, World from $t > /dev/tty;`";
"[puts {Hello, World from Tcl}; {exit}]";
from operator import concat;
exec concat(concat(concat(chr(109),chr(61)),chr(39)),chr(39));
m,""" ";/,;s/;//;
#else
#include <stdio.h>
#define BEGIN int main(int nargs,char** args)
View keybase.md

Keybase proof

I hereby claim:

  • I am nvie on github.
  • I am nvie (https://keybase.io/nvie) on keybase.
  • I have a public key whose fingerprint is 9B5C 55F6 2651 625C C4EE 7C8F 4DAB 9440 5EA5 AAF0

To claim this, I am signing this object:

@nvie
nvie / ormtools.py
Created Nov 29, 2013
Really useful helper that I use constantly to force myself to write more efficient Django queries.
View ormtools.py
from contextlib import contextmanager
from django.conf import settings
from django.db import connection
@contextmanager
def no_queries_allowed():
"""This is a helper method that makes it easier during development, by
throwing an exception when any queries are made within its block. Using
@nvie
nvie / sift.py
Last active Dec 18, 2015
The sift itertool.
View sift.py
from collections import deque
from functools import wraps
def inversify(predicate):
"""Returns a predicate that is the inverses of the given predicate."""
@wraps(predicate)
def _inner(*args, **kwargs):
return not predicate(*args, **kwargs)
return _inner
@nvie
nvie / where_to_put_this_best.py
Created Mar 7, 2013
What's the best place to put this code? This is basically setup code that you want to execute on Django's boot time. I'm currently putting it in an arbitrary app's __init__.py, but that feels a bit lame. Ideas? Settings seems like a bad idea, too.
View where_to_put_this_best.py
import jingo
from django_assets.env import get_env
jingo.env.assets_environment = get_env()
@nvie
nvie / log.txt
Created Mar 4, 2013
The following code crashes when ran on Django==1.5, but it works fine on Django==1.4.3. (Both py27.)
View log.txt
$ python minimal_example.py
Traceback (most recent call last):
File "minimal_example.py", line 7, in <module>
s.sign('foo')
File "/Users/nvie/.virtualenvs/foo/lib/python2.7/site-packages/django/core/signing.py", line 175, in sign
return str('%s%s%s') % (value, self.sep, self.signature(value))
File "/Users/nvie/.virtualenvs/foo/lib/python2.7/site-packages/django/core/signing.py", line 169, in signature
signature = base64_hmac(self.salt + 'signer', value, self.key)
File "/Users/nvie/.virtualenvs/foo/lib/python2.7/site-packages/django/core/signing.py", line 75, in base64_hmac
return b64_encode(salted_hmac(salt, value, key).digest())
You can’t perform that action at this time.