Skip to content

Instantly share code, notes, and snippets.

View stefanondisponibile's full-sized avatar
👾
I'm game!

Stefano stefanondisponibile

👾
I'm game!
View GitHub Profile
@glenfant
glenfant / a_G_for_FastAPI.md
Last active June 29, 2024 06:21
A simple POC that mimics in FastAPI the "g" request lifecycle pseudo global

Like Flask "g". Good news you can do the same with FastAPI

"g" is a threadlocal magic object that lets developer add / change / remove attributes during the request lifecycle. Learn more about this "g" here.

There is no OTB equivalent in FastAPI, but thanks to the new contextvars Python 3.7+ module, I made this simple demo.

Any comment or help to improve yhis recipe is welcome.

@jhrcook
jhrcook / common-github-badges.md
Last active July 25, 2024 22:21
A list of GitHub badges I usually add to me README files.

GitHub Badges

Social

jhc github jhc twitter jhc website

Code

@dgarana
dgarana / __init__.py
Created July 7, 2016 16:13
Python load dynamic settings module through environment
# -* coding: utf-8 *-
"""
Config import handler
This let us import settings, and don't care about:
>>> settings = importlib.import_module('module_name')
"""
import os
import importlib
my_module = importlib.import_module(os.getenv('SETTINGS_MODULE'))
@brandonmwest
brandonmwest / example.cs
Last active June 27, 2024 04:03
Generating base64-encoded Authorization headers in a variety of languages
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", username, password))));
@itsmattsoria
itsmattsoria / gistfil1.textile
Last active July 3, 2024 05:36
Mac Terminal Cheat Sheet

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@crtr0
crtr0 / client.js
Created June 8, 2012 17:02
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});