Skip to content

Instantly share code, notes, and snippets.

View jimrthy's full-sized avatar

James Gatannah jimrthy

View GitHub Profile
@jimrthy
jimrthy / indirect_spec_gen.clj
Last active February 28, 2018 05:32
clojure.spec gen oddities
(ns indirect-spec-gen
(:require [clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.test :refer (deftest is)]))
(def extension-length 16)
;; Need a byte array with 16 members
(s/def ::extension (s/and bytes?
#(= (count %) extension-length)))
;; Need to track one for the client, another for the server
@jimrthy
jimrthy / block-stack-verify.txt
Last active November 16, 2017 15:33
Verifying my Blockstack ID is secured with the address 153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo https://explorer.blockstack.org/address/153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo
Verifying my Blockstack ID is secured with the address 153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo https://explorer.blockstack.org/address/153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo
@jimrthy
jimrthy / sample-comms-protocol.clj
Created December 30, 2016 05:55
Example of a network handshake protocol
(defn version-contract
"Declaration of the handshake to allow client and server to agree on handling the next pieces"
[]
[{::direction ::client->server
::initial-step true
::spec #(= % ::ohai)
::client-gen (fn [_] ::ohai)
::problem "Illegal greeting"}
{::direction ::server->client
::spec (s/and keyword? #(= % ::orly?))
@jimrthy
jimrthy / sente-fnhouse-handlers.clj
Created August 17, 2015 04:32
Sample of translating sente web socket upgrade request handlers into fnhouse routes
(defnk $chsk$GET
{:responses {200 {:what? s/Int}}}
;; Note the way to just access the full request
[request
[:resources [:web-sock-handler ch-sock]]]
(let [handler (:ring-ajax-get-or-ws-handshake ch-sock)
response (handler request)]
response))
(defnk $chsk$POST