$ uname -r
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
| ;; Synchronous Clojure trained us to use Exceptions, while asynchronous JavaScript has trained us to use Promises. | |
| ;; In contexts where we work asynchronously in Clojure (in particular ClojureScript), it can be difficult to see a definite way of managing failure. Here are some proposals. | |
| ;; OPTION 1: adapting exception handling to core.async CSPs | |
| ;; As proposed by David Nolen, with some macro sugar we use Exceptions in go blocks with core async in the same way we would do with synchronous code. | |
| (require '[clojure.core.async :as a :refer [go]]) | |
| ;; defining some helper macros | |
| (defn throw-err "Throw if is error, will be different in ClojureScript" |
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 app.logging | |
| (:refer-clojure :exclude [time]) | |
| (:require #?(:clj [clojure.tools.logging :as log] | |
| :cljs [goog.log :as glog])) | |
| #?(:cljs (:import goog.debug.Console))) | |
| #?(:cljs | |
| (def logger | |
| (glog/getLogger "app"))) |
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) Rich Hickey. All rights reserved. | |
| * The use and distribution terms for this software are covered by the | |
| * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
| * which can be found in the file epl-v10.html 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. | |
| **/ |
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 dispatch-map.core | |
| (:refer-clojure :exclude [dispatch-fn isa?])) | |
| (declare empty-cache reset-cache! update-map cache-best prefers?) | |
| (defprotocol IHierarchy | |
| (-isa [this child parent])) | |
| (defn isa? | |
| "Returns true if (= child parent), or child is directly or |
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
| -- great for exporting a playlist from Swinsian to another music playing software, while keeping the order of the playlist. | |
| -- to install: open Script Editor.app, paste this, go File > Export, choose File Format: application, save anywhere you like. | |
| -- to use: select tracks to export in Swinsian, then run the app you just saved. | |
| -- note: doesn't handle those files already existing in selected folder. pads for two-digits, adds artist - title.ext | |
| set theFolder to choose folder | |
| set text item delimiters to "." | |
| tell application "Swinsian" | |
| set selected to selection of window 1 | |
| -- check that the playlist is not empty |
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 stack-traces [] | |
| (->> (Thread/currentThread) | |
| (.getStackTrace) | |
| (map (juxt #(.getClassName %) #(.getMethodName %) #(.getLineNumber %))) | |
| (map #(clojure.string/join ":" %)))) |
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 print-threads [& {:keys [headers pre-fn] | |
| :or {pre-fn identity}}] | |
| (let [thread-set (keys (Thread/getAllStackTraces)) | |
| thread-data (mapv bean thread-set) | |
| headers (or headers (-> thread-data first keys))] | |
| (clojure.pprint/print-table headers (pre-fn thread-data)))) | |
| (defn print-threads-str [& args] | |
| (with-out-str (apply print-threads args))) |
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 app.log | |
| (:require [clojure.java.io :as io]) | |
| (:import ch.qos.logback.classic.joran.JoranConfigurator | |
| ch.qos.logback.classic.LoggerContext | |
| org.slf4j.LoggerFactory)) | |
| (defn reload-logback | |
| [] | |
| (let [context ^LoggerContext (LoggerFactory/getILoggerFactory) | |
| configurator (JoranConfigurator.) |
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
| ;; | |
| ;; Example usages at the bottom of the file | |
| ;; | |
| (defn productions | |
| "Returns a sequence of values by repeatedly calling `produce!` until it | |
| returns `fin`. The sequence can be used lazily/caching or reducible/non-caching. | |
| The arity-2 variant's `produce!` takes no arguments and returns a value | |
| or the terminator. |