Skip to content

Instantly share code, notes, and snippets.

View zcaudate's full-sized avatar

Chris Zheng zcaudate

View GitHub Profile
@zcaudate
zcaudate / code.clj
Created June 29, 2012 22:03
html->hiccup
(use 'net.cgrand.enlive-html)
(import 'java.io.StringReader)
(defn enlive->hiccup
[el]
(if-not (string? el)
(->> (map enlive->hiccup (:content el))
(concat [(:tag el) (:attrs el)])
(keep identity)
vec)
@zcaudate
zcaudate / code.clj
Created June 29, 2012 22:04
clean-ns
(defn clean-ns [ns]
(let [vs (keys (ns-interns ns))]
(doseq [v vs] (ns-unmap ns v))
vs))
@zcaudate
zcaudate / code.clj
Created June 29, 2012 22:06
do-until
(defmacro do-until [& clauses]
(when clauses
(list
`when (first clauses)
(if (next clauses)
(second clauses)
(throw (IllegalArgumentException.
"do-until requires an even number of forms")))
(cons 'do-until (nnext clauses)))))
@zcaudate
zcaudate / code.clj
Created June 29, 2012 22:35
basic ring server
(use 'ring.adapter.jetty)
(defn naked-handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body (str request})
(def app #'naked-handler)
(defonce server (run-jetty #'app {:port 8080 :join? false}))
@zcaudate
zcaudate / gist:9609112
Created March 17, 2014 21:48
karma-test.js
var CLOSURE_NO_DEPS = true;
var COMPILED = false;
var goog = goog || {};
goog.global = this;
goog.DEBUG = true;
goog.LOCALE = "en";
goog.TRUSTED_SITE = true;
goog.provide = function(name) {
if (!COMPILED) {
if (goog.isProvided_(name)) {
(def db (connect host port
{:schema {"app" ^{:strategy_class "NetworkTopologyStrategy"
:strategy_options {"dc1" 3, "dc2" : 2}}
{"Users" {"name" ^{:index_type :key
:index_name "user_name_idx"}
[:utf-8]
"age" [:long]}}}})))
(ns hara.concurrent.workflow
(:require [hara.common.checks :refer [hash-map? promise?]]
[hara.common.primitives :refer [uuid]]
[hara.data.nested :refer [merge-nil-nested]]
[clojure.set :as set]))
(defn create-registry []
(atom {:tickets {}
:tasks {}
:active #{}
@zcaudate
zcaudate / stats.py
Created February 14, 2015 02:50
usage statistics for clojars
(import [bs4 [BeautifulSoup]]
[operator [itemgetter]]
requests)
(defn project-links [username]
(let [[url (+ "https://clojars.org/users/" username)]
[res (requests.get url)]
[soup (BeautifulSoup res.text)]
[links (-> (soup.find "h1")
(.find-next "h1")
@zcaudate
zcaudate / count.clj
Created August 6, 2015 10:41
generative testing
(defn count-elements [coll1 coll2]
(+ (count coll1) (count coll2) 1))
(defn count-elements-tester [f]
(let [n (rand-int 6)
m (rand-int 6)
output (+ n m)
inputs [(range n) (range m)]
actual (apply f inputs)]
(if (= actual output)
@zcaudate
zcaudate / speed_test.clj
Created February 20, 2017 21:23
record vs map
(defrecord Simple [value])
(deftype Basic [value])
(with-out-str
(time
(dotimes [i 100000000]
(set! (Basic. i) :value (* 2 i)))))