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 / config-gist.java
Last active August 29, 2015 13:55
lock-free config file
package com.github.nha;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Configuration<K, V> {
private Map<K, V> map;
public Configuration() {
@nha
nha / Keybase proof
Created February 27, 2014 22:55
Keybase proof
### Keybase proof
I hereby claim:
* I am nha on github.
* I am nha (https://keybase.io/nha) on keybase.
* I have a public key whose fingerprint is 7C65 1064 0EAC 25F8 1586 9E0E 59C5 150B 84CD 9FA4
To claim this, I am signing this object:
@nha
nha / Datomic News Updates
Created November 10, 2015 14:34 — forked from stuarthalloway/Datomic News Updates
Datomic update examples against a social news database
;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
@nha
nha / main.clj
Created January 25, 2016 20:28 — forked from fogus/main.clj
Cassowary constraint solver in ClojureScript
;;Using the Cassowary constraint solver from ClojureScript
;;This demo shows using multimethods for readable constraint syntax using +, -, and =.
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform.
(ns c2.main
;;refer-clojure :exclude is currently broken in ClojureScript master
;;Ticket open: http://dev.clojure.org/jira/browse/CLJS-114
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude
(:refer-clojure :exclude [+ - =])
@nha
nha / Nil Finder
Created January 27, 2016 08:42 — forked from stuarthalloway/Nil Finder
Finding those nested nils
(ns user)
(def app
"Intenal Helper"
(fnil conj []))
(defprotocol PathSeq
(path-seq* [form path] "Helper for path-seq"))
(extend-protocol PathSeq
@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))]
@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]
;; 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 / 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();
(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)))