Skip to content

Instantly share code, notes, and snippets.

View fmelihh's full-sized avatar
🐜
atom karıncaa !!

Furkan Melih Ercan fmelihh

🐜
atom karıncaa !!
View GitHub Profile
@philippegirard
philippegirard / main.py
Created April 18, 2020 20:18
fastapi logging middleware
import logging
from fastapi import FastAPI
from uicheckapp.services import EchoService
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger(__name__)
app = FastAPI()
@farhadmpr
farhadmpr / chain-of-responsibility.py
Created December 25, 2019 07:42
Chain of responsibility design pattern in python
class ReportFormat(object):
PDF = 0
TEXT = 1
class Report(object):
def __init__(self, format_):
self.title = 'title'
self.format_ = format_
@dmmeteo
dmmeteo / 1.srp.py
Last active June 7, 2024 14:11
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
// HTTPError implements ClientError interface.
type HTTPError struct {
Cause error `json:"-"`
Detail string `json:"detail"`
Status int `json:"-"`
}
func (e *HTTPError) Error() string {
if e.Cause == nil {
return e.Detail
@ghandic
ghandic / pandas_s3.py
Last active June 5, 2023 11:40
Load csv from S3 directly into memory and write to S3 directly from memory by extending pd.DataFrame class
import boto3
import pandas as pd
from io import StringIO
class S3DataFrame(pd.DataFrame):
"""
# Make a dataframe and upload it as csv
s3df = S3DataFrame({'h1':[1], 'h2':[2]})
s3df.to_s3(Bucket='bucket-name',
@amorgun
amorgun / sample.py
Created November 10, 2017 10:51
SqlAlchemy postgres bulk upsert
from sqlalchemy.dialects import postgresql
def bulk_upsert(session: Session,
items: Sequence[Mapping[str, Any]]):
session.execute(
postgresql.insert(MyModel.__table__)
.values(items)
.on_conflict_do_update(
index_elements=[MyModel.id],
set_={MyModel.my_field.name: 'new_value'},
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active June 27, 2024 14:45
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
@PSJoshi
PSJoshi / hash-webpage.py
Last active December 22, 2023 14:53
Hash a web page
#!/usr/bin/env python
import requests
import hashlib
page_contents = requests.get('http://www.google.com')
response = page_contents.text
print hashlib.sha256(response.encode('utf-8')).hexdigest()
@IrSent
IrSent / celery.py
Created November 12, 2016 19:12
Celery Best Practices
# Safe Queue Celery App Settings
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('some_project',
broker='amqp://',
backend='amqp://',
include=['some_project.tasks'])