Skip to content

Instantly share code, notes, and snippets.

View vyzo's full-sized avatar

vyzo vyzo

  • Internet
  • Planet Earth
View GitHub Profile
vyzo@carbon go-libp2p-kad-dht $ go test -v -run TestConcurrentRequests -timeout 1m
=== RUN TestConcurrentRequests
panic: test timed out after 1m0s
goroutine 179 [running]:
testing.startAlarm.func1()
/usr/lib64/go/src/testing/testing.go:1145 +0xf9
created by time.goFunc
/usr/lib64/go/src/time/sleep.go:170 +0x44
@vyzo
vyzo / dump-stack-trace.ss
Last active January 8, 2018 12:50
dumping exception stack traces with dump-stack-trace! and an exception handler
(with-exception-handler
(let (E (current-exception-handler))
(lambda (exn)
(continuation-capture
(lambda (cont)
(dump-stack-trace! cont exn)
(E exn)))))
(lambda () do-stuff-that-raises))
@vyzo
vyzo / gist:e3c9c13cbe4b72c148ce1149a0014077
Created January 15, 2018 17:00
generic-cache-lookup
;; The cache is a perfect hash table represented as a vector containing
;; cache entries. A cache entry is an inverted arg type id improper list
;; terminating to the the method procedure.
;; This allows for lock-free allocation-free recursive lookup
;; and reasonably fast dispatch
(def (generic-cache-lookup cache args)
(def (lookup hash rest)
(match rest
([arg . rest]
@vyzo
vyzo / gist:574775c026cc9f4e7f3dcf8f6f8be1e9
Last active January 26, 2018 18:55
negative phase imports
$ cat for-syntax.ss
(import (phi: -1 :tmp/for-template))
(displayln "for-syntax")
$ cat for-template.ss
(displayln "for-template")
$ cat program.ss
(import (phi: +1 :tmp/for-syntax))
(defsyntax (let-hash stx)
(syntax-case stx ()
((macro expr body ...)
(with-syntax ((@ref (stx-identifier #'macro '%%ref)))
#'(let (hash expr)
(let-syntax
((var-ref
(syntax-rules ()
((_ id) (@ref id)))))
(let-syntax
@vyzo
vyzo / still-objects.scm
Created February 2, 2018 11:21
still object accounting
(c-declare #<<END-C
// these are defined in gambit/lib/mem.c
#define ___PSTATE_MEM(var) ___ps->mem.var
#define still_objs ___PSTATE_MEM(still_objs_)
#define ___STILL_LINK_OFS 0
#define ___STILL_REFCOUNT_OFS 1
#define ___STILL_BODY_OFS 6
#define ___STILL_HAND_OFS ___STILL_BODY_OFS
END-C
)
(def (get-caller cont)
(let lp ((cont cont))
(and cont
(or (##continuation-creator cont)
(lp (##continuation-next-frame cont #f))))))
(def (log/caller fmt . args)
(continuation-capture
(lambda (cont)
(let (caller (get-caller cont))
@vyzo
vyzo / rgraph.ss
Created February 24, 2018 12:04
some code to check the gossipsub overlay construction algorithm for connectivity
;; -*- Gerbil -*-
(import :gerbil/gambit/random
:std/misc/shuffle
(only-in :std/srfi/1 take))
(export (struct-out node)
node-degree
node-graft!
node-prune!
make-graph
@vyzo
vyzo / rendezvous.proto
Last active March 12, 2018 10:27
Rendezvous protocol
message Message {
enum MessageType {
REGISTER = 0;
UNREGISTER = 1;
RENDEZVOUS = 2;
DISCOVER = 3;
}
message Peer {
optional string id = 1;
@vyzo
vyzo / optimize-match.ss
Created March 17, 2018 12:32
some match optimization test patterns
(export #t)
(defstruct A (x))
(defstruct (B A) (y) final: #t)
(defstruct C (e))
(def (foo0 obj)
(match obj
([x] x)
([x y] y)