Skip to content

Instantly share code, notes, and snippets.

View SaulTigh's full-sized avatar
🐬
->

Kyrylo Tarasenko SaulTigh

🐬
->
View GitHub Profile
@SaulTigh
SaulTigh / solidlycalc.py
Created July 30, 2024 13:20
example of SOLID calc
"""
Write a class Calculator in Python that should implement `add` functionality of 2 numbers.
As a user of this class I should be able to make such call "calculator.add(2, 3)". Constructor implementation is of your choice.
If any of numbers is < 1000 class will calculate in memory.
If both numbers are >= 1000 class will calculate via http call to remote server.
If both numbers are >= 100000 class will calculate via SOAP call
Make sure that your Calculator is SOLIDly designed
"""
import abc
@SaulTigh
SaulTigh / sqlalchemy_helpers.md
Last active June 2, 2020 08:32
sqlalchemy query logging
import logging
log = logging.getLogger(__name__)
from sqlalchemy import event
from sqlalchemy.engine import Engine
event.listen(Engine, "before_cursor_execute",
             lambda conn, cursor, statement,
                    parameters, context,
                    executemany: log.info(statement, parameters))
@SaulTigh
SaulTigh / init.supervisord.sh
Last active August 29, 2015 14:06
Supervisord configuration as service on Ubuntu
# based on http://serverfault.com/a/96500
# http://serverfault.com/a/96500
sudo curl https://gist.githubusercontent.com/howthebodyworks/176149/raw/88d0d68c4af22a7474ad1d011659ea2d27e35b8d/supervisord.sh > /etc/init.d/supervisord
sudo chmod +x /etc/init.d/supervisord
sudo update-rc.d supervisord defaults
# now you can do such things as
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
import sys
import os
import re
import hotshot, hotshot.stats
import tempfile
import StringIO
@SaulTigh
SaulTigh / debug_middleware.py
Created March 6, 2014 09:00
for debugging django apps
class ExceptionLoggingMiddleware(object):
def process_exception(self, request, exception):
import traceback
print traceback.format_exc()