Skip to content

Instantly share code, notes, and snippets.

melmi /
Last active August 30, 2023 19:09
This a demo on how we can use an IoC container with FastAPI. Checkout my full article here:
import functools
from typing import Annotated, Any, Callable, Protocol, Type, TypeVar
from fastapi import APIRouter, Depends, FastAPI, Request
import punq
# domain - no dependency to FastAPI or IoC
class Greeter(Protocol):
def greet(self) -> str: ...
melmi /
Last active August 1, 2023 21:10
C# dumb practices

A long time ago in a galaxy far, far away....

if (condition) doSomething(); else if (!condition) doSomethingElse();
if (condition) doSomething(); else doSomething();
$query_string = $_SERVER['QUERY_STRING'];
$fp = fopen("dllist.txt", "a");
flock($fp, LOCK_EX);
fputs($fp, $query_string);
fputs($fp, "\n");
flock($fp, LOCK_UN);
melmi /
Created October 10, 2016 08:30
cd ~/Downloads/auto/
echo "============================" >> log.txt
echo "[$(date)] script launched" >> log.txt
echo "[$(date)] renewing dllist.txt" >> log.txt
rm dllist.txt
wget --user=folani --password=passwordesh
melmi / makefile
Last active September 23, 2016 11:22
A general purpose makefile for c++ projects
PROJNAME = your_project_name
SRCDIR = src
OBJDIR = bin
DEPDIR = bin
BINDIR = bin
CXX = g++
CXXFLAGS = -O3 -std=c++14
$fp = fopen("log.txt", "a");
flock($fp, LOCK_EX);
$timezone = 'Asia/Tehran';
$date = date('m/d/Y h:i:s a', time());
fputs($fp, "TIME: $date\n");
$timezone = date_default_timezone_get();
fputs($fp, "TIMEZONE: $timezone\n");
#!/usr/bin/env bash
show_err() {
echo "add-repo: an error occured."
echo "Usage:"
melmi / Default (Linux).sublime-keymap
Created May 19, 2013 22:13
An easy way to build and run inside SublimeText2. This method uses makefile with appropriate rules. A simple makefile is also provided just as an example. To use this copy `Unleash Makefile.sublime-build` into `Packages\User` directory of your SublimeText config directory. Keybindings also can be added to User keybindings.
{"keys": ["ctrl+shift+c"], "command": "exec", "args": {"kill": true} } ,
{"keys": ["ctrl+shift+l"], "command": "build", "args": {"variant": "Clean"} }