Skip to content

Instantly share code, notes, and snippets.

View Karitham's full-sized avatar
🖥️
nerd

Kar Karitham

🖥️
nerd
View GitHub Profile
@Karitham
Karitham / requestIDHandler.go
Created April 2, 2024 07:59
slog handler that pulls request id from context and adds it to traces
package http
import (
"context"
"log/slog"
)
// RequestAttrGrabber adds an attribute to each row produced by the logger when it can
type RequestAttrGrabber struct {
Sub slog.Handler
@Karitham
Karitham / .envrc
Last active February 27, 2024 09:32
alias for direnv
alias() {
mkdir -p .direnv/bin
echo "#!/usr/bin/env sh
$(which $2) \$@" >.direnv/bin/$1
chmod +x .direnv/bin/$1
}
alias k8 kubectl
alias k9 k9s
@Karitham
Karitham / screen.sh
Created February 20, 2024 07:54
script to set display settings based on the existence of a screen
#/usr/bin/env bash
set -x +o pipefail
# Get the current output of hyprland monitors command
output=$(hyprctl monitors -j)
# Check if the HDMI-A-1 display exists in the output
# use grep because it fails if it doesn't find anything, unlike jq.
if echo "$output" | grep "HDMI-A-1"; then
@Karitham
Karitham / README.md
Created January 11, 2024 11:07
nixos rustdesk from github deb pkg

To build the derivation just run nix-build -A rustdesk ./rustdesk.nix

@Karitham
Karitham / dragonfly.yml
Created August 9, 2023 14:10
dragonflydb template for a kraud app
version: '3.9'
name: dragonfly
x-kraud-ui:
label: "DragonflyDB"
description: |
Dragonfly is an in memory data store built for modern application workloads.
Fully compatible with Redis and Memcached APIs,
Dragonfly requires no code changes to adopt.
@Karitham
Karitham / update-char-img.sh
Last active March 8, 2022 08:11
Updating a character image in the WaifuBot DB with `usql`, `jq` and `curl`
#! /bin/bash
query=$(curl 'https://graphql.anilist.co/' \
-s \
-H 'content-type: application/json' \
-d "{\"query\":\"query(\$id: Int) {Character(id:\$id){image{large}}}\",\"variables\":{\"id\":$1}}")
URL=$(echo $query | jq -r '.data.Character.image.large')
if [ $URL != "null" ]; then
@Karitham
Karitham / README.md
Created July 2, 2021 10:04
SQL to Go struct

SQL to Go struct

Simple program to transform SQL queries to go structs.

The fields need to have a as clause for now.

Example

SELECT inbounds.count as inbounds_count,
@Karitham
Karitham / toCamel.go
Created May 16, 2021 17:11
Export all struct fields of a go file
package main
import (
"bytes"
"fmt"
"os"
"regexp"
"strings"
"github.com/iancoleman/strcase"
@Karitham
Karitham / webhook.go
Created November 13, 2020 12:26
small go code for using webhooks
package webhook
import (
"bytes"
"encoding/json"
"net/http"
)
// Webhook is the toplevel webhook object
type Webhook struct {