Skip to content

Instantly share code, notes, and snippets.

@jakobii
jakobii / opts.proto
Created May 28, 2021 16:05
Proto3 Optional Scalar Values
message Double {
oneof value {
None none = 1;
double some = 2;
}
}
message Float {
oneof value {
None none = 1;
float some = 2;
@jakobii
jakobii / certs.sh
Last active April 1, 2021 17:36 — forked from mrw34/postgres.sh
Enabling SSL for PostgreSQL in Docker
#!/bin/bash
set -e
sudo rm -f server.req privkey.pem server.key server.crt
# https://www.postgresql.org/docs/11/ssl-tcp.html
openssl req -new -text -passout pass:abcd -subj /CN=localhost -out server.req -keyout privkey.pem
openssl rsa -in privkey.pem -passin pass:abcd -out server.key
openssl req -x509 -in server.req -text -key server.key -out server.crt
chmod og-rwx server.key
@jakobii
jakobii / postgres_ssl.md
Last active March 10, 2020 23:46
Enable ssl connections on postgres 12 on ubuntu 18.04

uuid regex in golang

the straght forward answer

[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}

https://www.cockroachlabs.com/docs/stable/start-a-local-cluster-in-docker-linux.html

create cluster

sudo docker network create -d bridge roachnet
sudo docker run -d --name=roach1 --hostname=roach1 --net=roachnet -p 26257:26257 -p 8080:8080  -v "${PWD}/cockroach-data/roach1:/cockroach/cockroach-data" cockroachdb/cockroach:v19.2.2 start --insecure --join=roach1,roach2,roach3
sudo docker run -d --name=roach2 --hostname=roach2 --net=roachnet -v "${PWD}/cockroach-data/roach2:/cockroach/cockroach-data" cockroachdb/cockroach:v19.2.2 start --insecure --join=roach1,roach2,roach3
sudo docker run -d --name=roach3 --hostname=roach3 --net=roachnet -v "${PWD}/cockroach-data/roach3:/cockroach/cockroach-data" cockroachdb/cockroach:v19.2.2 start --insecure --join=roach1,roach2,roach3
@jakobii
jakobii / run_task_on_remote_servers_in_parallel.ps1
Last active January 7, 2020 20:07
Remote PSSession Tasks
# This is a scriptblock that will be invoked on the remote computer. This is
# just dummy code that gets the computers hostname from the global built in
# eniorment variable $env.
$RemoteTask = {
param(
[datetime]$Start
)
# pause remote script execition until the specified start time.
# you can use this to loosely sync jobs execution.
@jakobii
jakobii / gzip_http_response.go
Last active November 14, 2019 21:15
gzip golang http responses
//https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
func writeOptimizedHttpResponse(w http.ResponseWriter, r *http.Request, b []byte, contentType string) {
w.Header().Set("Content-Type", contentType)
encodings := r.Header.Get("Accept-Encoding")
switch {
case strings.Contains(encodings, "gzip"):
w.Header().Set("Content-Encoding", "gzip")
@jakobii
jakobii / postgres_map_fks.md
Last active November 14, 2019 20:47
Map FKs in Postgres

Table constraints can include multiple columns. The trick to getting this right is to join each column by their constraint ordinal positions. If you don't join correctly your script will blow up with duplicate rows 😥 whenever a table has multiple columns in a unique constraint.

Table Notes

This may be helpful in understanding what these tables do.

information_schema.table_constraints

  • lists all table constraints
  • explains constraint types
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
_ "github.com/denisenkom/go-mssqldb"
)
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"os"