Skip to content

Instantly share code, notes, and snippets.

View Eleeleth's full-sized avatar

Anthony Clever Eleeleth

View GitHub Profile
@eerien
eerien / forms.py
Last active May 12, 2024 11:20
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
@juntalis
juntalis / util.js
Created September 26, 2012 15:00
Utility one-liners for checking types, values, etc
/* Utility one-liners for checking types, values, etc */
var prims = ['string', 'number', 'boolean', 'function', 'array' ],
typof = function(x) { var s, t = typeof(x); return t === 'object' ? (s = Object.prototype.toString.call(x)).substring(8, s.length - 1).toLowerCase() : t; },
undef = function(x) { return typeof(x) === 'undefined' || x == undefined; },
defined = function(x) { return !undef(x); },
noVal = function(x) { return undef(x) || typof(x) === 'null' || x == null || isNaN(x); },
hasVal = function(x) { return !noVal(x); },
isStr = function(x) { return typof(x) === prims[0]; },
isNum = function(x) { return typof(x) === prims[1]; },
isBool = function(x) { return typof(x) === prims[2]; },