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-compose-migrate.yaml
Last active October 30, 2024 23:16
This focuses on the webserver and the migrate task. It is based on https://github.com/cookiecutter/cookiecutter-django
django: &django
build:
context: .
dockerfile: ./Dockerfile.dev
image: local_django
container_name:local_django
depends_on:
- django_migrate
- db
volumes:
@morenoh149
morenoh149 / example.ts
Created June 6, 2024 19:36
typesript, dealing with accumulating outside scope
/*
error
Line 6: Char 14: error TS2448: Block-scoped variable 'res' used before its declaration.
*/
/* code */
function longestCommonSubsequence(arrays: number[][]): number[] {
// have a ptr for each array
let res = new Set();
let setA = new Set<number>(arrays[0]);
@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: .