Skip to content

Instantly share code, notes, and snippets.

View sj14's full-sized avatar

Simon Jürgensmeyer sj14

View GitHub Profile
@sj14
sj14 / shutdown.sh
Last active March 10, 2024 09:23
Shutdown only when no smb connection is open
#!/usr/bin/env bash
set -o xtrace # output every line which gets executed
set -o nounset # fail if an unset variable is used
#set -o errexit # fail if a command exits with non-zero
set -o pipefail # fail if a command in a pipe fails
COUNTER=0
while test $COUNTER -le 30
@sj14
sj14 / splunkkafka.go
Last active February 19, 2024 16:16
OpenTelemetry splunkkafka tracing example (confluent-kafka-go)
// Produce (context to kafka message header)
propagators := propagation.TraceContext{}
propagators.Inject(ctx, splunkkafka.NewMessageCarrier(msg))
err := producer.Produce(msg, deliveryChan)
// Consume (kafka message headers to context)
message, err := client.ReadMessage(1 * time.Second)
@sj14
sj14 / sync_produce.go
Last active November 20, 2023 13:08
confluent-kafka-go sync produce
func syncProduce(ctx context.Context, producer *kafka.Producer, topic string, key, data []byte) error {
if producer == nil {
return errors.New("nil producer")
}
if producer.IsClosed() {
return errors.New("closed producer")
}
deliveryChan := make(chan kafka.Event, 1)
// do not close the delivery channel, as messages still could be sent there, which would panic
@sj14
sj14 / printstruct.go
Created September 26, 2023 09:00
Print Go structure (e.g. all tags)
package main
func main() {
val := reflect.ValueOf(&MY_STRUCTURE).Elem()
printStructure(val, 4)
}
func printStructure(s reflect.Value, level int) {
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
@sj14
sj14 / hosts
Created February 5, 2020 19:10
macOS Catalina 10.15 default /private/etc/hosts file
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
@sj14
sj14 / goreleaser-docker.md
Created July 14, 2019 07:26
Run goreleaser with docker

dry-run

docker run --rm --privileged \
  -v $PWD:/go/src/github.com/sj14/multicode \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -w /go/src/github.com/sj14/multicode \
  -e GITHUB_TOKEN=YOURTOKEN \
  -e GO111MODULE=on \
 goreleaser/goreleaser --rm-dist --snapshot --skip-publish
@sj14
sj14 / masq.sh
Created June 23, 2018 09:38 — forked from mowings/masq.sh
script to get xet xhyve working with all vpn interfaces
#!/bin/bash
interfaces=( $(netstat -in | egrep 'utun\d .*\d+\.\d+\.\d+\.\d+' | cut -d ' ' -f 1) )
rulefile="rules.tmp"
echo "" > $rulefile
sudo pfctl -a com.apple/tun -F nat
for i in "${interfaces[@]}"
do
RULE="nat on ${i} proto {tcp, udp, icmp} from 192.168.64.0/24 to any -> ${i}"
echo $RULE >> $rulefile
done

Keybase proof

I hereby claim:

  • I am sj14 on github.
  • I am simjue (https://keybase.io/simjue) on keybase.
  • I have a public key ASD4NSo5o8EeuD_BFMsysgkVNqX-9Sbpyjqlk-w3qDqo1wo

To claim this, I am signing this object:

@sj14
sj14 / fourier.go
Last active August 29, 2015 14:00
Discrete Fourier Transform (Go)
/*
* By Simon Jürgensmeyer, 2014.
* based on the work of Nayuki Minase:
* http://nayuki.eigenstate.org/page/how-to-implement-the-discrete-fourier-transform
*/
package main
import "fmt"
import "math"