Skip to content

Instantly share code, notes, and snippets.

View philippeowagner's full-sized avatar

Philippe O. Wagner philippeowagner

View GitHub Profile
#!/bin/sh
# USAGE
# cd to WORKSPACE and
# write output to ~/.atom/projects.cson
# ./make_atom_projects.sh > ~/.atom/projects.cson
WORKSPACE="/Users/phi/workspace"
for f in $WORKSPACE/*; do
if [[ -d $f ]]; then
g=`basename $f`
echo "\"$f\":"
Iñtérnätïonàlizatiøn
@philippeowagner
philippeowagner / git-gc-all.sh
Created August 10, 2015 11:13
Running ``git gc`` in each and every repository located in my workspace.
#!/bin/sh
WORKSPACE="/Users/phi/workspace"
for f in $WORKSPACE/*; do
if [[ -d $f ]]; then
echo "Processing " $f
cd $f
git gc
echo "================="
fi
done
@philippeowagner
philippeowagner / gist:5fc23a4cd28df78c0d9d
Last active February 20, 2017 15:44
Django > reload current object from DB
class Object(models.Model):
def reload(self):
"""
Reload object from the database
"""
return Object.objects.get(pk=self.pk)
@philippeowagner
philippeowagner / gist:8151b6bf74f30dfdc7a2
Created July 29, 2015 20:06
Creating a first organisation user and the organisation.
from compat import get_user_model
from organizations.utils import create_organization
User = get_user_model()
phi = User.objects.get(username="phi")
create_organization(phi, "arteria", "arteria")
<Organization: arteria>

This is all based on the [alpha release][1].

Properties

From the built-in help system:

For many settings TextMate will look for a .tm_properties file in the current folder and in any parent folders (up to the user’s home folder).

These are simple setting = value listings where the value is a format string in which other variables can be referenced.

# -*- coding: utf-8 -*-
from waffle import TEST_COOKIE_NAME, flag_is_active
from waffle.middleware import WaffleMiddleware
# FIXME: only works if TEST_COOKIE_NAME ends with the flag name
TEST_COOKIE_PREFIX = TEST_COOKIE_NAME.split('%s')[0]
class AlwaysWaffleMiddleware(WaffleMiddleware):
@philippeowagner
philippeowagner / gist:2f62929a9815c50a7080
Created January 19, 2015 15:37
Replace non-ASCII chars with ?
# based on http://stackoverflow.com/a/20078869/485361
import re
re.sub(r'[^\x00-\x7F]+','?', "Müller")
# 'M?ller'
import sys
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = ("Invalidates portions of the queryset cache based on the app names"
" or models provided as arguments to the command. If no arguments "
"are provided, nothing is done. To clear the entire queryset "
from django.db import models
import os
import uuid
class MyModel(models.Model):
def generate_new_filename(instance, filename):
f, ext = os.path.splitext(filename)