Skip to content

Instantly share code, notes, and snippets.

@quii
quii / contract_test.clj
Last active April 14, 2023 11:12
Clojure contracts
(ns tdd-clojure.contract-test
(:require [clojure.string :as str]
[clojure.test :refer :all]))
(defn test-greet-contract [greet-fn]
(testing "greet function should return a greeting with the given name"
(let [name "Chris"]
(is (= (greet-fn name) (str "Hello, " name))))))
;; Example implementation of the greet function
@quii
quii / blah.md
Last active August 9, 2022 15:14
Learn Go with Tests: Intro to acceptance tests

Learn Go with Tests: Intro to acceptance tests

We've been running into the need to have "graceful shutdown" for our services.

Graceful shutdown is making sure your system finishes its work properly before it is terminated. A real-world analogy would be someone trying to wrap-up a phone call properly before moving on to the next meeting, rather than just hanging-up mid-sentence.

This post will give an intro to graceful shutdown in the context of a HTTP server, and how to write "acceptance tests" to give yourself confidence in the behaviour of your code.

After reading this you'll know how to share packages with excellent tests, reduce maintenance efforts and, increase confidence in the quality of your work.

@quii
quii / arrange_the_furniture.md
Last active February 14, 2022 16:54
Furniture arranging checklist

Refactoring step, starting checklist

Refactoring (or as i often annoyingly call it, "Furniture arranging") is a skill that once practiced enough, becomes second-nature, and in a lot of cases, very easy.

It often gets conflated with design, but they are separate activities.

Refactoring vs Design

Refactoring is just improving existing code and not changing behaviour, and it's usually very localised changes; tests shouldn't have to change. A lot of very helpful refactorings are simple to learn, easy to do (many are almost entirely automated by your IDE) but over time become hugely impactful to the quality of our system.

@quii
quii / generics.go
Created December 15, 2021 17:00
learning afternoon code
package main
import "fmt"
func main() {
someNumbers := []int64{1, 2, 3}
someNames := []string{"John", "Chris", "Mary"}
fmt.Println(Reduce(someNumbers, 0, func(a, b int64) int64 {
return a + b

Words are important

Chris James 15 Jul 2020 https://quii.dev

"Mocking"

People say

@quii
quii / oops_test.go
Last active May 13, 2020 10:24
Why does this test pass huh?
package learn_go_with_tests
import (
"fmt"
"testing"
)
func Add(x, y int) int {
return 3
}
@quii
quii / es.md
Created March 16, 2020 09:03
es

Aggregates

Let's say I have a funds index with 2 documents like this

{
  "fundId": 123,
  "fundManager": {
    "id": 123434,
 "name": "Chris Inc"
@quii
quii / stitcher_test.go
Created February 14, 2020 11:47
stitcher tests
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
@quii
quii / stitcher.go
Created February 14, 2020 11:34
concurrent stitcher
func Stitcher(w http.ResponseWriter, r *http.Request) {
urls := r.URL.Query()["url"]
if len(urls) == 0 {
http.Error(w, "please provide a url querystring value", http.StatusBadRequest)
return
}
bodies := make(chan io.ReadCloser, len(urls))
@quii
quii / stitcher.go
Created February 14, 2020 11:29
stitcher
func Stitcher(w http.ResponseWriter, r *http.Request) {
urls := r.URL.Query()["url"]
if len(urls) == 0 {
http.Error(w, "please provide a url querystring value", http.StatusBadRequest)
return
}
for _, url := range urls {
res, _ := http.Get(url)