Skip to content

Instantly share code, notes, and snippets.


Ghadi Shayban ghadishayban

View GitHub Profile
ghadishayban / aproto3.ebnf
Last active Aug 7, 2020
instaparse is a super power
View aproto3.ebnf
proto = <syntax> { import | package | option | message | enum | service | emptyStatement } <ws>
(* Header *)
syntax = ws "syntax" ws "=" ws ( "'proto3'" | '"proto3"' ) ws ";"
import = <ws "import" ws> [ "weak" | "public" ] <ws> strLit <ws ";">
package = <ws "package" ws> fullIdent <ws ";">
option = <ws "option" ws> optionName <ws "=" ws > constant <ws ";">
ghadishayban / retry.clj
Last active May 1, 2019
retry with completablefuture
View retry.clj
(ns retry
(:import [java.util.function Supplier]
[java.util.concurrent CompletableFuture TimeUnit]))
(defn with-retry
"given an op wanting retries, and a strategy for backoff,
returns a CompletableFuture that can be waited on
op takes no args
A backoff strategy is a function of an exception, returning nil or a number of milliseconds to backoff"
View functional_interfaces.clj
(import '[java.lang.reflect Method Modifier])
(set! *warn-on-reflection* true)
(defn- samsig
"Given a SAM interface, returns the j.l.reflect.Method of the abstract method"
(let [kls (resolve sym)]
(if (and (class? kls) (.isInterface ^Class kls))
(let [mid (fn [^Method m] [(.getName m) (vec (.getParameterTypes m))])
ghadishayban /
Created Feb 12, 2018
a script that vendors asm and writes itself as git commit 'transaction data'
# author Ghadi Shayban <>
set -e
if [ -z ${1+x} ]
echo provide an asm git sha / ref
exit 1

Keybase proof

I hereby claim:

  • I am ghadishayban on github.
  • I am ghadi ( on keybase.
  • I have a public key ASBXbzSnNB9Tcf5AU7PXtLsWEiBhS8jeuA3ZQe9kHQHN0Qo

To claim this, I am signing this object:

ghadishayban / fuse.clj
Last active Jan 26, 2019
"stream fusion" example using transducers
View fuse.clj
;; lots of garbage
(->> coll ;; original collection
(map #(assoc % :foo :bar)) ;; intermediate Chunked collection 1
(filter :baz) ;; intermediate Chunked collection 2
(map :feature) ;; intermediate Chunked collection 3
(into [])) ;; reduction using #'conj over Chunked collection #3
;; -- direct reduction using transducers --
ghadishayban / sawtooth_signing.clj
Created Jul 19, 2017
sawtooth / bitcoin compact signature generation
View sawtooth_signing.clj
(ns sawtooth-signing
(:import org.bitcoinj.core.ECKey
(def ^{:doc "generates an in-memory priv key representation from the .wif"}
(let [MAINNET (MainNetParams/get)]
View map-templates.diff
diff --git a/src/jvm/clojure/lang/ b/src/jvm/clojure/lang/
index 6eb04ee8..7b163bf3 100644
--- a/src/jvm/clojure/lang/
+++ b/src/jvm/clojure/lang/
@@ -1,56 +1,113 @@
package clojure.lang;
import java.util.Arrays;
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
ghadishayban / clojure 1.8 bytecode
Last active Apr 29, 2017
clojure "map template" using invokedynamic
View clojure 1.8 bytecode
public static java.lang.Object invokeStatic(java.lang.Object, java.lang.Object, java.lang.Object);
0: bipush 10
2: anewarray #13 // class java/lang/Object
5: dup
6: iconst_0
7: getstatic #17 // Field const__0:Lclojure/lang/Keyword;
10: aastore
11: dup
12: iconst_1
View generators.clj
;; differences from scheme unfold
;; even initial value is lazy
;; predicate sense reversed
;; internal state == produced value, no special mapper-fn
;; no tail-gen
(defn series
"Produces a sequence of values.
`f` is a function that given a value, returns the next value.
`continue?` is a predicate that determines whether to produce