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')
[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 / django_reversion.md
Created July 12, 2016 17:39 — forked from goutham2027/django_reversion.md
using django reversion
pip install django-reversion

Add reversion to INSTALLED_APPS

INSTALLED_APPS = [
...
...
...
@marceloleiva
marceloleiva / forms.py
Created December 10, 2015 22:37 — forked from neara/forms.py
Django Class Based Views and Inline Formset Example
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from models import Sponsor, Sponsorship
class SponsorForm(ModelForm):
class Meta:
model = Sponsor