Skip to content

Instantly share code, notes, and snippets.

View mmviamm's full-sized avatar

milad vakili mmviamm

View GitHub Profile
@mmviamm
mmviamm / docs.md
Last active January 14, 2025 15:40
Docker login to insecure http or self-cert distrubution registry or gitlab container registry

create or edit config file

docs

create or edit /etc/docker/daemon.json and add this:

{
  "insecure-registries" : ["myregistrydomain.com:5000"]
}
@mmviamm
mmviamm / yield_lines_reverse.py
Last active October 19, 2024 15:01
yield lines by reverse order even for larg files in python
# suits for large files
def reverse_readlines(file_path, buffer_size=8192):
"""Generator that yields lines from the end of a file."""
with open(file_path, 'rb') as f:
# Start at the end of the file
f.seek(0, 2)
file_size = f.tell()
buffer = bytearray()
@mmviamm
mmviamm / main.py
Created July 28, 2024 13:19
how to log (print) response headers and body with middlewares in fastapi (starllete)
# from official docs and this hint
# Hint: https://github.com/encode/starlette/issues/874#issuecomment-1027743996
# Docs: https://fastapi.tiangolo.com/tutorial/middleware/
# Note: in my case response is `starlette.responses.StreamingResponse`. in error logs it is `_StreamingResponse`
from fastapi import FastAPI, Request
from starlette.concurrency import iterate_in_threadpool
app = FastAPI()
@mmviamm
mmviamm / tools.js
Last active May 7, 2023 19:27
some tools for js
// array method to return unique items in new array
Array.prototype.unique = function() {
let a = this.concat();
for(let i=0; i<a.length; ++i) {
for(let j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}