Skip to content

Github

Flask

from flask import make_response

@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)

Pre-Commit

pre-commit run black --all-files

Git stash

# To list the stashed modifications
git stash list

#To show files changed in the last stash
git stash show

#So, to view the content of the most recent stash, run
git stash show -p

#To view the content of an arbitrary stash, run something like
git stash show -p stash@{1}

Pytest

pytest -v --cov-report=html --cov=apis test_enpoints.py

IFTTT

import requests
def notification(message):
    report = {}
    report['value1'] = message
    requests.post('https://maker.ifttt.com/trigger/epoch_end/with/key/<Replace-key-here>', data=report)

Logging

from functools import wraps
def my_logger(orig_func):
    import logging
    logging.basicConfig(filename='{}.log'.format(orig_func.__name__), level=logging.INFO)

    @wraps(orig_func)
    def wrapper(*args, **kwargs):
        logging.info(
            'Ran with args: {}, and kwargs: {}'.format(args, kwargs))
        return orig_func(*args, **kwargs)
    return wrapper

def my_timer(orig_func):
    import time
    @wraps(orig_func)
    def wrapper(*args, **kwargs):
        t1 = time.time()
        result = orig_func(*args, **kwargs)
        t2 = time.time() - t1
        print('{} ran in: {} sec'.format(orig_func.__name__, t2))
        return result
    return wrapper

VIM

:set makeprg=python\ %
:set autowrite
:make

Simple CSS

<style type="text/css">body{margin:40px
auto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:0
10px}h1,h2,h3{line-height:1.2}</style>

remove docker log file

sudo find /var/lib/docker/ -name "*.log" -exec ls -sh {} \; | sort -h -r | head -10
sudo sh -c "truncate -s 0 /var/lib/docker/containers/<filename>-json.log"

Boyfriend Alert

while true; do echo ok | nc -l 8000; for i in 1 2 3 4; do printf '\a'; sleep 1; done; done
while true; do echo Coming! | nc -l 8000; for i in 1 2 3 4; do say "Lunch time!"; sleep 1; done; done
while true; do (echo ok | nc -q 1 -vlp 8000 2>&1; echo; date -u) | tee -a beeper.log; for i in 1 2 3 4; do printf '\a'; sleep 1; done & done

Reloads configuration without restarting Nginx

sudo nginx -s reload 

bash alias to help copy commands that include '$'

alias '$'=''

remove node modules

find . -name "node_modules" -exec rm -rf '{}' +