Skip to content

Instantly share code, notes, and snippets.

View marceloleiva's full-sized avatar

Marcelo Leiva marceloleiva

View GitHub Profile
@marceloleiva
marceloleiva / chrome_headless.py
Created January 25, 2024 00:31 — forked from haranjackson/chrome_headless.py
Deploys the Python Selenium library and Chrome Headless to an AWS Lambda layer. You can specify the region, library version, and runtime. An example Lambda function is given.
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = '/opt/headless-chromium'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--start-maximized')
options.add_argument('--start-fullscreen')
@marceloleiva
marceloleiva / invoice_template.html
Created September 8, 2022 15:14
Odoo 14 Invoice Template
<div style="margin:0px;padding: 0px;">
<p style="padding:0px;font-size: 13px;">
Estimado/a
% if object.partner_id.parent_id:
${object.partner_id.name} (${object.partner_id.parent_id.name})
% endif
<br><br>
Junto con saludarle y agradecer su preferencia, adjuntamos
% if object.name:
factura <strong>${object.name}</strong>
[options]
#
# WARNING:
# If you use the Odoo Database utility to change the master password be aware
# that the formatting of this file WILL be LOST! A copy of this file named
# /etc/odoo/openerp-server.conf.template has been made in case this happens
# Note that the copy does not have any first boot changes
#-----------------------------------------------------------------------------
# Odoo Server Config File - TurnKey Linux
@marceloleiva
marceloleiva / .env-example
Created April 3, 2020 00:08 — forked from gjbagrowski/.env-example
Django-environ example
# project-repo/app/settings/.env-example
#
# DJANGO
#
SITE_HOST=localhost:8000
USE_SSL=False
ALLOWED_HOSTS=localhost,127.0.0.1
SECRET_KEY=asdasd
DEBUG=true # never on production, will cause settings including api keys to leak
DJANGO_LOG_LEVEL=DEBUG
@marceloleiva
marceloleiva / forms.py
Created July 7, 2019 01:44 — forked from eerien/forms.py
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
@marceloleiva
marceloleiva / page.py
Created July 21, 2018 23:01 — forked from rturowicz/page.py
django - intermediate admin page
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']
@marceloleiva
marceloleiva / django_model_graph.sh
Created April 3, 2018 21:06 — forked from perrygeo/django_model_graph.sh
Generate UML diagram of django app models
apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in settings.py
python manage.py graph_models trees -o test.png
@marceloleiva
marceloleiva / letsencrypt_2017.md
Created June 6, 2017 14:51 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@marceloleiva
marceloleiva / views.py
Created April 27, 2017 21:59 — forked from MrYoda/views.py
Python 3, Django 1.9+: Excel file creation and send on-the-fly with XlsxWriter & BytesIO
import xlsxwriter
from io import BytesIO
from django.http import StreamingHttpResponse
from django.views.generic import View
def get_foo_table_data():
"""
Some table data
"""
@marceloleiva
marceloleiva / Buscar texto con re.py
Created October 17, 2016 18:43
Buscar texto con re created by marceloleiva - https://repl.it/Dy6x/1
import re
texto = 'Supermercado (1,10,5)'
busqueda_coordenada = re.search(r'(.+)(\(.{5,}\))', texto)
print(busqueda_coordenada.groups())
if busqueda_coordenada:
if len(busqueda_coordenada.groups()) >= 2:
texto = busqueda_coordenada.group(1).strip()
coordenada = re.sub('[()]', '', busqueda_coordenada.group(2)).split(',')