Skip to content

Instantly share code, notes, and snippets.

View manicolosi's full-sized avatar

Mark A. Nicolosi manicolosi

View GitHub Profile
;; 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#)
;; 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)
(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!)
@manicolosi
manicolosi / gist:b8aade87adc85b5f95e2
Created February 10, 2015 20:34
Broken github syntax hilighting for clojure
(defn this-is-good []
(println "GOOD"))
(def foo \")
(defn this-is-wrong []
(println foo))
@manicolosi
manicolosi / saysh
Last active August 29, 2015 14:04
Troll tool for Mark B.
# 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"
@manicolosi
manicolosi / gist:6290355
Created August 21, 2013 04:35
Better Clojure code for file system watching...
(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})
@manicolosi
manicolosi / gist:6289768
Created August 21, 2013 02:32
Watch for filesystem events in Clojure using `java.nio.file`
(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
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(/</, "&lt;")
else
# 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.
#
# ******* ****--+ ****--+ *--+--+ *--+--+ *--+--+
# | | * | * | | * | * | | * | | * | |
# +--+--* +--**** +--*--+ ******* ****--+ *--+--+
# | | * | | * | * | | | * | * | * | |
# 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