Skip to content

Instantly share code, notes, and snippets.

Avatar

James Gatannah jimrthy

View GitHub Profile
@jimrthy
jimrthy / indirect_spec_gen.clj
Last active Feb 28, 2018
clojure.spec gen oddities
View indirect_spec_gen.clj
(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 Nov 16, 2017
Verifying my Blockstack ID is secured with the address 153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo https://explorer.blockstack.org/address/153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo
View block-stack-verify.txt
Verifying my Blockstack ID is secured with the address 153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo https://explorer.blockstack.org/address/153ChCc5kEhHGgJ6YB7FSPTPAx8rfJneUo
@jimrthy
jimrthy / sample-comms-protocol.clj
Created Dec 30, 2016
Example of a network handshake protocol
View sample-comms-protocol.clj
(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 Aug 17, 2015
Sample of translating sente web socket upgrade request handlers into fnhouse routes
View sente-fnhouse-handlers.clj
(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