Skip to content

Instantly share code, notes, and snippets.

View mrb101's full-sized avatar
🌴
Adventuring

Basel J. Hamadeh mrb101

🌴
Adventuring
  • Germany
View GitHub Profile
@mrb101
mrb101 / sql.py
Created December 16, 2021 17:35 — forked from zzzeek/sql.py
The SQL is just as easy as an ORM challenge
""" "Writing SQL is just as fast as using an ORM" proof of concept
Below is a simple Python object model, where we represent a database that
stores the names of employees at a company, some of whom are "engineers",
and a list of the jobs they do and the programming languages they use.
We'd like to persist the state represented by this Python object model
in a relational database, using our Python objects as a start. Then we'd
like to write SQL queries for rows in this database, and we get back instances
of Python objects exactly as they were created.
@mrb101
mrb101 / rolling_col_upgrade.py
Created December 16, 2021 17:27 — forked from zzzeek/rolling_col_upgrade.py
keeping two columns in sync across an old and new schema version
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
e = create_engine("sqlite://", echo=True)
# first, we're in the old version of the app
OldBase = declarative_base()
@mrb101
mrb101 / test.py
Created December 16, 2021 17:11 — forked from zzzeek/test.py
adapt_on_lookup_mapping demo
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import aliased
from sqlalchemy.orm import declarative_base
#!/usr/bin/env bash
#
# Fetch diff stats for the current repo from the last year
# Get a commit SHA from a year ago
OLD_SHA=$(git log --since="365 days ago" --until="364 days ago" -1 --pretty=format:"%H")
NEW_SHA=$(git rev-parse HEAD)
# Number of lines then and now
OLD_LINES=$(git diff --stat `git hash-object -t tree /dev/null`..$OLD_SHA | awk '/files changed/ {print $4}')
@mrb101
mrb101 / run.py
Created August 28, 2021 11:30 — forked from codeinthehole/run.py
Sample Celery chain usage for processing pipeline
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@mrb101
mrb101 / celery.py
Created February 10, 2021 06:22 — forked from tapanpandita/celery.py
A celery abstract task class that is fired when a transaction is committed
class TransactionAwareTask(Task):
'''
Task class which is aware of django db transactions and only executes tasks
after transaction has been committed
'''
abstract = True
def apply_async(self, *args, **kwargs):
'''
Unlike the default task in celery, this task does not return an async
@mrb101
mrb101 / requirements.txt
Created October 30, 2020 07:09
Main Requirements.
django-celery-beat==2.0.0 # https://github.com/celery/django-celery-beat
flower==0.9.5 # https://github.com/mher/flower
pydantic==1.6.1 # https://github.com/samuelcolvin/pydantic
measurement==3.2.0 # https://github.com/coddingtonbear/python-measurement
whitenoise==5.2.0 # https://github.com/evansd/whitenoise
django-environ==0.4.5 # https://github.com/joke2k/django-environ
django-model-utils==4.0.0 # https://github.com/jazzband/django-model-utils
django-allauth==0.42.0 # https://github.com/pennersr/django-allauth
django-crispy-forms==1.9.2 # https://github.com/django-crispy-forms/django-crispy-forms
django-redis==4.12.1 # https://github.com/jazzband/django-redis
@mrb101
mrb101 / docker-aliases.sh
Created September 1, 2020 06:01 — forked from jgrodziski/docker-aliases.sh
Useful Docker Aliases
############################################################################
# #
# ------- Useful Docker Aliases -------- #
# #
# # Installation : #
# copy/paste these lines into your .bashrc or .zshrc file or just #
# type the following in your current shell to try it out: #
# wget -O - https://gist.github.com/jgrodziski/9ed4a17709baad10dbcd4530b60dfcbb/raw/d84ef1741c59e7ab07fb055a70df1830584c6c18/docker-aliases.sh | bash
# #
# # Usage: #
class BaseErrorHandlerMixin:
"""A mixin to use to handle errors occuring when running tasks.
Usage:
>>> from celery import Task
>>> from .mixins import BaseErrorHandlerMixin
>>>
>>> # Be careful with ordering the MRO
>>> class ThirdPartyBaseTask(BaseErrorHandlerMixin, Task):
>>> pass