Skip to content

Instantly share code, notes, and snippets.

View nha's full-sized avatar
🐢
https://turtlequeue.com

nha

🐢
https://turtlequeue.com
View GitHub Profile
@nha
nha / edn.cljx
Created November 5, 2017 16:58 — forked from Deraen/edn.cljx
Transit / edn date/datetime serialisers
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging
Verifying that "nha.id" is my Blockstack ID. https://onename.com/nha
@nha
nha / parsehtml.clj
Created October 22, 2017 23:43 — forked from seltzer1717/parsehtml.clj
Converts Bootstrap HTML to ClojureScript Om Code
;; Converts Bootstrap HTML into ClojureScript Om code
;; Formats output as well
;; Useful when you want to mock a Bootstrap layout but then convert to ClojureScript Om code.
(ns com.seltzer1717.term.server.parsehtml
(:import
(java.io
FileReader
FileWriter
BufferedReader
BufferedWriter)
@nha
nha / parsehtml.clj
Created October 22, 2017 23:43 — forked from seltzer1717/parsehtml.clj
Converts Bootstrap HTML to ClojureScript Om Code
;; Converts Bootstrap HTML into ClojureScript Om code
;; Formats output as well
;; Useful when you want to mock a Bootstrap layout but then convert to ClojureScript Om code.
(ns com.seltzer1717.term.server.parsehtml
(:import
(java.io
FileReader
FileWriter
BufferedReader
BufferedWriter)
@nha
nha / externs_for_cljs.clj
Created November 9, 2016 23:17 — forked from Chouser/externs_for_cljs.clj
Generate an externs.js file for arbitrary JS libraries for use in advanced Google Closure compilation, based on the ClojureScript code that uses the libraries.
(ns n01se.externs-for-cljs
(:require [clojure.java.io :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
(ns carder-devcards.map
(:require [taoensso.timbre :as timbre]
[cljsjs.react-leaflet] ;; js/ReactLeaflet
)
(:require-macros [devcards.core :as dc :refer [defcard defcard-doc defcard-om-next noframe-doc deftest dom-node]]))
(defn build
([component props]
(build component props (array)))
@nha
nha / event-loop-nashorn.js
Created May 14, 2016 00:24 — forked from bripkens/event-loop-nashorn.js
Java 8 Nashorn event loop "polyfill". javax.script.ScriptEngine#eval calls should immediately call window.main to enter the event loop and thus to avoid concurrency issues. The XMLHttpRequest simulation is not yet finished.
(function(context) {
'use strict';
var Timer = Java.type('java.util.Timer');
var Phaser = Java.type('java.util.concurrent.Phaser');
var TimeUnit = Java.type('java.util.concurrent.TimeUnit');
var AsyncHttpClient = Java.type('com.ning.http.client.AsyncHttpClient');
var timer = new Timer('jsEventLoop', false);
var phaser = new Phaser();
;; MUST be possible
;; http://funcool.github.io/cats/latest/#alet
;; https://gist.github.com/aclemmensen/11272381
;; http://www.lispcast.com/core-async-browser-motivation
;; https://gist.github.com/aclemmensen/11272381
(defn sample-async-fn [t s]
(println "sample-async-fn" t s js/Date.)
(go (<! (timeout t))
@nha
nha / free-port.clj
Created February 5, 2016 08:40 — forked from ptaoussanis/free-port.clj
A little utility to allow simple redeployment of Clojure web servers with zero downtime, and without the need for a proxy or load balancer. Just wrap any port-binding calls, and the utility will auto kill pre-existing servers as necessary. *nix only. Based on the blog post by Feng Shen, http://shenfeng.me/fast-restart-clojure-webapp.html
;; (require '[clojure.string :as str] '[clojure.java.shell :as shell] '[taoensso.timbre :as timbre])
(defn with-free-port!
"Attempts to kill any current port-binding process, then repeatedly executes
nullary `bind-port!-fn` (which must return logical true on successful
binding). Returns the function's result when successful, else throws an
exception. *nix only.
This idea courtesy of Feng Shen, Ref. http://goo.gl/kEolu."
[port bind-port!-fn & {:keys [max-attempts sleep-ms]
@nha
nha / datascript_utils.cljs
Created January 27, 2016 13:13 — forked from narma/datascript_utils.cljs
Convert json dump or just regular data to seq for `d/transact!`
(ns datascript-utils
(:require [datascript :as d]))
(defn data->datoms [prefix json]
(let [make-prefix
(fn [p]
(let [[full short]
(re-matches #"(.+?)s?$" p)]
short))]