Skip to content

Instantly share code, notes, and snippets.

@mybigman
mybigman / graceful_shutdown.go
Created September 8, 2022 12:56 — forked from aladhims/graceful_shutdown.go
Graceful Shutdown Go App
package main
// operation is a clean up function on shutting down
type operation func(ctx context.Context) error
// gracefulShutdown waits for termination syscalls and doing clean up operations after received it
func gracefulShutdown(ctx context.Context, timeout time.Duration, ops map[string]operation) <-chan struct{} {
wait := make(chan struct{})
go func() {
s := make(chan os.Signal, 1)
@mybigman
mybigman / main.go
Created August 25, 2022 01:05 — forked from dopey/main.go
How to generate secure random strings in golang with crypto/rand.
package main
import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"math/big"
)
package main
import (
"net/http"
)
type SingleHost struct {
handler http.Handler
allowedHost string
}
@mybigman
mybigman / main.go
Created August 8, 2022 08:53 — forked from StarBuckR/main.go
Golang Ldap Authentication, Bind and Search, including Anonymous Bind
package main
import (
"fmt"
"log"
"github.com/go-ldap/ldap/v3"
)
const (
@mybigman
mybigman / _base.html
Created June 4, 2022 12:44 — forked from simkimsia/_base.html
Django HTMX CSRF setup for htmx 1.1.0 and django 3.1
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{% block meta_tags %}
<meta name="csrf-token" content="{{ csrf_token }}">
{% endblock %}
@mybigman
mybigman / renderers.py
Created June 2, 2022 10:51 — forked from erny/renderers.py
FastAPI Simple content negotiation
"""Simple content negotiation
Usage:
Example 1:
from renderers import render
@router.post("/myapp/items/")
async def api_login(item: Item, accept: Optional[str] = Header(default='application/jwt')):
@mybigman
mybigman / app.py
Created June 2, 2022 03:19 — forked from PhilippHomann/app.py
FastAPI file upload with streaming_form_data to parse multipart/form-data
from fastapi import FastAPI, UploadFile, HTTPException
from starlette.requests import Request
from streaming_form_data import StreamingFormDataParser
from streaming_form_data.targets import FileTarget
from tempfile import NamedTemporaryFile
import os
import shutil
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
@mybigman
mybigman / freebsd.md
Created January 30, 2022 22:46 — forked from qis/freebsd.md
Installation and setup instructions for FreeBSD

FreeBSD

Installation template for FreeBSD RELEASE, STABLE and CURRENT.

Distribution Select

[ ] doc
[*] src (for building ports)
### FDE
man mkinitfs-bootparam
# filename and path is important
dd bs=512 count=4 if=/dev/urandom of=/crypto_keyfile.bin
cryptsetup luksAddKey /dev/sda1 /crypto_keyfile.bin
chmod 0 /crypto_keyfile.bin
cat /etc/mkinitfs/mkinitfs.conf
features="... cryptsetup cryptkey"