Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@douglasmiranda
douglasmiranda / option1.py
Last active April 25, 2024 09:10
Fix: Django Debug Toolbar not showing when using with Docker.
# YOU MAY WANT TO CHECK THIS OUT: https://github.com/douglasmiranda/ddpt/blob/master/{{cookiecutter.django_project_name}}/{{cookiecutter.django_project_name}}/config/local.py
# If you don't do this you will have to add the host IP in INTERNAL_IPS = ('127.0.0.1',)
# And it will change, then you will have to change INTERNAL_IPS again.
def show_toolbar(request):
if request.is_ajax():
return False
return True
@douglasmiranda
douglasmiranda / validate.py
Created April 23, 2024 23:31
Mailgun Webhook: validate webhook request in Python
# https://documentation.mailgun.com/docs/mailgun/user-manual/tracking-messages/#webhooks
# 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
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">
save
</button>
<button type="submit" name="send-all">
send all
</button>
</form>
@douglasmiranda
douglasmiranda / a.py
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
douglasmiranda / dramatiq.md
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


@dramatiq.actor
def identity(x):
    return x
@douglasmiranda
douglasmiranda / svg-optimizers.md
Last active April 12, 2024 14:35
About SVG Optimizers
@douglasmiranda
douglasmiranda / entrypoint.sh
Created April 10, 2024 01:58
Docker entrypoint template
#!/bin/sh
set -o errexit
set -o pipefail
# exec command: [..] from docker-compose.yml / stack.yml
exec "$@"
# Wait for any process to exit
wait -n
@douglasmiranda
douglasmiranda / my_server.tf
Created April 5, 2024 21:57
Terraform Hetzner example config (simple single server + simple firewall)
# Simple server: debian, simple firewall, ssh access using existing ssh key pre registered in hetzner panel
# https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/server
# https://docs.hetzner.cloud/#networks
# https://www.hetzner.com/cloud/
# Configure the Hetzner Cloud Provider
provider "hcloud" {
token = var.hcloud_token
}
@douglasmiranda
douglasmiranda / pdf-to-svg.md
Last active March 6, 2024 21:11
About PDF to SVG converters

(Maybe in the future I will explain better about what happens when you convert your document to pdf, so for now, just keep the originals safe.)

The easy way

Depending on the PDFs you could just extract the text, with simple tools like pdftotext, comes with Poppler Tools.

Want to convert a simple page? You could just simply load some vector editing software, that accepts PDF as an input and export in SVG. Or maybe and online converter. A single document, not too large, you probably could choose this option also.

Not too easy way