Skip to content

Instantly share code, notes, and snippets.

View christianromney's full-sized avatar
🏠
Working from home

Christian Romney christianromney

🏠
Working from home
View GitHub Profile
(ns switch
(:require [clojure.pprint :as pprint]))
(defn project-clj-map [filename]
(->> (slurp filename)
(read-string)
(drop 1)
(partition 2)
(map vec)
(into {})))
require "continuation"
$breadcrumbs = []
def current_continuation
callcc { |cc| cc }
end
def fail!
raise "No more breadcrumbs to follow" if $breadcrumbs.empty?
require './amb.rb'
$reported = false
def report(a, b)
puts "a: #{a}, b: #{b}"
unless $reported
puts "Press any key to continue..."
gets
$reported = true
@christianromney
christianromney / http_streaming.md
Created September 29, 2017 18:55 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@christianromney
christianromney / factorial.scm
Last active September 28, 2017 22:12
Factorial 3 ways
;; factorial (recursive)
(define fact
(lambda (n)
(if (= n 0)
1
(* n (fact (- n 1))))))
(display (fact 5)) ;; => 120
(newline)
@christianromney
christianromney / edn.cljx
Created August 24, 2017 19:19 — forked from Deraen/edn.cljx
Transit / edn date/datetime serialisers
(ns metosin.common.edn
#+clj
(:require [clj-time.format :as f])
#+cljs
(:require [cljs-time.format :as f]
cljs.reader)
#+clj (:import [org.joda.time DateTime LocalDate]))
;;
;; #DateTime tagging
;; This buffer is for Clojure experiments and evaluation.
;; Press C-j to evaluate the last expression.
(fn trapezoid [v]
(let [row (fn [v]
(-> (vector (first v))
(into (map #(reduce +' %) (partition 2 1 v)))
(conj (last v))))]
(lazy-seq (cons v (trapezoid (row v))))))
@christianromney
christianromney / core.clj
Last active November 30, 2016 16:19
A handy little Clojure utility function to print the members of an object.
(defn inspect
"Reflects the members of an object and prints them. Returns the
number of members on the object. Constructors are labeled
with [ctor], public members are prefixed with +, private members are
prefixed with -, and static members are listed as Class/member.
Fields are annotated as fieldName : type, functions have a parameter
list enclosed in parentheses (param1, param2) followed by an arrow
-> and the return type. Varargs have an elipsis following the last
param (params...)."
[x]
(defmacro <!?
"Exception-aware parking take. If a Throwable is returned
from the channel, it is re-thrown."
[c]
`(let [v# (<! ~c)]
(if (instance? Throwable v#)
(throw v#)
v#)))
(defmacro <!!?
(deftask overwrite
[f file VAL str "The path of the file to overwrite"
w with VAL str "The file containing the source content"]
(with-pre-wrap fs
(let [{:keys [file with]} *opts*
src-file (tmp-get fs with)
out-file (tmp-get fs file)]
(-> fs
(cp (tmp-file src-file) out-file)
commit!))))