Skip to content

Instantly share code, notes, and snippets.

View ZeroCoolHacker's full-sized avatar
🎖️
Code Lover

Zero Cool ZeroCoolHacker

🎖️
Code Lover
View GitHub Profile
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@ZeroCoolHacker
ZeroCoolHacker / Liberal Regex Pattern for Web URLs
Created March 15, 2022 09:58 — forked from gruber/Liberal Regex Pattern for Web URLs
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
@ZeroCoolHacker
ZeroCoolHacker / custom_auth_model_mid_project
Created March 7, 2022 05:59
Change from defualt auth model to custom auth model mid project django
# Instructions taken from https://www.caktusgroup.com/blog/2019/04/26/how-switch-custom-django-user-model-mid-project/
1. Create your new app
> python manage.py startapp users
2. Change all User references to get_user_model() and settings.AUTH_USER_MODEL
2. set db_table of your user model to auth_user
```
from django.db import models
from django.contrib.auth.models import AbstractUser
ssh user@machine "pg_dump -U user -h localhost -C --column-inserts" \
> backup_file_on_your_local_machine.sql
@ZeroCoolHacker
ZeroCoolHacker / NATIONALITIES.py
Created May 27, 2021 05:54 — forked from zamai/NATIONALITIES.py
List of nationalities in python list and tuple format
#List of *hopefuly* all nationalities in list an tuple format for each python copy/paste
NATIONALITIES_tuple = ('Afghan', 'Albanian', 'Algerian', 'American', 'Andorran', 'Angolan', 'Antiguans', 'Argentinean', 'Armenian', 'Australian', 'Austrian', 'Azerbaijani', 'Bahamian', 'Bahraini', 'Bangladeshi', 'Barbadian', 'Barbudans', 'Batswana', 'Belarusian', 'Belgian', 'Belizean', 'Beninese', 'Bhutanese', 'Bolivian', 'Bosnian', 'Brazilian', 'British', 'Bruneian', 'Bulgarian', 'Burkinabe', 'Burmese', 'Burundian', 'Cambodian', 'Cameroonian', 'Canadian', 'Cape Verdean', 'Central African', 'Chadian', 'Chilean', 'Chinese', 'Colombian', 'Comoran', 'Congolese', 'Costa Rican', 'Croatian', 'Cuban', 'Cypriot', 'Czech', 'Danish', 'Djibouti', 'Dominican', 'Dutch', 'Dutchman', 'Dutchwoman', 'East Timorese', 'Ecuadorean', 'Egyptian', 'Emirian', 'Equatorial Guinean', 'Eritrean', 'Estonian', 'Ethiopian', 'Fijian', 'Filipino', 'Finnish', 'French', 'Gabonese', 'Gambian', 'Georgian', 'German', 'Ghanaian', 'Greek', 'Grenadian', 'Guate
@ZeroCoolHacker
ZeroCoolHacker / drf-nested-views.py
Created March 29, 2021 05:38 — forked from dkarchmer/drf-nested-views.py
Example of a Django Rest Framework ViewSet with nested views
# ViewSets define the view behavior.
class FooViewSet(viewsets.ModelViewSet):
lookup_field = 'slug'
queryset = Foo.objects.all()
serializer_class = FooSerializer
def get_queryset(self):
"""
This view should return a list of all records
"""
# run python x.py > file.py to get the new dict
for x in Currency:
symbol = CURRENCY_SYMBOLS_MAP.get(x.value, None)
if symbol:
currency = CurrencyHelper._CURRENCY_DATA.get(x)
CurrencyHelper._CURRENCY_DATA[x]['symbol'] = symbol
CurrencyHelper._CURRENCY_DATA[x]['thousand_separator'] = ','
CurrencyHelper._CURRENCY_DATA[x]['symbol_placement'] = 'before'
with open("new.py", "w") as f:
@ZeroCoolHacker
ZeroCoolHacker / backup-and-restore-postgres-docker
Last active January 20, 2024 19:44
Backup and restore or clone a postgres database using docker
# Backup Postgres Database
```docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql```
# Restore Postgres Database
```cat your_dump.sql | docker exec -i your-db-container psql -U postgres```
@ZeroCoolHacker
ZeroCoolHacker / docker-compose.yml
Created January 7, 2021 11:02 — forked from onjin/docker-compose.yml
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@ZeroCoolHacker
ZeroCoolHacker / wkhtmltopdf.sh
Created January 7, 2021 08:11 — forked from faniska/wkhtmltopdf.sh
Install wkhtmltopdf with patched QT on Ubuntu Linux
# Uncomment the next line if you have installed wkhtmltopdf
# sudo apt remove wkhtmltopdf
cd ~
# Select an appropriate link for your system (32 or 64 bit) from the page https://wkhtmltopdf.org/downloads.html and past to the next line
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox*.tar.xz
sudo mv wkhtmltox/bin/wkhtmlto* /usr/bin
sudo apt-get install -y openssl build-essential libssl-dev libxrender-dev git-core libx11-dev libxext-dev libfontconfig1-dev libfreetype6-dev fontconfig