Skip to content

Instantly share code, notes, and snippets.

View branneman's full-sized avatar

Bran van der Meer branneman

View GitHub Profile
@branneman
branneman / git.js
Last active March 23, 2023 13:15
How Git works - super simplified! — https://www.youtube.com/watch?v=T9Nag5IXVQ0
// blob = file contents, identified by hash
const blobs = {
'73d8a': 'import x from "y"; console.log("some file contents")',
'9c6bd': 'D8 A1 31 0F ...',
'547d4': '# Readme\nThis is documentation',
'a0302': '# Readme\nThis is some updated documentation',
}
// tree = references to blobs and trees, identified by hash
const trees = {
@branneman
branneman / unit-testing.js
Last active October 5, 2022 21:03
How I write High Quality Unit tests - https://youtu.be/naL7-XQ7T70
/**
* Returns a list of numbers from `min` (inclusive) to `max` (exclusive).
*/
const range = (min, max, acc = []) => {
if (max < min) throw new Error('not supported!')
if (min >= max) return acc
return range(min + 1, max, acc.concat(min))
}
/**
@branneman
branneman / log.py
Created November 30, 2021 10:55
Python log util, outputting elastic/filebeat compatible json
import json
from datetime import datetime, timezone
LEVELS = {
"emergency": 7,
"alert": 6,
"critical": 5,
"error": 4,
"warning": 3,
"notice": 2,
@branneman
branneman / http-easy.rkt
Last active June 29, 2024 18:58
Racket: How to do HTTP requests
#lang racket/base
(require
net/http-easy)
(define (base-url path)
(string-append "https://httpbin.org" path))
; request: GET
; response: plain string body
@branneman
branneman / 1-web-server.rkt
Last active June 21, 2021 15:05
Racket: Example web-server which renders markdown
#lang racket/base
(provide
server-start)
(require
markdown
net/url
web-server/http
web-server/servlet-env
@branneman
branneman / 0-syntax.rkt
Last active May 24, 2021 13:34
Racket: Macro's
#lang racket/base
(require (for-syntax racket/base))
; Reading Quotes
; see: https://docs.racket-lang.org/reference/reader.html
; ' quote #' syntax
; ` quasiquote #` quasisyntax
; , unquote #, unsyntax
; ,@ unquote-splicing #,@ unsyntax-splicing

Automate backups: Nextcloud to S3

Assumptions

  • Disk space: at least 3× the size of the /var/www/nextcloud directory is available on /var/backups
  • Nextcloud is installed into /var/www/nextcloud as user www-data
  • AWS cli is installed and configured with credentials
  • mysqldump is installed
  • rsync is installed

Setup

@branneman
branneman / radicals.json
Created June 9, 2020 12:37
JSON list of 214 Simplified Chinese Radicals, data contains radical number, pinyin, english translation, stroke count
[
{
"id": 1,
"radical": "",
"pinyin": "",
"english": "one",
"strokeCount": 1
},
{
"id": 2,
(ns main (:gen-class))
;; Snake :: [[int int]…]
;; vector of x,y tuples
;; head is first, tail is last
;; out-of-bounds? :: (int int int) -> bool
;; grid-size is 1-indexed, x+y are 0-indexed
(defn out-of-bounds? [grid-size x y]
(or (neg? x) (neg? y) (>= x grid-size) (>= y grid-size)))

List of all Clojure Predicate functions

A predicate function returns a boolean true or false, and it's name ends with a ?. Ran against Clojure 1.10.0.

({:ns clojure.string,
  :predicates
  ({:fn ends-with?, :arglists ([s substr])}
   {:fn starts-with?, :arglists ([s substr])}
   {:fn includes?, :arglists ([s substr])}