Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
karl-gustav / json_decoding_encoding.go
Last active August 22, 2022 08:00
Encode/decode directly into golang http
var subscription Subscription
err := json.NewDecoder(r.Body).Decode(&subscription)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer r.Body.Close()
@karl-gustav
karl-gustav / server.js
Created February 11, 2022 22:43
Minimal pure node js server
const http = require('http');
const url = require('url');
function handler(req, res) {
res.writeHead(200, {'Content-type':'text/plain'});
res.write('Hello, I am a webserver !');
res.end();
}
const port = process.env.PORT || 8080;
@karl-gustav
karl-gustav / main.go
Created December 16, 2021 11:11
using zap for logging in GCP
package main
import (
"github.com/blendle/zapdriver"
"go.uber.org/zap"
)
func main() {
structuredLogger, _ := zapdriver.NewProduction()
defer structuredLogger.Sync() // flushes buffer, if any
@karl-gustav
karl-gustav / heic_to_jpg.sh
Created October 24, 2021 14:13
Convert heic --> jpg on a mac
for file in *.heic; do sips -s format jpeg "$file" --out "${file%.heic}.jpg" && rm -f "$file"; done
@karl-gustav
karl-gustav / archive.applescript
Created October 20, 2021 10:45
Script for archiving a message (used in keyboard maestro)
tell application "System Events"
click menu item "Archive" of menu "Message" of menu bar 1 of application process "Mail"
end tell
@karl-gustav
karl-gustav / .vimrc
Created October 5, 2021 06:11
my .vimrc file (mac)
filetype plugin indent on
syntax on
au FileType gitcommit set tw=72
" scrolling in (iTerm2)
:set mouse=a
" Spellchecking in vim
:setlocal spell spelllang=en_us
@karl-gustav
karl-gustav / etc_caddy_Caddyfile
Created September 7, 2021 10:58
Caddyfile used before migrating to traefik
ha.lillesveiven.space {
reverse_proxy 127.0.0.1:8123
}
oc.lillesveiven.space {
reverse_proxy 127.0.0.1:9123
}
nr.lillesveiven.space {
reverse_proxy 127.0.0.1:1880
@karl-gustav
karl-gustav / docker_commands.md
Last active June 14, 2021 10:09
Usefull docker commands

Bash prompt inside running docker (try sh if no bash)

docker exec -it $(docker ps -q) bash

Bash prompt inside new docker (try sh if no bash)

docker run -it ubunut bash

Kill all running containers with

docker kill $(docker ps -q)

Delete all stopped containers with

@karl-gustav
karl-gustav / easee charger.py
Last active May 20, 2021 08:53
control easee charger over internet
# Source https://community.home-assistant.io/t/easee-ev-charging-station/186474/7
import requests, json, time
from pprint import pprint
class connect:
def __init__(self,
access_token=None,
):