Skip to content

Instantly share code, notes, and snippets.

View olivergeorge's full-sized avatar

Oliver George olivergeorge

  • Tasmania, Australia
  • 06:47 (UTC +11:00)
View GitHub Profile
@olivergeorge
olivergeorge / forms.py
Created March 5, 2013 06:13
SearchFilter which builds on django-filter. The query build itself is using code taken from django-admin.
from django.db import models
import django_filters
import operator
class SearchFilter(django_filters.CharFilter):
def __init__(self, name='pk', search_fields=[], *args, **kwargs):
super(SearchFilter, self).__init__(name, *args, **kwargs)
self.search_fields = search_fields
@olivergeorge
olivergeorge / gist:5360475
Created April 11, 2013 03:19
Snippet for adding an admin style search field using django_filters
import django_filters
class SearchFilter(django_filters.CharFilter):
def __init__(self, name='pk', search_fields=[], *args, **kwargs):
super(SearchFilter, self).__init__(name, *args, **kwargs)
self.search_fields = search_fields
def filter(self, qs, keywords):
@olivergeorge
olivergeorge / gist:32331359a66e01802b23
Last active August 29, 2015 14:03
Does this look like a reasonable way to bootstrap a view with details of a local Django REST Framework api? My goal is to avoid my app from having to fetch the root and options before it can start rendering...
from api.urls import router
from django.core.serializers import serialize
from django.core.serializers.json import DjangoJSONEncoder
from django.utils import simplejson
from django.utils.safestring import mark_safe
def test_ui(request):
"Simple view to bootstrap the ui based on the rest api"
endpoints = router.get_api_root_view()(request).data
@olivergeorge
olivergeorge / modal.cljs
Last active August 29, 2015 14:12
Bootstrap modal as pure OM
(ns olivergeorge.modal
(:require [om.core :as om :include-macros true]
[sablono.core :as html :refer-macros [html]]))
(def ESCAPE-KEY-CODE (js/Number 27))
(defn handle-key-down [owner e]
(if (= ESCAPE-KEY-CODE (.-keyCode e))
(if-let [on-dismiss (:on-dismiss (om/get-props owner))]
(on-dismiss e))))
@olivergeorge
olivergeorge / Experimenting-with-om-and-reactjsnet-prerendering.md
Last active August 29, 2015 14:16
Quick hack attempt of using om components with reactjs.net prerendering

First issue was around using goog.require so I switched to a production build (advanced optimisations) build.

Second issue...

Visual studio reported errors trying to establish the virtual environment. It looks, perhaps, Google Closure was looking for features which would be available on a headless JS VM.

''' Error while loading "~/Content/ui/js/omapp.min.js": ReferenceError: XMLHttpRequest is not defined

@olivergeorge
olivergeorge / resize-with-delay.cljs
Created March 23, 2015 04:46
Snippet showing how I was planning to use a timeout channel to delay a possibly expensive resize operation.
(defn update-table-width [owner]
(let [autowidth (om/get-node owner "autowidth")
width (.-width (goog.style.getSize autowidth))]
(om/set-state! owner :width width)))
;(defn resize-engine
; "Sets up a core async loop to report on counters. Waits for 1 second of
; silence before reporting aggregates since last report."
; [owner resizing-ch]
@olivergeorge
olivergeorge / modal.cljs
Created March 23, 2015 21:44
Rough cut/paste of a modal component
(def ESCAPE-KEY-CODE 27)
(defn handle-key-down [owner e]
"For handling non-printing events"
(if (= ESCAPE-KEY-CODE (.-keyCode e))
(if-let [on-dismiss (:on-dismiss (om/get-props owner))]
(on-dismiss e))))
(defn Modal [props owner]
(reify
(defn Date [props owner]
"
Date picker field with popup calendar:
- can type date
- can pick date from calendar
Props:
:label
:value
:on-date-change
(ns condense.performance
(:require-macros [cljs.core.async.macros :refer [go alt!]])
(:require [om.core :as om]
[cljs.core.async :refer [put! chan dropping-buffer timeout]]))
; Globals
(def perf-counters (atom {}))
(defprotocol IClear
(clear! [x]))
(defn field-as-value [field-cursor]
(reify
IDeref
(-deref [_] (:value field-cursor))
ISwap
(-swap! [o f] (reset! o (f @o)))
(-swap! [o f a] (reset! o (f @o a)))