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
<?php | |
// Author: Jari Pennanen | |
// License: Public Domain | |
// 2014-04-16 | |
/** | |
* Display taxonomy selection in admin as select box | |
* | |
* @param WP_Post $post | |
* @param array $box |
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
// total in seconds | |
function formatTime(total: number): string { | |
// If the number is float ceiling gives best result | |
var total = Math.ceil(total), | |
mins = Math.floor(total / 60), | |
secs = Math.floor(total - mins * 60), | |
m = ("000" + mins).slice(-2), | |
s = ("000" + secs).slice(-2); | |
return m + ":" + s; |
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
/** | |
* Parse ISO datetime | |
* | |
* 2014-10-18 15:30:30 | |
* 2014-10-18T15:30:30 | |
* 2014-10-18 | |
*/ | |
function parseIsoDatetime(dtstr) { | |
var dt = dtstr.split(/[: T-]/).map(parseFloat); |
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
"""Session table that stores session data as JSON | |
Works similarily as :mod:`django.contrib.sessions.backends.db` | |
To use this add to your settings.py:: | |
SESSION_ENGINE = 'djangosessionjson' | |
""" |
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
<?PHP | |
/* | |
DjangoUser object to Joomla in PHP. | |
(Can be adapted easily to other PHP frameworks) | |
Usage:: | |
$user =& DjangoUser::getUser(); | |
if ($user && $user->hasPerm("polls.can_vote")) { |
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.conf import settings | |
class ObjectPermBackend(object): | |
"""Simple object permission backend that passesthrough the has_perm calls | |
to the object. | |
""" | |
supports_object_permissions = True | |
supports_anonymous_user = True | |
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
#!/usr/bin/python | |
import sys, os | |
# Add a custom Python path. | |
THE_SITE = "mysite" | |
PYTHONPATH = "/var/www/mysite.example.com/django-fcgi/pythonpath/" | |
# Following is inferred from above | |
THE_DIR = PYTHONPATH + THE_SITE | |
DJANGO_PATH = PYTHONPATH + "django" |
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
<?php | |
/** | |
* (WordPress) Insert or get term id | |
* | |
* @return int Term ID (0 no term was inserted or found) | |
*/ | |
function __wp_insert_or_get_term_id($name, $taxonomy, $parent = 0) { | |
if (!($term = get_term_by("name", $name, $taxonomy))) { | |
$insert = wp_insert_term($name, $taxonomy, array( |
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
"""Allows serving multiple sites per Django instance | |
""" | |
from django.utils.cache import patch_vary_headers | |
from sitecache import get_site_id, get_urlconf | |
class MultiSitedMiddleware: |
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
"""Cache of Site related settings | |
Site IDs and urlconfs are such that are testd on *all* requests thus they need | |
to be cached. | |
""" | |
from django.conf import settings | |
from django.contrib.sites.models import Site |
OlderNewer