Skip to content

Instantly share code, notes, and snippets.

Michał Marczyk michalmarczyk

Block or report user

Report or block michalmarczyk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
samn / lock_less_monster.clj
Last active Dec 18, 2015
The Lock Less Monster
View lock_less_monster.clj
Let's say you have a threadpool doing work that requires access to some shared resource.
And this resource needs to be refreshed at times. E.g. an OAuth bearer token that can expire or be revoked.
If this resource were expensive to refresh, or subject to rate limiting (OAuth tokens are often both)
then it's desirable to refresh as little as possible.
It's undesirable, however, to mix complicated synchronization code for updating the resource in
with the business logic consuming it.
Enter the lock less monster, a lock free method for coordinating updates to a shared reference.
willurd /
Last active Feb 24, 2020
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
w01fe / locals_clearing.clj
Created Mar 5, 2013
A bug in fine-grained locals clearing in Clojure 1.5?
View locals_clearing.clj
(deftype FinalizeReporter [x]
(finalize [this] (println "Finalizing" x))
(deref [this] x))
(defn leaker [n]
(with-open [_ (reify (close [this]))]
(let [s (map #(FinalizeReporter. %) (take 10 (iterate inc 0)))]
(when (> n -1)
hugoduncan / gist:4138017
Created Nov 24, 2012
lb being called on :clojure.core.logic/not-found
View gist:4138017
No implementation of method: :lb of protocol: #'clojure.core.logic/IInterval found for class: clojure.lang.Keyword
0: [CONTINUE] Pass exception to program
1: [ABORT] Abort request.
2: [IGNORE] Do not enter debugger for this exception type
3: [IGNORE-MSG] Do not enter debugger for this exception message
4: [IGNORE-CATCH] Do not enter debugger for exceptions with catch location clojure.lang.LazySeq.*
5: [IGNORE-LOC] Do not enter debugger for exceptions with throw location clojure.core.*
jasonrudolph /
Created Sep 21, 2012
Rough Notes from Strange Loop 2012
frenchy64 / fbound.clj
Created Aug 10, 2012
F-bounded Polymorphism in Typed Clojure
View fbound.clj
; y has upper bound x, z has upper bound (Seqable y)
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]]
[x y z -> Any]))
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))]
typed.core=> (declare foo)
;cf = check-form
typed.core=> (cf (foo 2 2 [2]))
View gist:3217582
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
jboner / latency.txt
Last active Feb 25, 2020
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
View lens.clj
(def users [{:name "Brian" :age 22} {:name "Ben" :age 19}])
;; Takes a "path", returns a function that takes an "object" and
;; returns a "costate"
(defn lens [p]
(fn [o]
{:get (get-in o p)
:set #(assoc-in o p %1)}))
(def myAgeLens (lens [0 :age]))
lambda-fairy / Fold.hs
Created May 27, 2012
Data.List.Fold - fold lists in constant space
View Fold.hs
-- | Lock-step folding.
-- This module presents an elegant way of executing multiple left folds
-- on one list using constant memory. For example, the mean can be
-- expressed as:
-- @
-- average = foldLeft $ (/) <$> sumF <*> lengthF
-- @
You can’t perform that action at this time.