This file contains 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
;; Produces maps from let-like bindings. And yes: we are not proud of this. | |
(defmacro bindmap [bindings] | |
`(let [~@bindings] | |
~(reduce | |
(fn [m# [binding-form# _#]] | |
(let [binding-symbol# (cond | |
(map? binding-form#) | |
(:as binding-form#) |
This file contains 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
;; Async Lifecycle | |
(defn lifecycle-channel [component] | |
(.-lifecycleChannel component)) | |
(defn with-lifecycle [klass] | |
(let [ch (async/chan) | |
handle (fn [event] | |
(fn [& args] | |
(async/put! ch event) |
This file contains 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 my.promise-ring | |
(:require-macros [cljs.core.async.macros :refer [go go-loop]]) | |
(:require | |
[cljs.core.async :refer [promise-chan put! <! chan close!] :as async])) | |
; You Only Put Once | |
; YOPO | |
(enable-console-print!) |
This file contains 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 this-is-good [] | |
(println "GOOD")) | |
(def foo \") | |
(defn this-is-wrong [] | |
(println foo)) |
This file contains 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
# Source this thing from bash | |
trap 'preexec_invoke_exec' DEBUG | |
preexec () { :; } | |
preexec_invoke_exec () { | |
[ -n "$COMP_LINE" ] && return # do nothing if completing | |
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND | |
local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`; | |
preexec "$this_command" |
This file contains 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 manico.utils.fs-watch | |
(:require [clojure.set :as set] | |
[lwjgl-spike.utils.interop :as interop]) | |
(:import [java.nio.file Paths WatchEvent$Kind | |
StandardWatchEventKinds])) | |
(def ^:private keywords->event-kinds | |
{:create StandardWatchEventKinds/ENTRY_CREATE | |
:modify StandardWatchEventKinds/ENTRY_MODIFY | |
:delete StandardWatchEventKinds/ENTRY_DELETE}) |
This file contains 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 watch-home [] | |
(let [path (java.nio.file.Paths/get "/home/mark" (into-array String [])) | |
watch-service (-> path (.getFileSystem) (.newWatchService))] | |
(.register path watch-service (into-array java.nio.file.WatchEvent$Kind | |
[java.nio.file.StandardWatchEventKinds/ENTRY_CREATE | |
java.nio.file.StandardWatchEventKinds/ENTRY_MODIFY | |
java.nio.file.StandardWatchEventKinds/ENTRY_DELETE])) | |
(loop [poll 0] | |
(if-let [watch-key (.poll watch-service)] | |
(do |
This file contains 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
module HTML | |
class StathamSanitizer < WhiteListSanitizer | |
protected | |
def tokenize(text, options) | |
super.map do |token| | |
if token.is_a?(HTML::Tag) && options[:parent].include?(token.name) | |
token.to_s.gsub(/</, "<") | |
else |
This file contains 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
# Project Euler - Problem 15 | |
# http://projecteuler.net/index.php?section=problems&id=15 | |
# | |
# Starting in the top left corner of a 2×2 grid, there are 6 routes | |
# (without backtracking) to the bottom right corner. | |
# | |
# ******* ****--+ ****--+ *--+--+ *--+--+ *--+--+ | |
# | | * | * | | * | * | | * | | * | | | |
# +--+--* +--**** +--*--+ ******* ****--+ *--+--+ | |
# | | * | | * | * | | | * | * | * | | |
This file contains 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
# Project Euler - Problem 14 | |
# http://projecteuler.net/index.php?section=problems&id=14 | |
# | |
# The following iterative sequence is defined for the set of positive | |
# integers: | |
# | |
# n → n/2 (n is even) | |
# n → 3n + 1 (n is odd) | |
# | |
# Using the rule above and starting with 13, we generate the following |
NewerOlder