Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila
nikoheikkila / README.md
Last active May 28, 2024 20:08
Fish Shell function for sourcing standard .env files

envsource

⚠️ NOTE (20.5.2023): I don't really use this function at all anymore since there are now tools such as Taskfile, which reads the .env file for me sparing me the need to pollute my session with environment variables.


I've been using Fish shell for years which is great and all, but one thing that has got me frustrated is using it with .env files.

When attempting to run source .env in a project, I usually encounter this problem:

@nkhitrov
nkhitrov / logger.py
Last active May 28, 2024 12:18
Configure uvicorn logs with loguru for FastAPI
"""
WARNING: dont use loguru, use structlog
https://gist.github.com/nkhitrov/38adbb314f0d35371eba4ffb8f27078f
Configure handlers and formats for application loggers.
"""
import logging
import sys
from pprint import pformat
@phiresky
phiresky / tune.md
Last active May 17, 2024 12:33
SQLite performance tuning

You can scale a SQLite database to multiple GByte in size and many concurrent readers by applying the below optimizations.

Run these every time you connect to the db

(some are applied permanently, but others are reset on new connection)

pragma journal_mode = WAL;

Instead of writing directly to the db file, write to a write-ahead-log instead and regularily commit the changes. Allows multiple concurrent readers, and can significantly improve performance.

@devsetgo
devsetgo / app.py
Last active November 8, 2021 05:31
Loguru configuration with Starlette and Uvicorn.
import logging
from pathlib import Path
from loguru import logger
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
# set log level [DEBUG, INFO, WARNING, ERROR, CRITICAL]
LOGURU_LOGGING_LEVEL = "WARNING"
@leodutra
leodutra / -setup-windows-wsl-devenv.md
Last active May 23, 2024 02:13
Install and Setup Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font

Setup Windows Subsystem 2 for Linux

Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font

To setup native Linux, see this gist

Preview

Requirements

@eshleebien
eshleebien / medium-terminating-with-grace.py
Created July 9, 2019 07:31
For my medium article "Containers: Terminating with grace"
# source code
# shamelessly copied from
# https://stackoverflow.com/a/31464349/2591014
import signal
import time
class GracefulKiller:
kill_now = False
signals = {
@marcosvpj
marcosvpj / vscode-remove-duplicate-lines.md
Last active March 22, 2024 13:41
How to remove duplicate lines in Visual Studio Code?

If the order of lines is not important##

Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: https://stackoverflow.com/q/1573361/3258851)

  1. Control+F

  2. Toggle "Replace mode"

  3. Toggle "Use Regular Expression" (the icon with the .* symbol)

@darrenmothersele
darrenmothersele / docker.sh
Created December 2, 2018 11:49
Serving Angular CLI project over HTTPS / generate SSL cert / configure Angular CLI / optionally use NGINX via Docker
#!/bin/bash
docker run --name fc \
-v $PWD/ssl:/etc/nginx/certs \
-v $PWD/ssl/nginx-default.conf:/etc/nginx/conf.d/default.conf:ro \
-v $PWD/dist/___PROJECT_NAME___:/usr/share/nginx/html:ro -p 8080:443 -d nginx
@yingray
yingray / main.go
Last active February 6, 2024 08:27
Golang: aes-256-cbc examples (with iv, blockSize)
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
)
@mattdesl
mattdesl / point-to-line-2d.js
Created March 22, 2018 00:36
2D Point to Line Segment distance function
// Taken From:
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
function sqr (x) {
return x * x;
}
function dist2 (v, w) {
return sqr(v[0] - w[0]) + sqr(v[1] - w[1]);
}