Skip to content

Instantly share code, notes, and snippets.

View etianen's full-sized avatar

Dave Hall etianen

View GitHub Profile
from django.db import models
import reversion
from reversion.models import Revision
from django.db import transaction
from django.db.models.signals import m2m_changed
class M2MRevisionManager(reversion.revisions.RevisionManager):
def register(self, model=None, adapter_cls=reversion.VersionAdapter, **field_overrides):
m2m_fields = model._meta.local_many_to_many
for f in m2m_fields:
Procfile
requirements.txt
runtime.txt
manage.py
project_name/
----wsgi.py
----settings/
--------local.py
--------production.py
--------base.py
class FooAdmin(VersionAdmin):
def construct_change_message(self, request, form, formsets):
return "FOO"
$("#your-button").click(function() {
// Remove the old audio tag.
$("#your-audio-container").find("audio").remove()
// Add a new audio tag in.
$("#your-audio-container").append($("<audio/>", {
src: "new-audio-file.mp3",
controls: true,
preload: true
}));
// Apply the html5media shim on legacy browsers.
html5media.configureFlowplayer = function(element, config) {
config.clip.onStart = function() {
};
config.clip.onPause = function() {
};
return config;
}
@register.filter
def search_description(obj, query):
for term in [query] + query.split():
pattern = re.compile(re.escape(term), re.IGNORECASE)
if pattern.search(obj.title):
return obj.description
for content in (obj.description, obj.content):
match = pattern.search(content)
if match:
start = max(match.start() - 100, 0)
How to add code samples in GitHub:
```
def your_code():
goes_here()
```
# Indent container contents on new lines.
some_tuple = (
("foo", "bar"),
("baz", "bat"), # Always add trailing commas.
)
some_dict = {
"foo": "bar",
"baz": "bat",
}
@etianen
etianen / gist:8595035
Last active January 4, 2016 08:19
Optimizing LESS stylesheets with RequireJS
/**
* LESS stylesheet loader.
*
* Load a LESS stylesheet using style!main.less . This will load
* a stylesheet on the path ../css/main.less, compile it to CSS,
* and inject it in the page.
*
* During the optimization step with r.js, the stylesheet will be
* inlined with the javascript file.
*
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave Hall 20/01/2014
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iQEcBAEBAgAGBQJS3YYEAAoJEIayWs+cr8YFXD8H/j/K0yjIW/gOalmT5sW8twk6
AfL9cJ4/PjM5wDnB3s879Wr4+OjHfIocwGt5czd8c2xqdo3t4EvySnBKRivDafx4
bNhqiXBGApGiA0fCgxGBSSBdAo4SDtTO7qMmDb0TiGXjg33j83TX1AiY/M0IyobO