Navigation Menu

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 / gmail_imap_python3.py
Last active March 12, 2024 07:29 — forked from robulouski/gmail_imap_example.py
Basic example of using Python3 and IMAP to read emails in a gmail folder/label. Remove legacy email.header api use
#!/usr/bin/env python
#
# Basic example of using Python3 and IMAP to read emails in a gmail folder/label.
# Remove legacy email.header api use.
import sys
import imaplib
import getpass
import email
import datetime
@morenoh149
morenoh149 / mysql.sql
Last active November 29, 2023 11:44
role based access control schemas in mysql, postgres and sqlite
/*
* Create Tables
*/
CREATE TABLE IF NOT EXISTS `PREFIX_permissions` (
`ID` int(11) NOT NULL auto_increment,
`Lft` int(11) NOT NULL,
`Rght` int(11) NOT NULL,
`Title` char(64) NOT NULL,
`Description` text NOT NULL,
#
# Generated automatically from man.conf.in by the
# configure script.
#
# man.conf from man-1.6c
#
# For more information about this file, see the man pages man(1)
# and man.conf(5).
#
# This file is read by man to configure the default manpath (also used
@morenoh149
morenoh149 / models.py
Last active July 19, 2023 09:18
Django model method mocking
class Blog(django.model):
name = models.CharField(null=False, max_length=64)
def list_articles(self):
return [
{'body': 'abcdefg'},
{'body': 'abcdefg'},
{'body': 'abcdefg'},
]
@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']
<ion-view>
<ion-header-bar align-title="center" class="bar-dark">
<div class="buttons">
<button class="button button-icon icon ion-close" ng-click="goHome()"></button>
</div>
<h1 class="title">crop</h1>
</ion-header-bar>
<!--
<div class="header-padding"></div>
-->
@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