Skip to content

Instantly share code, notes, and snippets.

Greg Brown gregplaysguitar

Block or report user

Report or block gregplaysguitar

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
@gregplaysguitar
gregplaysguitar / fabfile.py
Last active Jun 23, 2017
MySQL to PostgreSQL migrate script for Django. Turns a mysql export into a matching postgres database.
View fabfile.py
"""
Usage
=====
1. Install Fabric - http://www.fabfile.org/
2. Obtain db_converter.py from
https://github.com/lanyrd/mysql-postgresql-converter - put it in the same
directory as this fabfile.
@gregplaysguitar
gregplaysguitar / app.py
Last active Mar 24, 2017 — forked from maccman/app.py
Stripe Flask Example
View app.py
import os
from flask import Flask, render_template, request
import stripe
stripe_keys = {
'secret_key': os.environ['SECRET_KEY'],
'publishable_key': os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']
@gregplaysguitar
gregplaysguitar / admin_raw_id.py
Last active Nov 28, 2018
Show object description and a link next to django's raw_id_fields, for ForeignKey and ManyToMany fields
View admin_raw_id.py
"""
Show customisable str representation of the linked objects next to each raw id
field in a django admin change form. Works for ForeignKey, OneToOneField, and
ManyToManyField fields.
Example:
from django.contrib import admin
from admin_raw_id import ImprovedRawIdFieldsAdmin
from .models import MyModel
@gregplaysguitar
gregplaysguitar / postgres_ft.py
Last active Jan 29, 2018
Postgres full-text search utils for django
View postgres_ft.py
# -*- coding: utf-8 -*-
"""
To enable (and test) the unaccent function, as a superuser:
\connect DATABASE
CREATE EXTENSION unaccent;
SELECT unaccent('èéêë');
Example
@gregplaysguitar
gregplaysguitar / simple_search.py
Last active Apr 19, 2017
Django simple search
View simple_search.py
# Deprecated - see https://github.com/gregplaysguitar/django-simple-search/
@gregplaysguitar
gregplaysguitar / LICENSE.txt
Last active Apr 29, 2019
Auto-generate srcset and sizes attributes for an <img> with Django & sorl-thumbnail
View LICENSE.txt
Copyright (c) 2015 Greg Brown
[gregbrown.co.nz](http://gregbrown.co.nz)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@gregplaysguitar
gregplaysguitar / jinja_cms.py
Last active Aug 29, 2015
Djangocms2000 template tag file for Coffin & Jinja2 compatibility
View jinja_cms.py
# -*- coding: utf-8 -*-
from django.conf import settings
from coffin import template
from jinja2 import contextfunction, Markup
from cms.application import get_rendered_block, get_rendered_image
from cms.templatetags.cms_editor import cms_editor
from cms.utils import is_editing
View xapian-virtualenv.sh
pkgver=1.2.19
mkdir -p $VIRTUAL_ENV/src && cd $VIRTUAL_ENV/src
curl -O http://oligarchy.co.uk/xapian/$pkgver/xapian-core-$pkgver.tar.xz && tar xf xapian-core-$pkgver.tar.xz
curl -O http://oligarchy.co.uk/xapian/$pkgver/xapian-bindings-$pkgver.tar.xz && tar xf xapian-bindings-$pkgver.tar.xz
cd $VIRTUAL_ENV/src/xapian-core-$pkgver
./configure --prefix=$VIRTUAL_ENV && make && make install
export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib
@gregplaysguitar
gregplaysguitar / placeholder.scss
Created Aug 29, 2012 — forked from antsa/placeholder.scss
Placeholder mixin for Sass
View placeholder.scss
// Placeholder @mixin for Sass
//
// A mixin to style placeholders in HTML5 form elements.
// Includes also a .placeholder class to be used with a polyfill e.g.
// https://github.com/mathiasbynens/jquery-placeholder
// Requires Sass 3.2.
//
// Example usage (.scss):
//
// input {
@gregplaysguitar
gregplaysguitar / fields.py
Created Jun 27, 2012
Memory-safe ImageField for Django - checks filesize and dimensions before loading the uploaded file into memory.
View fields.py
try:
from PIL import Image
except ImportError:
import Image
from django import forms
from django.template.defaultfilters import filesizeformat
from django.core.exceptions import ValidationError
You can’t perform that action at this time.