Skip to content

Instantly share code, notes, and snippets.

@joncombe
joncombe / gist:1687068
Created January 27, 2012 04:55
Experiments with ExCanvas: Pie Charts (See http://joncom.be/code/excanvas-piechart/)
function PieChart(iMiddleX, iMiddleY, iRadius,
iExplodeDistance, bShowShadow, iDonutRadius, aData) {
// draw shadow
if (bShowShadow == true) {
var iStartAngle = 0;
var iShadowOffset = (iRadius / 45);
for (var i = 0; i < aData.length; i++) {
iStartAngle = DrawSlice(oColors.shadow,
iMiddleX + iShadowOffset,
iMiddleY + iShadowOffset,
@joncombe
joncombe / gist:1701894
Created January 30, 2012 01:51
Tache: a jQuery AJAX cache plugin (See http://joncom.be/code/jquery-tache/)
/*
License:
Tache 1.0 jQuery Plugin
Copyright (c) 2008 Jon Combe (http://joncom.be)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
@joncombe
joncombe / gist:2057145
Created March 17, 2012 09:44
Jookie: a jQuery JSON cookie handler (See http://joncom.be/code/jquery-jookie/)
/*
License:
Jookie 1.0 jQuery Plugin
Copyright (c) 2009 Jon Combe (http://joncom.be)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
@joncombe
joncombe / gist:fd93d0f83409dcf344c7
Created May 18, 2014 00:32
GeoDjango setup on Ubuntu 12.04
# https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/geolibs/
sudo apt-get install binutils libproj-dev gdal-bin
# http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS21UbuntuPGSQL93Apt
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list'
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-9.3-postgis pgadmin3 postgresql-contrib
# https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/postgis/
@joncombe
joncombe / .bash_aliases
Last active November 18, 2022 07:30
Personal .bash_aliases file
# get latest .bash_aliases file (you will need to logout and log back in to use it)
updateba() {
cd ~
rm .bash_aliases
wget https://gist.githubusercontent.com/joncombe/94b099d545a18cb970f8/raw/.bash_aliases --no-cache
}
# ng serve with host and default port
alias ngs='ng serve --host 0.0.0.0 --port 8001'
alias ngsp='ng serve --host 0.0.0.0 --disable-host-check --live-reload-client http://0.0.0.0:8001 --port 8001 --proxy-config proxy.conf.json'
@joncombe
joncombe / stars.py
Created February 2, 2019 05:16
A simple python script to generate a "rating indicator" stars PNG image and CSS
import math
import os
from PIL import Image, ImageDraw
"""
A very simple script to generate a row of star images which can be
used in a rating indicator (e.g. 4 out of 5 stars), and some css to
go with it..
Usage example:
@joncombe
joncombe / gist:4d4153413525f09d738dd7d16d04e78e
Created March 27, 2019 11:28
Django template tag to access settings
"""
Please don't use this for PHP-esque in template treachery. It fixed an emergency I had. Maybe it can for you too.
Output a string...
{% setting "FOO.BAR" %}
Use in an expression...
{% setting "FOO.BAR" as foobar %}
{% if foobar %}yeah!{% else %}boo!{% endif %}
@joncombe
joncombe / thai_phone.py
Last active April 15, 2019 05:38
Django template tag to format Thai phone numbers
"""
# https://gist.github.com/joncombe/a208be990d7b98c15b8dbf5475eb75c3
{% load thai_phone %}
{{ landline|thai_phone }} # 02 123 4567
{{ mobile|thai_phone }} # 081 234 5678
{{ mobile|thai_phone:'-' }} # 081-234-5678
"""
@joncombe
joncombe / integercsvfield.py
Last active May 8, 2021 07:19
Django IntegerCSVField: Accepts a string such as "43,575,3,123,543". Any other characters are invalid
from django import forms
from django.core.exceptions import ValidationError
from apps.merchant.models import Merchant
from views.form_fields import XEDateRangeField
class IntegerCSVField(forms.CharField):
def __init__(self, min_value=None, max_value=None, *args, **kwargs):
super().__init__(**kwargs)