Skip to content

Instantly share code, notes, and snippets.

View snorremd's full-sized avatar

Snorre Magnus Davøen snorremd

View GitHub Profile
@snorremd
snorremd / broadcast.go
Last active October 21, 2023 17:32
Go Broadcast solution
// Make it extend sync to handle multiple go routines
type Broadcaster struct {
sync.Mutex
clients map[string]chan models.CreatePostEvent
}
// Constructor
func NewBroadcaster() *Broadcaster {
return &Broadcaster{
clients: make(map[string]chan models.CreatePostEvent),
@snorremd
snorremd / db.clj
Created April 24, 2021 14:53
Clojure next.jdbc protocols for type/value conversion
;; Documents how to handle time and interval postgres types with next.jdbc library
;; See more docs here: https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.1.646/doc/getting-started/result-set-builders
(ns yourapp.db
(:require [next.jdbc.result-set :as rs]
[next.jdbc.prepare :as p]
[next.jdbc.date-time :refer [read-as-local]]
[tick.core :as tick])
(:import [org.postgresql.util PGInterval]
[java.sql PreparedStatement]))
(-> (zip/zipper vector?
seq
(fn [_ children] children)
[])
(zip/append-child 1)
(zip/append-child 2))
@snorremd
snorremd / passphrase.clj
Last active June 19, 2020 18:19
Passphrase in babashka using /dev/urandom and /usr/share/dict/words
#!/usr/bin/env bb
(defn random-bytes
[n]
(with-open [in (io/input-stream (io/file "/dev/urandom"))]
(let [buf (byte-array n)]
(.read in buf)
buf)))
(defn random-number
@snorremd
snorremd / ghost-to-md.clj
Created May 6, 2020 21:43
Takes a ghost export file on stdin. Writes markdown files with headers in ./
#!/usr/bin/env bb
(def md-head-template
"---
path: \"/blog/%s\"
date: \"%s\"
title: \"%s\"
---
")
@snorremd
snorremd / Dockerfile
Last active April 21, 2019 11:29
Clojure tools.deps multi-stage Dockerfile setup to compile Clojure code inside Dockerfile
FROM clojure:openjdk-11-tools-deps-1.10.0.442 as builder
WORKDIR /app
# Install deps
COPY ./deps.edn ./
RUN clojure -Abuild -e "(clojure-version)"
# Compile Clojure code
ADD . /app
@snorremd
snorremd / cljpg.sh
Last active February 25, 2019 15:18
Script to grab credentials from gpg encrypted file and run clj with them
#!/usr/bin/env bash
# cljgp is a script for decrypting a credentials file with environment
# variables and set them on the clj process. Combine this with the
# ~/.m2/settings.xml file and tell maven to use your environment vars:
# https://maven.apache.org/settings.html.
#
# Credentials file should contain:
# MY_USER=someuser
# MY_PASS=somepass

Keybase proof

I hereby claim:

  • I am snorremd on github.
  • I am snorremd (https://keybase.io/snorremd) on keybase.
  • I have a public key ASD_4XYCom9uHTi1LegqEqSMDqO0PKkdi_pI6Siy4OZwFgo

To claim this, I am signing this object:

# notify-desktop shit
notify() {
osascript -e "display notification \"$2\" with title \"$1\""
}
alias display-notification=notify
var webdriverio = require('webdriverio'),
moment = require('moment');
var options = {
desiredCapabilities: {
browserName: 'firefox'
}
};
var password = process.env.FACEBOOK_PASSWORD,
email = process.env.FACEBOOK_EMAIL,