Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block rwat

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 pg.web.messaging.clj
(ns pg.web.messaging
(:require [clojure.core.async :refer [>! <! >!! <!! alts! alts!! chan go go-loop thread timeout close!] :as async]
[pg.util :as util]
(def buffer-size 50)
(def wait-time (* 25 1000))
(comment "
View pg.web.core.clj
(ns pg.web.core
(:require [clojure.core.async :refer [>! <! >!! <!! alts! chan go go-loop put! take! thread timeout close!] :as async]
[ :refer [refresh]]
[compojure.core :refer [defroutes GET POST]]
[compojure.route :as route]
[compojure.handler :as handler]
[integrant.core :as ig]
[ring.adapter.jetty :as jetty]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.format-response :refer [wrap-transit-json-response]]
View pg.web.messaging.cljs
(ns pg.web.messaging
(:require [cljs.core.async :refer [>! <! chan put! take! timeout close!] :as async]
[ajax.core :refer [GET POST]]
[pg.util :as util]
(:require-macros [cljs.core.async.macros :refer [alt! go go-loop]]))
(def temp-start-time (util/local-instval))
;; these are the only functions and vars exported from this namespace
View pg.util.clj
(ns pg.util
(:require [clojure.core.async :refer [>! <! >!! <!! alts! alts!! chan go go-loop put! take! thread timeout close!] :as async]))
;; synchronous; takes from channel argument if something is available, else returns nil
(def maybe-take!
(let [closed-ch (doto (chan) (close!))]
(fn [ch]
(let [[x port] (alts!! [ch closed-ch] {:priority true})]
(when (= port ch)
rwat / cache-interact.clj
Last active Jun 28, 2017
generalizes and makes transparent the use of clojure.core.cache
View cache-interact.clj
(ns foo
(:require [clojure.core.cache :as cache]))
(defn cache-interact
[the-agent the-function & the-items]
"Generalizes the interaction of performing c.c.cache operations by
transparently retrieving something from a cache or running the supplied
function outside of the agent's thread to generate a value"
(let [delay-func (delay (apply the-function the-items))
the-promise (promise)
rwat / clojurescript_snippets.cljs
Last active Jan 1, 2016
Sundry Clojurescript snippets
View clojurescript_snippets.cljs
;; milliseconds since the epoch
(.now js/Date)
;; read clojure data received over the network
(ns foo.core (:require [cljs.reader :as reader]))
(reader/read-string x)
;; write clojure data to send over the network
(pr-str {:hi "there"})
rwat / clojure_snippets.clj
Last active Jan 1, 2016
Sundry Clojure snippets
View clojure_snippets.clj
;; current time
;; make a version 4 random UUID as per
;; start a new thread and run a function
(.start (Thread. (fn [] (loop []
rwat / my-date-time.clj
Created Jan 24, 2011
exception handling example
View my-date-time.clj
(ns my-ns
(:use [clj-time.core :only [date-time]]))
(defn my-date-time
"same as clj-time.core date-time but returns nil on improper input"
[& args]
(apply date-time (map #(Integer/parseInt %) args))
(catch RuntimeException e nil)))
View leaks_memory.clj
(import '( InetAddress
; networking
(defrecord UDPServer [dgram-socket connected closed])
View is-rfc1918.clj
(ns your-namespace
(:use [clojure.string :only [split]]))
; authored by ordnungswidrig
(defn is-rfc1918?
"Returns true if a string is a dotted quad in the IP ranges of, or, else returns nil)"
[^String ip]
(when-let [[a b c d :as qs]
You can’t perform that action at this time.