Skip to content

Instantly share code, notes, and snippets.

View philippeowagner's full-sized avatar

Philippe O. Wagner philippeowagner

View GitHub Profile
import sys
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = ("Invalidates portions of the queryset cache based on the app names"
" or models provided as arguments to the command. If no arguments "
"are provided, nothing is done. To clear the entire queryset "
from django.db import models
import os
import uuid
class MyModel(models.Model):
def generate_new_filename(instance, filename):
f, ext = os.path.splitext(filename)
@philippeowagner
philippeowagner / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Standard 1.4 urls
{% url path.to.some_view v1 v2 %}
{% url path.to.some_view arg1=v1 arg2=v2 %}
{% url app_views.client client.id %}
{% url path.to.view arg arg2 as the_url %}
{% url path.to.view as the_url %}
# Namespaced 1.4 urls
{% url myapp:view-name %}
{% url myapp:path.to.some_view v1 v2 %}
if (document.body.requestFullscreen ||
document.body.mozRequestFullScreen ||
document.body.webkitRequestFullscreen
) {
$("<button>View this chart in Full Screen</button>")
.on('click', function (e) {
var root = $interactive.get(0);
if (root.requestFullscreen) { root.requestFullscreen(); }
else if (root.mozRequestFullScreen) { root.mozRequestFullScreen(); }
else if (root.webkitRequestFullscreen) { root.webkitRequestFullscreen(); }
@philippeowagner
philippeowagner / API.md
Last active August 29, 2015 14:09 — forked from iros/API.md

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

class PubSub(object):
"""
Very simple Pub/Sub pattern wrapper
using simplified Redis Pub/Sub functionality.
Usage (publisher)::
import redis
r = redis.Redis()
class FooAdmin(admin.ModelAdmin):
def get_urls(self):
urls = super(ContentProjectAdmin, self).get_urls()
extra_urls = patterns('',
url(r'^dashboard/$', self.admin_site.admin_view(self.dashboard), name="cms_dashboard"),
)
return extra_urls + urls
@property
def request(self):
"""
just for convenience
"""
return self
STATUS_CANCELLED = 'cancelled'
STATUS_NEW = 'new'
STATUS_PENDING = 'pending'
STATUS_PAYMENT_DUE = 'payment-due'
STATUS_PAYMENT_PENDING = 'payment-pending'
STATUS_PAID = 'paid'
NEGOTIABLE_STATUS_CHOICES = (
(STATUS_CANCELLED, 'Cancelled'), # Cancelled, duh
(STATUS_NEW, 'New'), # Default state of request