Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
karl-gustav / Dockerfile
Last active September 29, 2023 08:03
Dockerfile for building golang scratch container
FROM golang:1-alpine as builder
RUN apk update
RUN apk add --no-cache ca-certificates git
WORKDIR /app
# Fetch dependencies first; they are less susceptible to change on every build
# and will therefore be cached for speeding up the next build.
COPY go.* .
@karl-gustav
karl-gustav / main.go
Created May 24, 2019 11:49
Super simple golang reverse proxy
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
)
@karl-gustav
karl-gustav / Makefile
Last active September 29, 2023 08:21
Good example of Makefile for using google run containers with gopass
export DOCKER_BUILDKIT=1
GPC_PROJECT_ID=hkraft-iot
SERVICE_NAME=defibrilator-registry
CONTAINER_NAME=europe-west1-docker.pkg.dev/$(GPC_PROJECT_ID)/cloud-run/$(SERVICE_NAME)
.PHONY: *
run: build
docker run -it -p 8080:8080\
-e CLIENT_ID=$$(gopass hjertestarterregisteret.no/client-id)\
@karl-gustav
karl-gustav / lillesveiven.space
Created April 24, 2019 11:05
/etc/nginx/sites-available/lillesveiven.space
# Based on https://gist.github.com/nrollr/9a39bb636a820fb97eec2ed85e473d38:
# =========================================================================
# UPDATED 17 February 2019
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
listen [::]:80;
server_name lillesveiven.space;
return 301 https://lillesveiven.space$request_uri;
}
@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

server {
listen 80;
location / {
proxy_pass http://localhost:8080/owncloud;
}
}
@karl-gustav
karl-gustav / my_math.js
Created April 5, 2019 12:09
helper math functions in javascript
// fixes that 2.55 is rounded to 2.5 and not 2.6 as it should have been
export function round(num, digits) {
digits = isNaN(digits) ? 2 : digits;
return +(Math.round(num + "e+" + digits) + "e-" + digits).toFixed(digits);
}
@karl-gustav
karl-gustav / safeGet.js
Created March 23, 2019 13:39
javascript safe get
function get(obj, ...args) {
let walker = obj;
for (const arg of args) {
if (walker && walker[arg]) {
walker = walker[arg];
} else {
return;
}
}
return walker;
@karl-gustav
karl-gustav / package.json
Created March 15, 2019 09:03
Absolute minimun package.json file
{
"name": "some-name",
"version": "0.0.1",
"dependencies": {
}
}