Skip to content

Instantly share code, notes, and snippets.

View dvliman's full-sized avatar

David Liman dvliman

View GitHub Profile
@dvliman
dvliman / auth-middleware.clj
Created July 22, 2020 17:41
buddy auth access rules snippet
;; File: src/some_app/middleware.clj
(defn open-gates [request]
true)
(def rules [{:pattern #"^/admin.*"
:handler admin-access
:redirect "/notauthorized"},
{:pattern #"^\/vclass.*"
:handler user-access
:redirect "/notauthorized"},
{:pattern #"^\/api.*"
@dvliman
dvliman / future-utils.clj
Created July 15, 2020 01:28
dpsutton's snippet
(defn ->Function
[f]
(reify java.util.function.Function
(apply [_ obj] (f obj))))
(defn future-map
[cf f]
(.thenApply cf (->Function f)))
(defn future->ch
([cf]
(future->ch cf (async/chan 1) true))
@dvliman
dvliman / cheshire.clj
Created July 11, 2020 03:04
cheshire serialize org.postgresql.geometric PGpoint
(ns plokal.cheshire
(:require [cheshire.generate :refer [add-encoder]]
[cheshire.core :as json])
(:import [com.fasterxml.jackson.core JsonGenerator]
(org.postgresql.geometric PGpoint)))
(add-encoder
PGpoint
(fn [^PGpoint data ^JsonGenerator jsonGenerator]
(.writeString jsonGenerator (json/generate-string {:type :Point
go env
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/dv/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dv/go"
interview-mind-map
@dvliman
dvliman / concurrency-models
Created April 22, 2020 20:08
concurrency-models
concurrency-models

Keybase proof

I hereby claim:

  • I am dvliman on github.
  • I am dvliman (https://keybase.io/dvliman) on keybase.
  • I have a public key ASBe4DkFe9qsB1j_Dc89k_Vd2euOfMD-Qz4FXTtbNRwTtwo

To claim this, I am signing this object:

@dvliman
dvliman / spike-day-02-03-20.md
Created February 9, 2020 20:46 — forked from cldwalker/spike-day-02-03-20.md
GraalVM dive in Clojure at work

Spike

I looked into the state of GraalVM and Clojure and wrote some small work-related scripts.

GraalVM Build Tools

@dvliman
dvliman / gist:921ca48137d134e0152d494d9aa54c73
Created November 14, 2019 18:23 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

package httplib
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/manyminds/api2go"