Skip to content

Instantly share code, notes, and snippets.

(defn set-style
[elt property value]
(doto (.-style elt)
(.setProperty property value))
elt)
(defn set-styles
[elt s]
(let [style (.-style elt)]
(doseq [[property value] s]
-> a = {json : "hello"}
Object {json: "hello"}
-> a.json
"hello"
-> a = {"json" : "hello"}
Object {json: "hello"}
-> a.json
@gtrak
gtrak / gist:5042933
Created February 26, 2013 22:30
Request-scoped compojure bindings, compatible with defroutes.
(defmacro wrap-request-binding
"Wraps the ring handler definition to provide request-scoped bindings
via symbol-capture on %."
[bindings handler-def]
`(fn [request#]
(let [~'% request#
~@bindings]
(~handler-def request#))))
(defmacro request-binding-handlers
com.garytrakhman.cordova_test.app.flat_button = function() {
var flat_button__delegate = function(text, p__6105) {
var vec__6108 = p__6105;
var width = cljs.core.nth.call(null, vec__6108, 0, null);
var height = cljs.core.nth.call(null, vec__6108, 1, null);
var b = function() {
var G__6109 = new goog.ui.Button([cljs.core.str(text)].join(""), goog.ui.FlatButtonRenderer.getInstance());
G__6109.render(com.garytrakhman.cordova_test.app.top.call(null));
return G__6109
}();
@gtrak
gtrak / gist:4948166
Last active December 13, 2015 17:28
;;; helpful to get rid of repetitive compojure destructuring.
(defmacro wrap-request-binding
"Wraps the ring handler definition to provide request-scoped bindings
via symbol-capture on %."
[bindings handler-def]
`(fn [request#]
(let [~'% request#
~@bindings]
(~handler-def req#))))
@gtrak
gtrak / gist:4726660
Created February 6, 2013 22:55
circular-lists.
user=> (take 6 (cycle [1 2 3]))
(1 2 3 1 2 3)
user=> (source cycle)
(defn cycle
"Returns a lazy (infinite!) sequence of repetitions of the items in coll."
{:added "1.0"}
[coll] (lazy-seq
(when-let [s (seq coll)]
(concat s (cycle s)))))
@gtrak
gtrak / gist:4548456
Last active December 11, 2015 04:58
(ns xml.test
(:require [clojure.java.io :as io]
[clojure.data.xml :as xml]))
;; wget
;; download.geofabrik.de/openstreetmap/north-america/us/maryland.osm.bz2
(def xml-seq
#(-> (io/file "/home/gary/dev/maryland.osm")
io/input-stream
(defmacro let-map
"Avoids having to build maps from let bindings manually"
[bindings]
(let [names (->> (take-nth 2 bindings)
(tree-seq #(or (sequential? %) (map? %)) identity)
(filter symbol?)
(into #{})) ; dumps it all into a set
bindings (destructure bindings)]
`(let [~@bindings]
(zipmap [~@(map keyword names)]
(defmacro let-map
[pairs]
(let [names (map first (partition 2 pairs))]
`(let [~@pairs]
(zipmap
[~@(map (comp keyword name) names)]
[~@names]))))
@gtrak
gtrak / gist:4437190
Created January 2, 2013 19:32
Fogus's 2012 books read, titles scraped with some noob jquery, from http://blog.fogus.me/2013/01/01/books-read-in-2012/
var jq = document.createElement('script');
jq.src = "http://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
$('div a').map(function(){return this.title;}).each(function(){console.log(this.toString())})
Borges: A Life
Island
Smalltalk 80: Bits Of History, Words Of Advice