Skip to content

Instantly share code, notes, and snippets.

View dwickstrom's full-sized avatar
🐎

David Wickström dwickstrom

🐎
View GitHub Profile
@liviaerxin
liviaerxin / README.md
Last active May 2, 2024 00:04
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload
@i-am-tom
i-am-tom / interactive-config.js
Last active November 1, 2018 09:06
Prompt users for missing/sensitive config data as and when it's required.
// Sometimes, you might want to supply *some* config, but
// not necessarily *all*. Maybe your password is really
// secret, so you don't want to risk saving it in a config
// file. In which case, you'll want to ask the user to enter
// it when your script runs.
// This interface provides a flexible approach, where
// the user is prompted for a missing key when it's
// requested - if a particular key isn't needed for a given
// run, the user won't need to enter it. Of course, if the
@abacaphiliac
abacaphiliac / run-kafka-container.md
Last active January 21, 2024 12:10
Run Kafka Container

Start Kafka service

The following commands will start a container with Kafka and Zookeeper running on mapped ports 2181 (Zookeeper) and 9092 (Kafka).

docker pull spotify/kafka
docker run -d -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=kafka --env ADVERTISED_PORT=9092 --name kafka spotify/kafka

Why Spotify?

ADVERTISTED_HOST was set to kafka, which will allow other containers to be able to run Producers and Consumers.

@btroncone
btroncone / rxjs_operators_by_example.md
Last active July 16, 2023 14:57
RxJS 5 Operators By Example
@Avaq
Avaq / combinators.js
Last active May 1, 2024 09:38
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@branneman
branneman / algebraic-data-types.js
Last active August 22, 2019 14:35
Simple Algebraic Data Types (ADTs) implementing fantasy-land: Identity, Const, Maybe, Either, IO
const fl = require('fantasy-land')
const inspect = require('util').inspect.custom
// Fantasy Land
// of :: Applicative f => a -> f a
// map :: Functor f => f a ~> (a -> b) -> f b
// ap :: Apply f => f a ~> f (a -> b) -> f b
// chain :: Chain m => m a ~> (a -> m b) -> m b
/**
@JulienPalard
JulienPalard / curry.py
Created August 1, 2014 10:51
KISS Python curry
#!/usr/bin/env python
def curry(func):
"""
Decorator to curry a function, typical usage:
>>> @curry
... def foo(a, b, c):
... return a + b + c
var apply = Function.prototype.apply;
var flatten = apply.bind([].concat, []);
Array.of = function (a) {
return [a];
};
Array.prototype.chain = function (f) {
return flatten(this.map(f));
};
@venkatesh22
venkatesh22 / django custom signal
Created June 26, 2013 05:37
django custom signals creation example
#signals.py
from django.dispatch import Signal
user_login = Signal(providing_args=["request", "user"])
#views.py
from foo import signals
@cjhanks
cjhanks / htool.py
Last active September 25, 2016 18:31
Haskell --> Python Tools
""" htool :: Haskell Tool
Module of borrowed operators from Haskell implemented in Python for the purpose
of gaining more familiarity with functional programming in a familiar
environment.
"""
__author__ = 'CjHanks'
__license__ = 'Free'
from operator import lt, gt