Skip to content

Instantly share code, notes, and snippets.

@davidbgk
davidbgk / server.py
Created April 11, 2017 15:39
An attempt to create the simplest HTTP Hello world in Python3
import http.server
import socketserver
from http import HTTPStatus
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(HTTPStatus.OK)
self.end_headers()
self.wfile.write(b'Hello world')
@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": {
}
}
@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 / 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 / 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 / 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 / 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"