Skip to content

Instantly share code, notes, and snippets.

Kevin Downey hiredman

Block or report user

Report or block hiredman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View scratch.clj
(require '[clojure.core.async.impl.protocols :as impl]
'[clojure.core.async.impl.dispatch :as dispatch]
'[clojure.core.async.impl.channels :as c]
'[clojure.core.async :as async])
;;=> nil
(defn wait [watchable expected?]
(reify
impl/ReadPort
View scratch.clj
(require '[clojure.core.async.impl.protocols :as impl]
'[clojure.core.async.impl.dispatch :as dispatch])
;;=> nil
(extend-type java.util.concurrent.CompletionStage
impl/ReadPort
(take! [this handler]
(.whenCompleteAsync this
(reify
View q.clj
(defn message-queue-read-port [take-message ack-message nack-message]
(let [q (java.util.concurrent.LinkedBlockingQueue.)]
(async/thread
(loop [msg nil
handler nil]
(cond (and msg handler)
(let [_ (.lock handler)
take-cb (when (and (clojure.core.async.impl.protocols/active? handler)
(clojure.core.async.impl.protocols/commit handler))
handler)
View gist:05af7cef14991cfea802cf83fb82d178
user=> (require '[clojure.core.async :as async])
nil
user=> (def ^java.net.Socket s nil)
#'user/s
user=> (defn f [] (async/go (.getOutputStream s)))
#'user/f
user=> (defn f [] (async/go (try (.getOutputStream s) (catch Exception e nil))))
#'user/f
user=>
View cml.js
var cml = {
Buffer:function (n) {
var buf = [];
this.full=function() {
return !(buf.length < n);
}
this.add=function(item){
buf.push(item);
}
this.remove=function(item){
View ws.clj
(import '(java.nio ByteBuffer)
'(java.net InetSocketAddress)
'(java.util.concurrent LinkedBlockingQueue)
'(java.nio.channels SelectionKey
SocketChannel
SelectableChannel
ServerSocketChannel
Selector)
'(java.io Closeable)
'(clojure.lang PersistentQueue)
View jgroups.clj
;; clj -J-Xmx32m -Sdeps '{:deps {org.jgroups/jgroups {:mvn/version "4.0.12.Final"}}}'
(defn server []
(let [channel (org.jgroups.JChannel.)
_ (.connect channel "clojure-eval")
_ (.setReceiver
channel
(proxy [org.jgroups.ReceiverAdapter] []
(receive [msg-batch]
(doseq [msg (.array msg-batch)
@hiredman
hiredman / foo.clj
Created Feb 2, 2019
reflection boxing
View foo.clj
user=>
(as-> clojure.lang.RT %
(.getDeclaredField % "checkSpecAsserts")
(doto % (.setAccessible true))
(.get % nil)
(doto % prn)
(if % :a :b))
false
:a
user=>
View deployer.clj
(ns deployer
(:require [clojure.tools.deps.alpha :as deps]
[clojure.tools.deps.alpha.reader :as reader]
[clojure.java.io :as io]
[clojure.string :as string])
(:import (java.security MessageDigest)
(com.jcraft.jsch JSch)
(java.net URI)))
(def hex-alphabet (vec "0123456789ABCDEF"))
View substitution model.clj
(defn inc-more [nums]
(if (first nums)
(cons (inc (first nums))
(inc-more (rest nums)))
(list)))
(inc-more [1 2])
(if (first [1 2])
(cons (inc (first [1 2]))
You can’t perform that action at this time.