Skip to content

Instantly share code, notes, and snippets.

Avatar

Craig Andera candera

View GitHub Profile
@candera
candera / example.sh
Last active Jan 26, 2020
Package ClojureScript in a Native EXE
View example.sh
# Update: This micro-blog is now also a guide on clojurescript.org:
# http://clojurescript.org/guides/native-executables
# Hello! This is a micro-post about how to produce native executables
# from ClojureScript source. The basic idea is to produce a
# JavaScript file using the ClojureScript compiler, and then use a
# Node.js tool called nexe (https://github.com/jaredallard/nexe) to
# compile that into an executable. The resulting file can be run
# without requiring a node install on the target machine, which can
# be handy.
View recur.cljs
(let [opacity-ch (async/chan (async/dropping-buffer 1))]
(async/go-loop [last-set (:opacity @app-state)
last-received nil]
(let [t (async/timeout 100)
[ch val] (async/alts! [t opacity-ch])
[new-set new-received] (cond
(= ch opacity-ch)
[last-set val]
View lat-long.clj
(require '[clojure.math.combinatorics :as combo]
'[clojure.core.async :as async])
(def zeus-route
["Kadena"
"Pohang"
"Pusan"
"Kimhae"
"Sachon"
"Taegu"
View solvent-guard.clj
(require '[scad-clj.scad :refer :all]
'[scad-clj.model :refer :all])
(defn degrees [d]
(-> d (/ 180.0) (* Math/PI)))
(def x-axis [1 0 0])
(def y-axis [0 1 0])
(def z-axis [0 0 1])
View freepie-axis-mapper.py
import time
class Utils:
@staticmethod
def mapmouse(val):
if abs(val) <= 13:
return val * 128
elif abs(val) <= 25:
return val * 256
View transit.org
@candera
candera / cpu.clj
Created Jul 7, 2014
Measure CPU utilization
View cpu.clj
(defn- cpu-stats
"Returns measures of the various types of CPU usage to date"
[]
(->> (-> (clojure.java.shell/sh "cat" "/proc/stat")
:out
(clojure.string/split #"\n")
first
(clojure.string/split #"\s"))
(remove clojure.string/blank?)
(drop 1)
View ssh-repl.org

Embedding an SSH-accessible REPL in a Clojure process

N.B. This is now a library, thanks to the efforts of the wonderful @mtnygard. And the README does a good job of making clear just how terrible an idea it is to actually do this. :)

As any Clojurist knows, the REPL is an incredibly handy development tool. It can also be useful as a tool for debugging running programs. Of course, this raises the question of how to limit access to the REPL to authorized parties. With the Apache SSHD library, you can embed an SSH server in any JVM process. It takes only a little code to hook this up to a REPL, and to limit access either by public key or

View transact-firehose.clj
;; This has to be a separate function. The way we had it before, with
;; a loop inside a future, creates a closure that captures the head of
;; the sequence. Locals clearing here saves us from that.
(defn- enqueue-transactions
"Transact a (potentially infinite) sequence of transactions on `q`,
reporting status via `status`. Pause for `delay` (if non-nil)
between each transaction."
[conn [tx & more] q status delay]
(if (or (not tx) (:done @status))
(.put q (future :done))
View dopar.clj
(defn dopar
"Given a (potentially infinite) sequence `coll`, uses core.async to
run `f` for side effects against each value in the collection.
Performs at most `concur` operations in parallel, and never enqueues
more than `lead` items ahead of the ones being consumed. If any call
to `f` throws an exception, it will be rethrown from this function.
Otherwise, returns nil. Optional timeout value is number of
milliseconds to wait for all operations to complete."
([coll f concur lead] (dopar coll f concur lead nil))
([coll f concur lead timeout-ms]