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 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 |
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 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) | |
x))))) |
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 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 " |
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 pg.web.core | |
(:require [clojure.core.async :refer [>! <! >!! <!! alts! chan go go-loop put! take! thread timeout close!] :as async] | |
[clojure.tools.namespace.repl :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]] |
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 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) |
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 bar.baz | |
(:require [vertigo.core :as vc] | |
[vertigo.structs :as vs])) | |
;; | |
;; based off of work by Michał Marczyk | |
;; http://stackoverflow.com/questions/8949837/binary-search-in-clojure-implementation-performance | |
;; | |
(set! *warn-on-reflection* true) |
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
;; 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"}) |
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
;; current time | |
(System/currentTimeMillis) | |
;; make a version 4 random UUID as per http://www.ietf.org/rfc/rfc4122.txt | |
(java.util.UUID/randomUUID) | |
;; start a new thread and run a function | |
(.start (Thread. (fn [] (loop [] | |
(do | |
(update-mock-data!) |
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-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] | |
(try | |
(apply date-time (map #(Integer/parseInt %) args)) | |
(catch RuntimeException e nil))) |
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
(import '(java.net InetAddress | |
InetSocketAddress | |
DatagramPacket | |
DatagramSocket)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; networking | |
(defrecord UDPServer [dgram-socket connected closed]) |
NewerOlder