Skip to content

Instantly share code, notes, and snippets.

View sanderploegsma's full-sized avatar

Sander Ploegsma sanderploegsma

View GitHub Profile
@sanderploegsma
sanderploegsma / .gitconfig
Created December 8, 2017 14:25
Global git aliases
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
st = status
co = checkout
cm = commit
cp = cherry-pick
cl = !sh -c \"git branch --merged master | grep -v -e 'master' -e '\\*' | xargs -n 1 git branch -d && git remote prune origin\"
up = !sh -c \"git push && git push --tags\"
br = branch
// waitUntilQueueEmpty subscribes on the queue and returns when no messages arrive for more than 5 seconds
// all received messages are not acknowledged in order to return them to the queue so that workers can process them
func (m *master) waitUntilQueueEmpty(ctx context.Context, sub *pubsub.Subscription) error {
// Use cancellable context for the subscription
ctx, cancelSubscribe := context.WithCancel(ctx)
messageReceived := make(chan bool)
go func() {
// keep checking if we received a message in the last 5 seconds
// if not, cancel the subscription
for {
// waitUntilQueueEmpty subscribes on the queue and returns when no messages arrive for more than 5 seconds
// all received messages are not acknowledged in order to return them to the queue so that workers can process them
func (m *master) waitUntilQueueEmpty(ctx context.Context, sub *pubsub.Subscription) error {
var mu sync.Mutex
lastMessageTimestamp := time.Now()
// Use cancellable context for the subscription
ctx, cancelSubscribe := context.WithCancel(ctx)
// Check if the last message was received more than 5 seconds ago. If so, cancel the subscription context
go func() {
for {
@sanderploegsma
sanderploegsma / redis-cluster-statefulset.yml
Last active August 22, 2018 20:33
Redis cluster example
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: redis-cluster
labels:
app: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
selector:

Keybase proof

I hereby claim:

  • I am sanderploegsma on github.
  • I am sanderp (https://keybase.io/sanderp) on keybase.
  • I have a public key ASCeL-IVd_AzlnZlHwps27TSVke0LroY4h9JGAc3Okcsmwo

To claim this, I am signing this object:

@sanderploegsma
sanderploegsma / up.sh
Last active August 29, 2015 14:15
Linkdump upload script
#!/bin/bash
# up.sh by Sander Ploegsma (@sanderploegsma)
#
# Copy file to remote location using generated filename. Return file link and copy to clipboard
# NOTE: Currently only meant for OS X due to use of pbcopy.
#
REMOTE_USER="username"
REMOTE_URL="example.com"
REMOTE_PATH="/path/to/files"
LINK_BASE="http://my.short.url/"
@sanderploegsma
sanderploegsma / postdownload.sh
Created October 12, 2014 15:12
Force CouchPotato rescan after download completion
#! /bin/bash
# postdownload.sh by Sander Ploegsma
{
CP_API_KEY="apikeyhere"
CP_HOST="<ip>:<port>"
echo $(date +%Y-%m-%d\ %H:%M:%S) "Forcing CouchPotato rescan..."
curl --silent -X POST "http://$CP_HOST/api/$CP_API_KEY/renamer.scan" > /dev/null
echo $(date +%Y-%m-%d\ %H:%M:%S) "Done."
}