Skip to content

Instantly share code, notes, and snippets.

@acdha
acdha / django-1.2.5-lookup_allowed-example.py
Created December 23, 2010 20:29
How to whitelist other admin lookups with Django 1.2.5
class FooAdmin(ModelAdmin):
def lookup_allowed(self, key, value):
# NOTE: Django 1.2.5 changed the call signature to add the value
# Django 1.2.4 restricted the list of allowed lookups to only those
# specified in list_filter or date_hierarchy, which doesn't help when
# we need to filter on a list with thousands of options. We'll
# override that to allow the few which we actually use:
if key in ('related__pk', 'related__custom_field'):
return True
@coordt
coordt / check_for_updates.py
Created April 8, 2011 18:39
Check locally installed packages against one or more package indexes for updates and list them.
#!/usr/bin/env python
"""
Use pip to get a list of local packages to check against one or more package
indexes for updated versions.
"""
import pip
import sys, xmlrpclib
from cStringIO import StringIO
from distutils.version import StrictVersion, LooseVersion
#!/usr/bin/python
from sorl.thumbnail.conf import settings
from sorl.thumbnail.base import ThumbnailBackend
FORMAT_DICT = {
'png': 'PNG',
'jpeg': 'JPEG',
'jpg': 'JPEG',
@Acorn-zz
Acorn-zz / gist:1059155
Created July 1, 2011 18:45
Load jQuery and jQuery UI in bookmarklet
((window, document, requirements, callback) ->
getScript = (url, callback) ->
script = document.createElement('script')
script.src = url
head = document.documentElement.childNodes[0]
done = false
script.onload = script.onreadystatechange = ->
if not done and (not (readyState = @readyState) or readyState == 'loaded' or readyState == 'complete')
done = true
callback()
@mtigas
mtigas / gist:2220161
Created March 27, 2012 20:55
Serving retina <img> tags in Django at the Spokesman-Review
<!--
Where {% jsmin %}{% endjsmin %} is a django template tag that
uses a Python port of Crockford's JSMin:
* http://www.crockford.com/javascript/jsmin.html
* https://gist.github.com/1b085c39b85347255557
Where {% mogrify %} is a custom template tag that generates a
URL with a resize command in the filename (semi-compatible with
ImageMagick mogrify) that is caught by a 404-handling script
running on the media server. A special hashed key is generated
@bzgeb
bzgeb / TriggerContainerEditor.cs
Created September 28, 2012 14:52
Example Drag & Drop area in a custom inspector for the Unity editor
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor (typeof(TriggerContainer))]
public class TriggerContainerEditor : Editor
{
private SerializedObject obj;
@radiatoryang
radiatoryang / TriplanarWorld.shader
Created February 6, 2013 19:24
a triplanar / procedural UV / world space UV shader for Unity, cobbled together bits from @quickfingerz and @Farfarer
Shader "Tri-Planar World" {
Properties {
_Side("Side", 2D) = "white" {}
_Top("Top", 2D) = "white" {}
_Bottom("Bottom", 2D) = "white" {}
_SideScale("Side Scale", Float) = 2
_TopScale("Top Scale", Float) = 2
_BottomScale ("Bottom Scale", Float) = 2
}
# Requires https://github.com/andybak/codebase-python-api-client.git
import csv
from codebase.client import CodeBaseAPI
codebase = CodeBaseAPI(username='account name/user name', apikey='your key here', project='project name')
tickets = [codebase.ticket(ticket_id=x) for x in range(1,151)]
f = open('tickets.csv', 'wb')
tickets = [x['ticket'] for x in tickets if x.get('ticket')]
@aras-p
aras-p / gist:ac4339c040afabea6ee7
Created August 18, 2014 09:13
fog macros WIP
// ------------------------------------------------------------------
// Fog helpers
//
// multi_compile_fog Will compile fog variants.
// UNITY_FOG_COORDS(texcoordindex) Declares the fog data interpolator.
// UNITY_TRANSFER_FOG(outputStruct,clipspacePos) Outputs fog data from the vertex shader.
// UNITY_APPLY_FOG(fogData,col) Applies fog to color "col". Automatically applies black fog when in forward-additive pass.
// Can also use UNITY_APPLY_FOG_COLOR to supply your own fog color.
// In case someone by accident tries to compile fog code in one of the g-buffer or shadow passes:
@nealtodd
nealtodd / settings_test_snippet.py
Last active November 14, 2019 01:25
Skip migrations for a Django 1.7 test run
# If your test settings file doesn't import any other settings file
# then you can use the function directly:
def prevent_tests_migrate(db):
import django
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
django.setup()
ma = MigrationExecutor(connections[db]).loader.migrated_apps
return dict(zip(ma, ['{a}.notmigrations'.format(a=a) for a in ma]))