Skip to content

Instantly share code, notes, and snippets.

View morenoh149's full-sized avatar
💭
Working from 🛰

Harry Moreno morenoh149

💭
Working from 🛰
View GitHub Profile
@morenoh149
morenoh149 / django_settings.py
Last active January 17, 2023 15:17
django ignore db errors in sentry
# sentry docs for filtering errors
# https://docs.sentry.io/platforms/python/guides/django/configuration/filtering/#event-hints
from django.urls import reverse_lazy
from django.db.utils import InterfaceError as djangoDbInterfaceError
...
def before_send(event, hint):
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
@morenoh149
morenoh149 / settings.py
Created December 20, 2022 19:22
django logger propage traceback in 500
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
},
'handlers': {
@morenoh149
morenoh149 / settings.py
Last active December 2, 2022 04:20
Django log slow queries
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'slow_queries': {
'()': 'django.utils.log.CallbackFilter',
# output slow queries only, unit are 1s, so 0.3 is 300ms
# ref 300ms * 0.001 = 0.3, 50ms * 0.001 = 0.05
'callback': lambda record: record.duration > 0.05
},

How do I do something like options kwarg JazzCore/python-pdfkit#222

options = {
      "enable-local-file-access": True,
      ...
}
pdfkit.from_string(html_file, pdf_file, options=options, ...)
@morenoh149
morenoh149 / hosts.sh
Created November 14, 2022 16:04
bash script for add/removing host in /etc/hosts
#!/bin/bash
hosts() {
VALID_COMMANDS=("help" "show" "samplefile" "activate" "deactivate")
NO_ARG_COMMANDS=("help" "show" "samplefile")
GREEN='\033[0;32m';
RED='\033[0;31m';
NOCOLOR='\033[0m';
read -r -d '' SAMPLE_ETC_HOSTS_FILE <<HEREDOC
@morenoh149
morenoh149 / view.py
Last active October 11, 2022 21:46
django inspect variable
print('instance', dir(template_context['instance']))
> lists all variable fields
@morenoh149
morenoh149 / app.py
Created October 6, 2022 15:16
django orm optimization count on aggregates
results = myModel.objects.values().annotate(
group_representative=ArrayAggFirstElem('pk', distinct=True),
)
group_representatives = results.values_list('group_representative', flat=True)
assert_(
results.count() == group_representatives.count(),
'Aggregation Spec should partition the results space (no overlaps)'
)
@morenoh149
morenoh149 / local.yml
Created October 3, 2022 17:54
docker cookiecutter local.yml
version: "3"
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django: &django
build:
context: .
@morenoh149
morenoh149 / deploy-django.md
Created September 28, 2022 05:35 — forked from rmiyazaki6499/deploy-django.md
Deploying a Production ready Django app on AWS

Deploying a Production ready Django app on AWS

In this tutorial, I will be going over to how to deploy a Django app from start to finish using AWS and EC2. Recently, my partner Tu and I launched our app Hygge Homes (a vacation home rental app for searching and booking vacation homes based off Airbnb) and we wanted to share with other developers some of the lessons we learned along the way.

Following this tutorial, you will have an application that has:

  • An AWS EC2 server configured to host your application
  • SSL-certification with Certbot
  • A custom domain name
  • Continuous deployment with Github Actions/SSM Agent
@morenoh149
morenoh149 / user-data.sh
Last active September 28, 2022 19:56
aws solution architect certification user data script for ec2 instances
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html