Skip to content

Instantly share code, notes, and snippets.

@jerber
jerber / pydantic_to_strawberry.py
Last active February 1, 2022 21:38
Getting Strawberry to work with nested Pydantic Models
from __future__ import annotations
import typing as T
from enum import Enum
from pydantic import BaseModel
from pydantic.fields import ModelField
import strawberry
from strawberry.field import StrawberryField
from strawberry.types.types import TypeDefinition
@sandys
sandys / Fastapi-sqlalchemy-pydantic-dataclasses-reloadable-logging.md
Last active April 12, 2024 01:38
fastapi with python 3.10 dataclasses - used to create both sqlalchemy and pydantic models simultaneously. And setting up sqlalchemy the right way (without deadlocks or other problems). Additionally, this also takes care of unified logging when running under gunicorn..as well as being able to run in restartable mode.
@defulmere
defulmere / settings.py
Last active April 30, 2024 05:34
How to override an old sqlite3 module with pysqlite3 in django settings.py
# ⚠️ USE AT YOUR OWN RISK
# first: pip install pysqlite3-binary
# then in settings.py:
# these three lines swap the stdlib sqlite3 lib with the pysqlite3 package
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
DATABASES = {
@cb109
cb109 / vscode_python_sort_imports_isort_on_save.md
Last active June 12, 2023 03:50
VSCode: Python Sort Imports on File Save (isort)

VSCode: Python Sort Imports on File Save (isort)

Problem

VSCode does have support to sort imports inside a .py file using isort. The recommended way to turn this on is via the following settings:

"[python]": {
    "editor.formatOnSave": true,
 "editor.codeActionsOnSave": {
@ameenkhan07
ameenkhan07 / FB-PE-InterviewTips.md
Last active May 8, 2024 05:03
Facebook Production Engineering Interview

What to Expect and Tips

• 45-minute systems interview, focus on responding to real world problems with an unhealthy service, such as a web server or database. The interview will start off at a high level troubleshooting a likely scenario, dig deeper to find the cause and some possible solutions for it. The goal is to probe your knowledge of systems at scale and under load, so keep in mind the challenges of the Facebook environment.
• Focus on things such as tooling, memory management and unix process lifecycle.

Systems

More specifically, linux troubleshooting and debugging. Understanding things like memory, io, cpu, shell, memory etc. would be pretty helpful. Knowing how to actually write a unix shell would also be a good idea. What tools might you use to debug something? On another note, this interview will likely push your boundaries of what you know (and how to implement it).

Design/Architecture 

Interview is all about taking an ambiguous question of how you might build a system and letting

"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@jdrew1303
jdrew1303 / readme.md
Last active April 2, 2024 20:34
Market Order Matching Engine

Introduction

The computer driven markets for instruments like stocks and exchange traded stock options, have transformed finance and the flow of capital. These markets are enabled by order matching engines (and the infrastructure that supports this software). Before computer trading networks and matching engines, stocks where traded on cavernous exchange floors and transaction costs where high. When electronic trading fully matured, floor traders were a fading anachronism and transaction costs had been reduced to pennies a share in many cases. Electronic trading could not exist without advanced network infrastructure, but without the software matching engines no shares would change hands. The computer trading networks, the matching engine software has also created a concentrated nexus of potential failure. Failures in these systems have increased as the frequency and volume on the electronic networks has increased. The position of order matching engines in the trading infrastructure makes these systems o

@troyharvey
troyharvey / deployment.yml
Last active May 9, 2024 10:55
Using Kubernetes envFrom for environment variables
# Use envFrom to load Secrets and ConfigMaps into environment variables
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: mans-not-hot
labels:
app: mans-not-hot
spec:
replicas: 1
@niksmac
niksmac / zmv-examples.md
Created March 7, 2017 05:58
ZMV-Examples (require autoload zmv)

rename a section of a filename, i. e. example.1.{txt,conf,db} or 12345.1.{wav,ogg,mp3} and

change the 1 to a 2 in the filename while preserving the rest of it.

$ zmv -n '(.)(<->)(.[^.]#)' '$1$(($2+1))$3' # would rename x.0001.y to x.2.y. $ zmv -n '(.0#)(<->)(.[^.]#)' '$1$(($2+1))$3'

Rename files to lower case

$ zmv '*' '${(L)f}'

serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)

$ autoload zmv

@amgorb
amgorb / redis-client-ouput-buffer-limit
Created February 20, 2017 16:19
redis replication scheduled to be closed ASAP for overcoming of output buffer limits.
If you redis initial replication fails with error like
"5101:M 20 Feb 18:14:29.130 # Client id=4500196 addr=71.459.815.760:43872 fd=533 name= age=127 idle=127 flags=S db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=13997 oll=1227 omem=192281275 events=rw cmd=psync scheduled to be closed ASAP for overcoming of output buffer limits.
means that slave buffer is not enough and you should increase it (at master!) with command like
redis-cli config set client-output-buffer-limit "slave 836870912 836870912 0"
more info: https://redis.io/topics/clients