Skip to content

Instantly share code, notes, and snippets.

View bukowa's full-sized avatar

Buk Bukowski bukowa

View GitHub Profile
@bukowa
bukowa / cli.sh
Created February 15, 2023 03:08
bash cli with positional and named arguments
#!/bin/bash
set -o errexit
force=false
reg_name='test'
reg_port='5001'
pos_args=()
while [ $# -gt 0 ]; do
arg="$1"
@bukowa
bukowa / Makefile
Created February 14, 2023 06:01 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@bukowa
bukowa / bash-cheatsheet.sh
Created February 14, 2023 06:00 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@bukowa
bukowa / Makefile.py
Created February 13, 2023 09:21
python makefile click autocomplete
import dataclasses
import selectors
import sys
import click
from colorama import Fore
@dataclasses.dataclass
class Command:
@bukowa
bukowa / bash.sh
Last active February 16, 2023 05:34
bash
# spinner, progress bar
https://stackoverflow.com/questions/238073/how-to-add-a-progress-bar-to-a-shell-script/238094#238094
# kubectl get all api resources separated by comma
kubectl api-resources -o name | paste -sd, -
# gpg print signing keys
gpg --list-keys --with-colons | awk -F: '/^pub:/ { print $5 }'
# gpg generate and export
@bukowa
bukowa / gunicorn.conf.py
Last active February 11, 2023 06:05
django + gunicorn proper logging setup
from .logging import GunicornLogger, gunicorn_logconfig_dict, gunicorn_access_log_format
wsgi_app = "conf.wsgi"
bind = "0.0.0.0:8000"
workers = 2
proxy_protocol = True
proxy_allow_ips = "*"
@bukowa
bukowa / constraint.py
Last active February 7, 2023 22:22
django constraint error message for field
from django.core.exceptions import ValidationError
from django.db import models
class ViolationFieldNameMixin:
"""
Mixin for BaseConstraint subclasses that builds custom
ValidationError message for the `violation_field_name`.
By this way we can bind the error to the field that caused it.
This is useful in ModelForms where we can display the error
@bukowa
bukowa / models.py
Created February 6, 2023 21:36
django cascade on related change foreign key
class CascadeOnRelatedChangeForeignKey(models.ForeignKey):
"""
ForeignKey that deletes all instances of the "related_name"
whenever the related instance changes.
For example while using this field in a token model, if the user
changes, all the tokens will be deleted.
"""
def contribute_to_related_class(self, cls, related):
@bukowa
bukowa / __init__.py
Created January 30, 2023 16:38
django don't cache static files wrapper no-cache
from functools import wraps
import django.http
import django.views.static
def no_cache_static(f):
@wraps(f)
def static(*a, **kw):
response: django.http.response.HttpResponse = f(*a, **kw) # type:
@bukowa
bukowa / Makefile
Created January 30, 2023 16:37
download node
getnode:
mkdir venvnode || true && wget -c https://nodejs.org/dist/v18.13.0/node-v18.13.0-linux-x64.tar.xz -O - | tar --strip-components=1 -xJ -C venvnode