Skip to content

Instantly share code, notes, and snippets.

@neomantra
neomantra / grafana-pdc.nomad.tpl
Last active July 12, 2024 19:44
pdc-agent with HashiCorp Nomad
# Grafana PDC -- private network tunnel
# This is templated by Terraform templatefile()
# https://grafana.com/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/configure-pdc/
job "grafana-pdc" {
region = "global"
datacenters = ["${NOMAD_DATACENTER}"]
namespace = "${NOMAD_NAMESPACE}"
type = "service"
@neomantra
neomantra / compressed_reader_writer.go
Created May 28, 2024 20:14
Compression wrappers for io.Reader and io.Writer
// Copyright (c) 2024 Neomantra BV
//
// Opinionated Reader/Writer wrappers
package nmio
import (
"compress/gzip"
"io"
"os"
@neomantra
neomantra / directory.go
Created May 21, 2024 22:45
VerifyDirectoryExists
func VerifyDirectoryExists(dirPath string) error {
if fileInfo, err := os.Stat(dirPath); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("directory '%s' does not exist", dirPath)
} else {
return fmt.Errorf("error filestat on '%s': %w", dirPath, err)
}
} else if !fileInfo.IsDir() {
return fmt.Errorf("'%s' exists but is not a directory", dirPath)
}
@neomantra
neomantra / pointerValueMap.go
Created March 31, 2023 13:31
NewPointerValueMap converts a map[string]*T to a map[string]T, omitting nil pointers.
// NewPointerValueMap converts a map[string]*T to a map[string]T, omitting nil pointers.
func NewPointerValueMap[K comparable, V any](src map[K]*V) map[K]V {
dst := make(map[K]V)
for k, ptr := range src {
if ptr != nil {
dst[k] = *ptr
}
}
return dst
}
@neomantra
neomantra / install_onload.sh
Created February 2, 2023 12:45
Installing OpenOnload on Ubuntu 22.04 Jammy
# adapted from https://github.com/neomantra/docker-onload/blob/master/jammy/Dockerfile
# install dependencies
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends \
autoconf \
automake \
ca-certificates \
coreutils \
curl \
 
 --------
 ////////\\
/ \\
| o o |
| /_ @|
 \ /
 \ \__/ /\
 \____/
How badly does MIT
@neomantra
neomantra / sleepy-cat.pl
Created January 16, 2023 14:25
sleepy-cat - like cat, except delay a little bit to emulate the # behavior of an old terminal
#!/usr/bin/env perl
# From: https://klipkyle.gitlab.io/blog/2017-10-22-vt100-ani.html
#
# scat
#
# sleepy-cat - like cat, except delay a little bit to emulate the
# behavior of an old terminal
#
# By default a delay is inserted after every line feed (to emulate
# screen refresh), and a smaller delay is inserted between every
@neomantra
neomantra / cnum.lua
Created December 7, 2022 13:51
Lua function to convert thousands-separated numbers into plain numbers
-- converts thousands-separated numbers into plain numbers
-- for example:
-- cnum(0) == 0
-- cnum(1,000) == 1000
-- cnum(3,141,593) == 3141593
-- cnum(-9,001) == -9001
function cnum(...)
local superbase = 1000
local sign = 1
local result = 0
@neomantra
neomantra / pi_from_dns.sh
Created April 27, 2022 15:19
Extract PI from pi.neomantra.com
# Extract Pi from pi.neomantra.com
# IPv4
dig pi.neomantra.com +short
# 3.141.59.26
dig pi.neomantra.com +short | tr -d . | sed -re 's/^.{1}/&./'
# 3.1415926
@neomantra
neomantra / High_Performance_Redis.md
Last active October 20, 2024 15:00
Notes on running Redis with HPC techniques

High Performance Redis

In response to this brief blog entry, @antirez tweeted for some documentation on high-performance techniques for Redis. What I present here are general high-performance computing (HPC) techniques. The examples are oriented to Redis. but they work well for any program designed to be single- or worker-threaded and asynchronous (e.g. uses epoll).

The motivation for using these techniques is to maximize performance of our system and services. By isolating work, controlling memory, and other tuning, you can achieve significant reduction in latency and increase in throughput.

My perspective comes from the microcosm of my own bare-metal (vs VM), on-premises deployment. It might not be suitable for all scenarios, especially cloud deployments, as I have little experience with HPC there. After some discussion, maybe this can be adapted as [redis.io documentation](https://redis.io/do