This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns exp.dfn | |
| (:refer-clojure :exclude [take eval compile apply])) | |
| (alias 'c 'clojure.core) | |
| (defn destructure* | |
| "stolen from core, just add options" | |
| [bindings & [{:keys [unbound-val default-bindings on-unbound] | |
| :or {unbound-val nil default-bindings {} on-unbound identity}}]] | |
| (let [bents (partition 2 bindings) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; error handling ----------------------------------- | |
| (defn check-cyclic-prefs [sd spec specs] | |
| (assert (not-any? #(contains? (set (get @(:prefs sd) %)) | |
| spec) | |
| specs) | |
| (str "circular dependency:" | |
| "\nname: " (:name sd) | |
| "\nspec:" spec | |
| "\nconflicts: " (keep #(contains? (set (get @(:prefs sd) %)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; Copyright (c) 2015 Designed.ly, Marcin Bilski | |
| ; The use and distribution terms for this software are covered by the | |
| ; Eclipse Public License which can be found in the file LICENSE at the root of this distribution. | |
| ; By using this software in any fashion, you are agreeing to be bound by the terms of this license. | |
| ; You must not remove this notice, or any other, from this software. | |
| (ns reforms.core.import | |
| (:require [cljs.analyzer.api :as ana-api])) | |
| (defmacro import-vars [[_quote ns]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns reforms.core.import | |
| (:require [cljs.analyzer.api :as ana-api])) | |
| (defmacro import-vars [[_quote ns]] | |
| `(do | |
| ~@(->> | |
| (ana-api/ns-interns ns) | |
| (remove (comp :macro second)) | |
| (map (fn [[k# _]] | |
| `(def ~(symbol k#) ~(symbol (name ns) (name k#)))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn file-input [on-result] | |
| [:input {:type "file" | |
| :on-change | |
| (fn [e] | |
| (let [f (first (array-seq (.. e -target -files))) | |
| reader (js/FileReader.)] | |
| (aset reader "onload" | |
| (fn [e] | |
| (on-result (.. e -target -result)))) | |
| (.readAsText reader f)))}]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn download [data filename & [format]] | |
| (let [format (or format "application/octet-stream") | |
| a (.createElement js/document "a")] | |
| (aset a "href" (str "data:text/plain;charset=utf-8," (pr-str data))) | |
| (aset a "download" filename) | |
| (.click a) | |
| (.removeChild js/document a))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Transparent Functions | |
| ;; I was experimenting with transducers and wanted a way to understand how they worked. Transducer | |
| ;; code uses many nested functions in various locations with other nested functions defined as local | |
| ;; variables in scope. Typically after an anonymous Clojure function is defined you have no visibility | |
| ;; into the locals that were in scope when the function was defined, where the function came from, | |
| ;; or the code in the function. I defined a macro, tfn, that creates a transparent function. It's | |
| ;; a normal Clojure function with additional metadata including the function code and local | |
| ;; variable names and values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require '[reagent.core :as r]) | |
| (defn i [] | |
| (let [dims (r/atom {}) | |
| this (atom nil) | |
| resized? (atom nil)] | |
| (fn [][:div | |
| [:img {:src "http://www.lispcast.com/img/pre-conj/rich-hickey.jpeg" | |
| :ref (fn [x] (reset! this x)) | |
| :on-load |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getQueryVariable(variable) { | |
| var query = window.location.search.substring(1); | |
| var vars = query.split('&'); | |
| for (var i = 0; i < vars.length; i++) { | |
| var pair = vars[i].split('='); | |
| if (decodeURIComponent(pair[0]) == variable) { | |
| return decodeURIComponent(pair[1]); | |
| } | |
| } | |
| console.log('Query variable %s not found', variable); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn set-timeout [f millis] | |
| (let [running (atom true)] | |
| (future | |
| (while @running | |
| (f) | |
| (Thread/sleep millis))) | |
| #(reset! running nil))) | |
| ;; start an interval, the stop function is returned and bound to stop-interval var | |
| (def stop-interval (set-interval #(println "yop") 1000)) |