Skip to content

Instantly share code, notes, and snippets.

@schmir
schmir / .sh
Created January 31, 2019 11:13
show git status on tab key
# When Tab is pressed on an empty(!) command line, the contents of the
# directory are printed (`ls`) instead of a menu list of all
# executables:
function my-hg-report() {
tip=$(hg tip 2> /dev/null) || return
echo
hg --config pager.pager= status
echo
hg --config pager.pager= log --limit 5 --style compact
@schmir
schmir / jdbc_streaming.clj
Created July 5, 2017 12:25
streaming responses in java.jdbc
(ns soka-trb.jdbc-streaming
"streaming results in clojure.java.jdbc, when {:use-streaming? true} is passed
as option
hooks into jdbc/prepare-statements and calls turn-on-streaming
Users need to extend the TurnOnStreaming protocol for their databases
"
(:require [clojure.java.jdbc :as jdbc]
[robert.hooke]))
(deftask dev-repl
"start development repl"
[]
(comp (dev-profile) (repl)))
def find_ip ():
# we get a UDP-socket for the TEST-networks reserved by IANA.
# It is highly unlikely, that there is special routing used
# for these networks, hence the socket later should give us
# the ip address of the default route.
# We're doing multiple tests, to guard against the computer being
# part of a test installation.
candidates = []
for test_ip in ["192.0.2.0", "198.51.100.0", "203.0.113.0"]:
(require '[boot.pod :as pod]
'[boot.tmpdir :as tmpdir]
'[clojure.java.io :as io]
'[clojure.string :as string])
(task-options!
pom {:project 'steinmetz
:version "0.1.0"}
repl {:init-ns 'user}
aot {:namespace #{}}
(defn code-points-from-string
[^String s]
(iterator-seq (.iterator (.codePoints s))))
(defn string-from-code-points
[s]
(let [ia (int-array s)]
(String. ia 0 (count s))))
(defn decode-with-fn
(defn code-points-from-string
[^String s]
(iterator-seq (.iterator (.codePoints s))))
(defn string-from-code-points
[s]
(let [ia (int-array s)]
(String. ia 0 (count s))))
(defn decode
(in-ns 'clojure.core)
;; make reloading namespaces work with proxy!
(defn proxy-name**
{:tag String}
[^Class super interfaces]
(let [inames (into1 (sorted-set) (map #(.getName ^Class %) interfaces))
ihashes (into1 (sorted-set) (map #(System/identityHashCode %) interfaces))]
(apply str (.replace (str *ns*) \- \_) ".proxy"
(interleave (repeat "$")
(ns sandbox.core)
(defprotocol GetUserData
"get user data"
(getUserData [this] "get user data"))
(def d (proxy [Object sandbox.core.GetUserData] []
(getUserData [] 42)))
;; sandbox.core=> (getUserData d)
In [23]: from pyethereum import trie
In [24]: t=trie.Trie("foo2")
In [25]: t.__dict__
Out[25]: {'db': <pyethereum.trie.DB at 0x128a950>, 'debug': False, 'root': ''}
In [26]: t.update("foo", "bar")
In [27]: t.__dict__