Navigation Menu

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 / 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 / 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 / gist:aa171323de9711b8344efdb96d9d822d
Created September 14, 2023 01:14
Fix Virtualbox USB not detected
Virtual box cant enumerate
Virtual box no usb devices detected
sudo usermod -aG vboxusers $USER
@douglasmiranda
douglasmiranda / Dockerfile
Created January 24, 2023 23:14
Python Pillow build on Alpine
FROM python:3.11-alpine3.17
ENV PATH=$PATH:$HOMEAPP/.local/bin
ENV PYTHONPATH=$HOMEAPP:$PROJECT_NAME
# Python packages build dependencies
RUN apk add --no-cache --virtual .build-dependencies \
# Essentials
gcc musl-dev openssl-dev openssl \
# Pillow / PIL build dependencies
@douglasmiranda
douglasmiranda / admin.py
Created January 12, 2021 22:02
Django Admin Inline / Access parent object/instance of an Inline
# Let's say you want to access the Collection instance for a Image in a Django Admin Inline
from django.contrib import admin
from app.models import Image, Collection
class ImageInline(admin.StackedInline):
model = models.Image
extra = 1
@douglasmiranda
douglasmiranda / toasts.css
Last active December 8, 2022 19:29
Bootstrap Toasts - Top Right Fixed (+ Fix toast-container overlaping content)
/* https://getbootstrap.com/docs/5.0/components/toasts/ */
.toast-container {
position: fixed;
right: 20px;
top: 20px;
}
.toast:not(.showing):not(.show) {
display: none !important;
@douglasmiranda
douglasmiranda / tagify.js
Created January 7, 2021 16:57
Tagify: Format for server side comma separated / on form changes event / jQuery example
jQuery(document).ready(function ($) {
$input = $('#my-form')
.tagify()
.on('change', function (e, tagData) {
if (tagData === undefined) {
return;
}
// string [{"value":"test"}', '{"value":"test2"}] to JSON Object
var tags = JSON.parse(tagData);
// Converts into a simple array ["test", "test2"], then convert to string "test,test2"