Skip to content

Instantly share code, notes, and snippets.

@digitaldreamer
digitaldreamer / query.sql
Created July 30, 2020 15:16 — forked from prestonp/query.sql
postgres update return new values and old values
-- returning updated values and old values by using a sub-expression
update orders
set type = 'delivery'
where id = 3767
returning id, type, (
select type from orders where id = 3767
) as old_type;
@digitaldreamer
digitaldreamer / looper.go
Last active February 25, 2020 20:44
benchmarking looping arrays in go
/*
Summary
As expected, the time increase to loop an array is linear.
If we consider anything under 1ms as unnoticable then everything up to around 1 mil is realtively safe
depending on the work that you're doing.
The run times of 100 mil and larger have a lot of variance because of the low iteration counts so the overall
runtime is unreliable (i.e. too much of the run is taken up by allocating the array), but their runtimes
@digitaldreamer
digitaldreamer / grandcentral.md
Created October 25, 2019 06:50
Grand Central documentation

GrandCentral Distributed Messaging

Grand Central is the messaging service that will distribute information between the applications.

The central concept revolves around Topics and Channels to support pubsub Event distribution.

Glossary

  • Topic - is a unique identifier for an Event stream. Publishers POST an event to a topic.
@digitaldreamer
digitaldreamer / workerpool.go
Created August 30, 2019 21:38
Worker Pool example
package main
import (
"fmt"
"log"
"math/rand"
"sync"
"time"
)
@digitaldreamer
digitaldreamer / binder.go
Last active September 16, 2019 18:02
New Binder Pattern
// We would make a seaprate {service}/data package. The reason to separate out the data module is to utilize
// private methods to not expose lower-level resources
// We would no longer need the big global Databinder and instead replace it with a smaller Binder for each resource
// The benifit of switching off of the interface is we can then leverage private attributes like the clients
// The Binders can expose sqlx components like tx in private functions
// The binder methods would be raw management of the resources with no side-effects (i.e. creating a guest
// would not create a guest token)
type GuestBinder struct {
@digitaldreamer
digitaldreamer / homebrew-install-older-version.md
Created October 17, 2018 20:36
Homebrew: Install an older version of a formula

Homebrew: Install an older version of a formula

kubernetes-cli (v1.10.3) taken as example

  1. Downgrade Homebrew to the commit which upgrades the formula to the specific version that we want
$ cd "$(brew --repo homebrew/core)"
$ git log Formula/kubernetes-cli.rb

...
@digitaldreamer
digitaldreamer / graceful.go
Created August 30, 2018 19:50 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
@digitaldreamer
digitaldreamer / wait
Last active May 8, 2018 18:58
circle wait for db
#!/usr/bin/env bash
TIMEOUT=5
until psql -h $PG_HOST -U $PG_USER -d $PG_DATABASE -c "select 1" > /dev/null 2>&1 || [ $TIMEOUT -eq 0 ]; do
echo "Waiting for postgres server, $((TIMEOUT--)) remaining attempts..."
sleep 1
done
@digitaldreamer
digitaldreamer / 1_kubernetes_on_macOS.md
Created May 2, 2018 20:35 — forked from kevin-smets/1_kubernetes_on_macOS.md
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

target, _ := url.Parse(h.ProxyHost)
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.ServeHTTP(w, r)