Skip to content

Instantly share code, notes, and snippets.

View JonCanning's full-sized avatar

Jon Canning JonCanning

View GitHub Profile
@JonCanning
JonCanning / compose.yml
Created April 2, 2025 12:27
open telemetry collector and file exporter
services:
opentelemetry-collector-contrib:
image: otel/opentelemetry-collector-contrib:latest
ports:
- '4317:4317'
volumes:
- ./file-exporter:/file-exporter:rw
- ./otel-config.yml:/otel-config.yml
command: ['--config=/otel-config.yml']
@JonCanning
JonCanning / otel.ts
Created March 24, 2025 13:30
An OpenTelemetry abstraction for typescript
import {
type AttributeValue,
type Context,
context,
type Counter,
type Meter,
propagation,
type Span,
SpanStatusCode,
trace,
#!/usr/bin/env zx
const account = process.argv[3];
const cluster = process.argv[4];
const target = process.argv[5];
const port = process.argv[6];
if (!target || !port) {
console.error("Usage: forward.mjs <account> <cluster> <target> <port>");
console.error("Example: forward.mjs 1234567890 cluster-dev my-api 8000");
process.exit(1);
@JonCanning
JonCanning / getprotoc.sh
Created February 6, 2025 17:18
Get latest protoc
version=$(curl -s -L -o /dev/null -w '%{url_effective}' https://github.com/protocolbuffers/protobuf/releases/latest | grep -oP 'tag/\Kv[^/]+')
version=${version#v}
url="https://github.com/protocolbuffers/protobuf/releases/download/v$version/protoc-$version-linux-x86_64.zip"
curl -O "$url"
@JonCanning
JonCanning / main.go
Created November 12, 2024 12:22
golang circular seq
func circularSeq[T any](values []T) iter.Seq[T] {
i := 0
return func(yield func(T) bool) {
value := values[i]
i++
if i == len(values) {
i = 0
}
if !yield(value) {
return
@JonCanning
JonCanning / test.sh
Last active June 6, 2024 06:23
golang continuous testing
#!/bin/bash
fswatch -l 1 -o ./**/*.go --event=Updated | while read -r; do
clear
output=$(go test ./... 2>&1)
if echo "$output" | grep -- '- FAIL' > /dev/null; then
echo -e "\e[31m$(echo "$output" | awk '/--- FAIL/,/Test:/')\e[0m"
elif [ -z "$output" ]; then
echo -e "\e[31mBUILD FAILED\e[0m"
else
echo -e "\e[32mPASS\e[0m"
@JonCanning
JonCanning / log.go
Last active November 10, 2024 20:53
Go OTel and rotating file Logger
package log
import (
"context"
"log/slog"
"os"
"runtime"
"github.com/bakins/slogotlp"
"github.com/covalenthq/lumberjack"
@JonCanning
JonCanning / install.sh
Created December 18, 2023 10:04
Install latest docker-compose
curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep -i "$(uname -s)-$(uname -m)" | cut -d '"' -f 4 | head -n 1 | xargs curl -L -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
@JonCanning
JonCanning / kafka.fsx
Last active January 24, 2023 11:02
Kafka F# example
#r "nuget: Confluent.Kafka"
#r "nuget: System.Text.Json"
open Confluent.Kafka
open System
open System.Text.Json
open System.Threading.Tasks
open Confluent.Kafka.Admin
let server = "localhost:9092"
@JonCanning
JonCanning / packet.fsx
Last active January 12, 2023 22:19
Send a packet using SharpPcap and PacketDotNet
#r "nuget: PacketDotNet"
#r "nuget: SharpPcap"
open PacketDotNet
open SharpPcap
open System.Net.NetworkInformation
open System.Net
open System.IO
let deviceName = "eth0"