Skip to content

Instantly share code, notes, and snippets.

Avatar

Shen Tian shen-tian

View GitHub Profile
@shen-tian
shen-tian / firebase_push_id.cljs
Created November 20, 2019 10:23
Firebase Push ID, in Clojurescript
View firebase_push_id.cljs
(def firebase-push-id!
(let [last-push-time (atom nil)
saved-random (atom nil)]
(fn firebase-push-id-inner
([] (firebase-push-id-inner nil))
([millis]
(locking last-push-time
(let [push-chars "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
now (or millis (.getTime (js/Date.)))
duplicate? (= now @last-push-time)