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
walterrenner / unicode.py
Created Oct 11, 2017
Dealing with unicode and strings in Python
View unicode.py
# 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.
# https://stackoverflow.com/a/6048203
>>> s = 'abc'
>>> type(s)
<type 'str'>
>>> u = u'abc' # note the u prefix
@walterrenner
walterrenner / split_excel.py
Created Sep 13, 2017
Split large Excel files into chunks of n
View split_excel.py
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
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
walterrenner / hack.md
Created Jan 4, 2016
some useful bash commands
View hack.md

count history commands

history | cut -c8- | sort | uniq -c | sort -rn | head
@walterrenner
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
{
"folders":
[
{
"path": "django_project_dir"
},
{
"path": "lib/python2.7"
}
],
@walterrenner
walterrenner / readme.md
Created Oct 14, 2015
Use project related mirgation modules
View readme.md

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 settings.py right after INSTALLED_APPS.

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

@walterrenner
walterrenner / tests.py
Created Aug 26, 2015
Minimal django TestCase
View tests.py
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()
thing.save()
@walterrenner
walterrenner / command.py
Created Aug 21, 2015
print django project information
View command.py
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
try:
print "verion: " + app.__version__
except Exception as e:
print "version: " + str(e)
@walterrenner
walterrenner / models.py
Created Jan 29, 2015
get_admin_url() for any model instance
View models.py
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=(self.id,))
View .pythonrc
import atexit
import os
import sys
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind('tab:complete')
You can’t perform that action at this time.