Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
@mariocesar
mariocesar / access.lua
Last active December 12, 2025 17:10
Nginx Lua script redis based for Basic user authentication
function password_encode(password)
local bcrypt = require 'bcrypt'
return bcrypt.digest(password, 12)
end
function check_password(password, encoded_password)
local bcrypt = require 'bcrypt'
return bcrypt.verify(password, encoded_password)
end
@mariocesar
mariocesar / admin.py
Last active November 23, 2025 20:43
Django admin decorator to create a confirmation form action, like the default delete action works
from .models import Post, Category
from .decorators import action_form
class PostCategoryForm(forms.Form):
title = 'Update category for the selected posts'
myfile = forms.FileField()
category = forms.ModelChoiceField(queryset=Category.objects.all())
<script>
import { onMount } from "svelte";
let wrapper;
let copied = false;
async function copyText() {
const text = wrapper.innerText.trim();
try {
await navigator.clipboard.writeText(text);

Usage

export AWS_BUCKET_ARN=...
export WEBSITE_DOMAIN=tugerente.com
./sync-bank.sh

Make sure

@mariocesar
mariocesar / README.md
Created March 10, 2025 16:11
Apagar/Encender/Reiniciar instancias EC2 con Policy. Util para gitlab CI

Comandos AWS CLI:

Apagar una instancia EC2 por ID y esperar a que se detenga:

aws ec2 stop-instances --instance-ids i-1234567890abcdef0
aws ec2 wait instance-stopped --instance-ids i-1234567890abcdef0

Encender una instancia EC2 por ID y esperar a que inicie:

@mariocesar
mariocesar / README.md
Created February 26, 2025 15:30
A django template tag that generates SVG icons. Useful to create svg favicons with emojis

Usage

{% load utils_tags %}
{% svgicon '🕶️' 'rounded square' '#ffccff' as icon %}
<link rel="icon" href="data:image/svg+xml,{{ icon | urlencode }}">

Will make a nice favicon of sunglases with a pink background.

@mariocesar
mariocesar / README.md
Last active February 22, 2025 20:20
React-style components for Django templates, but only on Django Template. Simple, familiar, and good enough for most projects

Why?

I built this because I wanted React's component patterns in Django templates without switching to a JavaScript frontend. When you use Jinja2 you have macros and that work similar. This will bring the Jinja2 macro experience.

No complex setup, no build process, just practical template components when you need them.

How It Works

Two template tags, that's it:

@mariocesar
mariocesar / README.md
Last active February 10, 2025 20:14
TimestampStateField custom Django field that creates a timestamp-boolean pair

The TimestampStateField creates two related fields in your Django models:

  1. A timestamp field (DateTimeField) that records when a state changed
  2. A corresponding boolean field that indicates the current state

The goal is to do state-tracking where you want to know both IF something is in a state and WHEN it entered that state. For example, tracking if a user is active and when they became active. And with that also gain the benefits of faster DB access and creating more efficient db indexes.

Here's how it works through an example:

@mariocesar
mariocesar / README.md
Last active February 4, 2025 03:35
Check network can resolve and access a host with port

Run me like this. Or maybe not! it's dangerous!

curl -sL "https://gist.github.com/mariocesar/b628c91e7b00cca0dca371ac2d54544c/raw/script.py?v=$(date +%s)" | python3 - google.com:443
@mariocesar
mariocesar / README.md
Last active January 31, 2025 21:20
Useful oneliners that I often forget. #terminal #python #shell

bash

Get a sha256sum hash for all the given files, similar to GitHub Action hashFiles function.

hashFiles() {
    local files=("$@")
    if [[ ${#files[@]} -eq 0 ]]; then
        echo "Error: No files provided" >&2
 return 1