Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar

Douglas Miranda douglasmiranda

  • Earth, Brazil
View GitHub Profile
douglasmiranda /
Created July 9, 2024 01:53
Django (postgres) ArrayField Multiple Choices as checkboxes.
from django import forms
from django.contrib.postgres.fields import ArrayField
class MultipleChoiceArrayField(ArrayField):
def formfield(self, **kwargs):
defaults = {
"form_class": forms.MultipleChoiceField,
"choices": self.base_field.choices,
douglasmiranda / Dockerfile
Created July 6, 2024 23:02
Dockerfile Alpine Python Pillow
FROM python:3.12-alpine
# Python specific settings
# sends output directly to terminal
# Python packages build dependencies
RUN apk add --no-cache --virtual .build-dependencies \
# Essentials
douglasmiranda /
Created June 10, 2024 21:43
Testing browserless deployed on Google Cloud Run + Google API Gateway
import requests
browserless_url = "https://..../config"
url = ""
querystring = {"token":"XYZ", "timeout":"1200000"}
response = requests.get(
douglasmiranda /
Last active June 4, 2024 00:44
Browserless / Puppeteer (Protocol error (Runtime.callFunctionOn): Target closed) Timeout Issue

Error: Protocol error (Runtime.callFunctionOn): Target closed

Browserless v2.6.1 running on Docker

I don't know why this happens, but it doesn't matter if you set your TIMEOUT environment variable, like so:

douglasmiranda /
Created April 23, 2024 23:31
Mailgun Webhook: validate webhook request in Python
# Securing Webhooks
# To ensure the authenticity of event requests, Mailgun signs them and posts the signature alongside the webhook's event-data.
# A signature takes the following form:
# Parameter Type Description
# timestamp int Number of seconds passed since January 1, 1970.
# token string Randomly generated string with length of 50.
# signature string String with hexadecimal digits generated by an HMAC algorithm
douglasmiranda / example.html
Created April 21, 2024 20:39
[HTML / Javascript form] multiple submit buttons/actions | capturing submit action server side | alert before submit javascript may affect submit button on server side
Lets say you have a form, with multiple submit buttons:
<form method="POST">
<button type="submit" name="save">
<button type="submit" name="send-all">
send all
douglasmiranda /
Created April 16, 2024 23:35
Python 2 urlencode unicode error (UnicodeEncodeError: 'ascii' codec can't encode character...)
import urllib
# 'a=%3F'
urllib.urlencode({'a': 'Á'}, 'utf-8')
douglasmiranda /
Created April 12, 2024 23:35
Dramatiq Task Queue - Check task status OR retrieve task result/status

It's much better simply implementing the callbacks on_success / on_failure.

import dramatiq
def identity(x):
    return x
douglasmiranda /
Created April 10, 2024 01:58
Docker entrypoint template
set -o errexit
set -o pipefail
# exec command: [..] from docker-compose.yml / stack.yml
exec "$@"
# Wait for any process to exit
wait -n