Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / taxonomy_select.php
Last active August 29, 2015 13:59
Shows the taxonomy selection in admin as <select> box
<?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
@Ciantic
Ciantic / formatTime.ts
Created June 29, 2014 21:41
Format time HH:MM
// 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;
@Ciantic
Ciantic / parse-format-isodatetime.js
Last active August 29, 2015 14:07
Parse and format iso datetime
/**
* 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);
@Ciantic
Ciantic / djangosessionjson.py
Created June 16, 2010 19:18
Django JSON serialized database SessionStore
"""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'
"""
@Ciantic
Ciantic / django_session.php
Created June 17, 2010 13:57
PHP DjangoUser class
<?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")) {
@Ciantic
Ciantic / objectperms.py
Created June 27, 2010 13:18
Django object permission backend, that passesthrough
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
@Ciantic
Ciantic / django.fcgi.py
Created July 8, 2010 21:45
Django FCGI application
#!/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"
@Ciantic
Ciantic / insert_or_get_term_id.php
Created September 8, 2015 05:54
Insert or Get Term ID
<?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(
@Ciantic
Ciantic / multisitedmiddleware.py
Created January 25, 2011 16:19
MultiSitedMiddleware
"""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:
@Ciantic
Ciantic / sitecache.py
Created January 25, 2011 16:17
My Site object cache
"""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