Skip to content

Instantly share code, notes, and snippets.

Avatar

Oliver George olivergeorge

  • Tasmania, Australia
View GitHub Profile
View gist:476058
from django.core.exceptions import ValidationError
from django.db.models import Field, CharField
__all__ = ['MultiColumnField']
try:
from hashlib import md5
except ImportError:
from md5 import new as md5
View clean_utm.js
// Clean up all those invasive and ugly utm_ parameters, so you can paste a url.
// (will reload the page, be warned)
(function(){
var qs = window.location.search.slice(1).split('&'),
newqs = [];
for (var i = 0; i < qs.length; i++) {
if (qs[i].slice(0,4)!='utm_') {
newqs.push(qs[i]);
}
}
@leobm
leobm / gist:6061734
Created Jul 23, 2013
break point in clojure - A macro from 《the joy of clojure》 for debugging:
View gist:6061734
(defn contextual-eval [ctx expr]
(eval
`(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)]
~expr)))
(defmacro local-context []
(let [symbols (keys &env)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(defn readr [prompt exit-code]
(let [input (clojure.main/repl-read prompt exit-code)]
(if (= input ::tl)
View router.cljs
(def views
{:some-view SomeView
:another-view AnotherView})
(def factories
(map om/factory (vals views)))
(defui Router
static om/Ident
(ident [this {:keys [route]}]
@freewayz
freewayz / django_model_deletable.py
Created Sep 27, 2016
Django check if model has related object before Deleting the model
View django_model_deletable.py
#After looking for a way to check if a model instance can be deleted in django ,
#i came across many sample, but was not working as expected. Hope this solution can help.
#Let start by creating an Abstract model class which can be inherited by other model
class ModelIsDeletable(models.Model):
name = models.CharField(max_length=200, blank=True, null=True, unique=True)
description = models.CharField(max_length=200, blank=True, null=True)
date_modified = models.DateTimeField(auto_now_add=True)
@kennyjwilli
kennyjwilli / defspec-test.clj
Created Nov 5, 2016
clojure.spec.test integration with clojure.test
View defspec-test.clj
(defmacro defspec-test
([name sym-or-syms] `(defspec-test ~name ~sym-or-syms nil))
([name sym-or-syms opts]
(when t/*load-tests*
`(def ~(vary-meta name assoc :test `(fn []
(let [check-results# (clojure.spec.test/check ~sym-or-syms ~opts)
checks-passed?# (every? nil? (map :failure check-results#))]
(if checks-passed?#
(t/do-report {:type :pass
:message (str "Generative tests pass for "
@pesterhazy
pesterhazy / error_boundary.cljs
Last active Oct 12, 2021
Reagent error boundary for recovering from exceptions
View error_boundary.cljs
(ns error-boundary.error-boundary
(:require [reagent.core :as r]
[reagent.impl.component :as comp]
[reagent.impl.util :as util]
[goog.object :as gobj]))
;; (c) 2016 Paulus Esterhazy
;;
;; License: MIT
View Lambda-ApiGateway-Cloudformation.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation sample template that contains a single Lambda function behind an API Gateway",
"Resources": {
"GreetingLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
@terjesb
terjesb / latency.txt
Created May 4, 2017 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@raymcdermott
raymcdermott / decoding-jwt.clj
Last active May 12, 2020
Simple JWT Decoder in Clojure
View decoding-jwt.clj
(defn base64-decode
"Utility function over the Java 8 base64 decoder"
[to-decode]
(String. (.decode (Base64/getDecoder) ^String to-decode)))
(defn string->edn
"Parse JSON from a string returning an edn map, otherwise nil"
[string]
(when-let [edn (json/decode string true)]
(when (map? edn)