This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Indent container contents on new lines. | |
some_tuple = ( | |
("foo", "bar"), | |
("baz", "bat"), # Always add trailing commas. | |
) | |
some_dict = { | |
"foo": "bar", | |
"baz": "bat", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to add code samples in GitHub: | |
``` | |
def your_code(): | |
goes_here() | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html5media.configureFlowplayer = function(element, config) { | |
config.clip.onStart = function() { | |
}; | |
config.clip.onPause = function() { | |
}; | |
return config; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooAdmin(VersionAdmin): | |
def construct_change_message(self, request, form, formsets): | |
return "FOO" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Procfile | |
requirements.txt | |
runtime.txt | |
manage.py | |
project_name/ | |
----wsgi.py | |
----settings/ | |
--------local.py | |
--------production.py | |
--------base.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(models.Model): | |
parent = models.ForeignKey("self", blank=True, null=True) | |
reversion.register(Node) | |
with reversion.create_revision(): | |
p = Node.objects.create() # Version saved. | |
with reversion.create_revision(): | |
c = Node.objects.create() # Version saved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Runs a per-page init function. | |
* | |
* The init function is chosen via the `page` config setting. | |
* | |
* This has to be defined in a separate module, since RequireJS | |
* does not allow passing config to the main module. | |
*/ | |
define(["module"], function(module) { | |
OlderNewer