Skip to content

Instantly share code, notes, and snippets.

David Liman dvliman

Block or report user

Report or block dvliman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dvliman
dvliman / gist:921ca48137d134e0152d494d9aa54c73
Created Nov 14, 2019 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second
View gist:921ca48137d134e0152d494d9aa54c73

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

View dummy.go
package httplib
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/manyminds/api2go"
View config.fish
set -gx PATH $PATH /usr/local/sbin
set -gx GOPATH $HOME/go
set -gx GOBIN $GOPATH/bin
set -gx PATH $PATH $GOBIN
set -gx GOOGLE_APPLICATION_CREDENTIALS /Users/dliman/lereta/acq-plt/app-credentials.json
set -gx GOGOOGLE_APPLICATION_CREDENTIALS /Users/dliman/lereta/acq-plt/app-credentials.json
set -gx APP_ENV local
set -gx PROJECT_ID ltf-eng-dliman-cb8b
function set_psql
View rename-files
# rename files to have underscores instead of ' ', '(', and ')' - runs on * or takes extension argument: i.e., `rename_filename_chars txt`
rename_filename_chars() { for file in *"$1"; do mv -n "$file" $(echo $file | sed -e "s/ /_/g" | sed -e "s/(/_/g" | sed -e "s/)/_/g"); done }
View .spacemacs
;; -*- mode: emacs-lisp -*-
(defun dotspacemacs/layers ()
(setq-default
dotspacemacs-distribution 'spacemacs
dotspacemacs-enable-lazy-installation 'unused
dotspacemacs-ask-for-lazy-installation t
;; If non-nil layers with lazy install support are lazy installed.
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (i.e. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '()
View DiffieHellman.java
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator keygen = KeyPairGenerator.getInstance("ECDH", "BC");
keygen.initialize(ECNamedCurveTable.getParameterSpec("P-256"), new SecureRandom());
KeyPair keypair1 = keygen.generateKeyPair();
KeyPair keypair2 = keygen.generateKeyPair();
String secret1 = computeSecret((ECPrivateKey) keypair1.getPrivate(), (ECPublicKey) keypair2.getPublic());
String secret2 = computeSecret((ECPrivateKey) keypair2.getPrivate(), (ECPublicKey) keypair1.getPublic());
@dvliman
dvliman / gist:372de58943f2534fafe9803bc8fb8893
Created Jun 12, 2019 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.
View gist:372de58943f2534fafe9803bc8fb8893

Client-side SSL

For excessively paranoid client authentication.


Updated Apr 5 2019:

because this is a gist from 2011 that people stumble into and maybe you should AES instead of 3DES in the year of our lord 2019.

some other notes:

@dvliman
dvliman / _reader-macros.md
Created Jun 10, 2019 — forked from chaitanyagupta/_reader-macros.md
Reader Macros in Common Lisp
View _reader-macros.md

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

View package.el
(defun spacemacs/go-run-directory ()
(interactive)
(shell-command
(format "go run %s" (concat (file-name-directory (buffer-file-name)) "*.go"))))
You can’t perform that action at this time.