Skip to content

Instantly share code, notes, and snippets.

@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 / 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,
):
@karl-gustav
karl-gustav / webserver.go
Last active September 29, 2023 08:21
go webserver
package main
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello world!")
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
@karl-gustav
karl-gustav / timed-ssh-tunnel
Last active October 3, 2020 20:30
SSH tunnel that auto closes after a given time
# Portforward localhost:8080 to port 8200 on the server
ssh -L 8080:localhost:8200 usr@server.com sleep 600
@karl-gustav
karl-gustav / useful_commands.sh
Last active February 12, 2020 08:36
Useful commands
# Move pictures from iPhone 7 into separate file structure:
find . -iname '*.JPG' -or -iname '*.JPEG' |while read line; do jhead "$line" |grep "Camera model : iPhone 7" && (mkdir -p $(dirname "${line/./.\/KGR}") ;mv "$line" "${line/./.\/KGR}" ) ; done
@karl-gustav
karl-gustav / safe_script.bash
Last active January 3, 2020 14:36
safe bash scripts
#######COPY THIS#######
set -euo pipefail
#######################
# Exit immediately when a command fails.
set -e
# Fail if any step in pipe fails, not just the last one
set -o pipefail
@karl-gustav
karl-gustav / json_decoding_web_request.go
Last active December 19, 2022 11:38
Decode directly from request in golang webserver
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 / 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 / Makefile
Last active August 29, 2019 13:21
Makefile for deploying with password environment variables on remote ssh server (and 8080->80, 4443->443 port forwarding)
SSH_SERVER=45.46.47.48
PROJECT_NAME=some-power
EXECUTABLE=some_power
ENV_FILE=.env_file
build:
GOOS=linux GOARCH=amd64 go build -o $(EXECUTABLE) .
deploy: build
$(eval IS_SUITE_PASSWORD := $(shell gopass api/some_more_power/password))
$(eval SMS_PASSWORD := $(shell gopass api/sms_service/password))
@karl-gustav
karl-gustav / Makefile
Last active March 31, 2020 11:01
Makefile for deploying a go executable as a service to an ssh machine
SSH_SERVER=34.32.31.30
SERVICE_NAME=flexit_web
test::
go test ./...