Skip to content

Instantly share code, notes, and snippets.

View sjkingo's full-sized avatar

Sam Kingston sjkingo

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sjkingo on github.
  • I am sjkingo (https://keybase.io/sjkingo) on keybase.
  • I have a public key ASC2GrxtlLaSX3EU3RMgZCWRREzbpr15bs4pr3x5bxRbfgo

To claim this, I am signing this object:

@sjkingo
sjkingo / logging_utils.py
Created February 18, 2017 04:19
Suppress Django deprecated warnings
import logging
class SuppressDeprecated(logging.Filter):
def filter(self, record):
WARNINGS_TO_SUPPRESS = [
'RemovedInDjango110Warning'
]
# Return false to suppress message.
return not any([warn in record.getMessage() for warn in WARNINGS_TO_SUPPRESS])
@sjkingo
sjkingo / README.md
Last active January 8, 2017 21:05
Installing and running kitty

Installing and running kitty https://github.com/kovidgoyal/kitty on Fedora 25

libglew-2.0 is required and Fedora only ships with version 1.13. Build and override the system-wide libglew:

# build glew at /path/to/glew-2.0.0
$ export PKG_CONFIG_PATH=/path/to/glew-2.0.0/dest/lib/pkgconfig
$ cd /path/to/kitty
$ python3 setup.py build
$ LD_PRELOAD=/path/to/glew-2.0.0/dest/lib64/libGLEW.so python3 .
@sjkingo
sjkingo / models.py
Created June 30, 2016 02:56
Redirecting to a PDF when "View on site" is clicked in Django admin
from django.db import models
class SomeModel(models.Model):
# fields here
class Meta:
pass
def get_absolute_url(self):
return reverse('pdf_view', id=self.id)
@sjkingo
sjkingo / base.html
Last active June 25, 2016 05:17
fantail example
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ title }}</title>
<meta name="generator" content="fantail-{{ version }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
@sjkingo
sjkingo / README.md
Last active October 5, 2019 02:53
Fix for re-adding the django_content_type.name column in Django 1.7

Django 1.8 drops the name field from ContentType in favour of a property on the model itself (see https://docs.djangoproject.com/en/1.8/ref/contrib/contenttypes/#the-contenttype-model).

If you update to 1.8 and then back to 1.7 (for whatever crazy reason..) you will come across exceptions as the name property doesn't exist (and neither does the database field).

These scripts restore that functionality to Django 1.7 (by recreating the field and populating it correctly).

It does not cause any data loss, but as always: Use at your own risk.

@sjkingo
sjkingo / add_product_image.py
Created June 4, 2015 22:56
Add a product image programatically in Cartridge
filename = 'image.jpg'
source_fp = open(filename, 'rb')
p = Product.objects.get(...)
# Create the ProductImage if it doesn't exist already and assign to Product
images = ProductImage.objects.filter(description=filename)
if len(images) == 0:
the_file = File(source_fp)
the_image = p.images.create(
product=p,