Skip to content

Instantly share code, notes, and snippets.

Walter walterrenner

Block or report user

Report or block walterrenner

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
walterrenner /
Created Oct 11, 2017
Dealing with unicode and strings in Python
# Deal exclusively with unicode objects as much as possible
# by decoding things to unicode objects when you first get them and
# encoding them as necessary on the way out.
>>> s = 'abc'
>>> type(s)
<type 'str'>
>>> u = u'abc' # note the u prefix
walterrenner /
Created Sep 13, 2017
Split large Excel files into chunks of n
import argparse
import xlrd
import xlwt
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
walterrenner / german-iso-3166.csv
Last active Apr 10, 2019 — forked from malteos/german-iso-3166.csv
German ISO-3166 Country Codes CSV (deutsche Ländercodes)
View german-iso-3166.csv
AF Afghanistan
EG Ägypten
AL Albanien
DZ Algerien
AD Andorra
AO Angola
AI Anguilla
AQ Antarktis
AG Antigua und Barbuda
GQ Äquatorial Guinea
walterrenner /
Created Jan 4, 2016
some useful bash commands

count history commands

history | cut -c8- | sort | uniq -c | sort -rn | head
walterrenner / gist:f8e8d6b06a1f0c79bea6
Created Dec 17, 2015 — forked from abrookins/gist:1933635
A Sublime Text 2 Django project file with a test runner build system
View gist:f8e8d6b06a1f0c79bea6
"path": "django_project_dir"
"path": "lib/python2.7"
walterrenner /
Created Oct 14, 2015
Use project related mirgation modules

Keep your custom Migrations in your project

A proof of concept.

If you cant't/won't use the apps Migration files this workaround can be helpful for you.

We assume you have a clean Database without any Migrations applied and a Project named my_project that you are working on. Add the below snippet in your right after INSTALLED_APPS.

This tells django to use migration files from the module in my_project.migrations.<appname>.migrations.

walterrenner /
Created Aug 26, 2015
Minimal django TestCase
from django.test import TestCase
from .models import Thing
# Create your tests here.
class TestModels(TestCase):
def test_saving_a_model(self):
thing = Thing.objects.create()
walterrenner /
Created Aug 21, 2015
print django project information
from compat import import_string
from django.conf import settings
for app_name in settings.INSTALLED_APPS:
app = __import__(app_name)
print "Information for " + app_name
print "verion: " + app.__version__
except Exception as e:
print "version: " + str(e)
walterrenner /
Created Jan 29, 2015
get_admin_url() for any model instance
from django.core import urlresolvers
from django.contrib.contenttypes.models import ContentType
from django.db import models
class MyModel(models.Model):
def get_admin_url(self):
content_type = ContentType.objects.get_for_model(self.__class__)
return urlresolvers.reverse("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(,))
View .pythonrc
import atexit
import os
import sys
import readline
except ImportError:
print "Module readline not available."
import rlcompleter
You can’t perform that action at this time.