Skip to content

Instantly share code, notes, and snippets.

<script>
function decodeURL() {
var uri_enc = document.getElementById("url").value;
var uri_dec = decodeURIComponent(uri_enc);
var text = document.getElementById("text");
text.textContent = uri_dec;
}
</script>
<input id="url">
@alej0varas
alej0varas / digits.py
Created October 5, 2017 13:21
(FTR Digits was retired on 30/09/2017) Digits verification
class DigitsVerification:
DIGITS_API_URL = 'https://api.digits.com'
AUTH_PROVIDER_KEY = 'apiUrl'
CREDENTIALS_KEY = 'credentials'
def __call__(self, credentials):
auth_provider = self.validate_auth_provider(credentials)
if auth_provider is None:
return None
@alej0varas
alej0varas / colorpickerpanel.py
Created September 12, 2014 16:03
Wagtail CMS color picker panel. Requires jQuery plugin http://www.eyecon.ro/colorpicker/
from django.conf import settings
from django.utils.safestring import mark_safe
from wagtail.wagtailadmin.edit_handlers import BaseFieldPanel
class BaseColorFieldPanel(BaseFieldPanel):
def render_js(self):
big_javascript_block = """
(function() {
@alej0varas
alej0varas / wagtailredirectpage.py
Created September 26, 2014 12:41
Wagtail redirect page. Can link to page, ulr and document.
# Thanks to Ethan Jucovy
# http://www.coactivate.org/projects/ejucovy/blog/2014/05/10/wagtail-notes-managing-redirects-as-pages/
# This model comes from wagtaildemo
class LinkFields(models.Model):
link_external = models.URLField("External link", blank=True)
link_page = models.ForeignKey(
'wagtailcore.Page',
null=True,
@alej0varas
alej0varas / django-jsonfield-length-sum-average.py
Created September 2, 2016 14:37
Example usage of database funtions(`Sum` and `Avg`) and Django `JSONField`'s `jsonb_array_length`
# Example usage of database funtions(`Sum` and `Avg`) and Django `JSONField`'s `jsonb_array_length`
# PostgreSQL json field functions: https://www.postgresql.org/docs/9.5/static/functions-json.html
# Django `F` and `Func`: https://docs.djangoproject.com/en/1.10/ref/models/expressions/#f-expressions
# Django aggregation: https://docs.djangoproject.com/en/1.10/topics/db/aggregation/
# Django `JSONField`: https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield
# Given a model
class Contact(models.Model):
numbers = JSONField(help_text="An array of numbers")