Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
mariocesar /
Last active November 9, 2023 12:29
Git useful commands

Searching for a text in all the history of the repo.

function grep_git_history() {
  local term="${@}"
  git grep -e "${term}" $(git log -S "${term}" --pretty=format:"%H")

grep_git_history 'var = 1'
grep_git_history '{% url'
mariocesar /
Created April 8, 2018 21:48
Bash script that runs forever and wait for signals.
#!/usr/bin/env bash
catch_kill() {
echo "Caught SIGKILL signal!"
kill -KILL "$pid" 2>/dev/null
catch_term() {
echo "Caught SIGTERM signal!"
kill -TERM "$pid" 2>/dev/null
mariocesar / access.lua
Last active November 5, 2023 07:16
Nginx Lua script redis based for Basic user authentication
View access.lua
function password_encode(password)
local bcrypt = require 'bcrypt'
return bcrypt.digest(password, 12)
function check_password(password, encoded_password)
local bcrypt = require 'bcrypt'
return bcrypt.verify(password, encoded_password)
mariocesar /
Last active November 4, 2023 03:03
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())
mariocesar /
Created November 25, 2012 06:08
Update a Route53 Record if your public IP changes. Like DynDNS
$ sudo pip install boto dnspython
Edit ~/.boto to use your AWS credentials
import time
import sys
mariocesar /
Last active May 24, 2023 10:12
Django load secrets and settings from a safe file

This util manage to load django settings from a config file that contain sensitive information such as cache, database and project passwords/secrets.

The util also check the permissions file to be safe, and the existence of the SECRET_KEY variable, if no file is found it will automatically create a file with a random SECRET_KEY value.

How to use it?

Add the method load_environment_file into your code, an use it in your django

mariocesar / api.js
Created September 26, 2017 04:21
Axios single configured instance
View api.js
import axios from "axios";
const singleton = Symbol();
const singletonEnforcer = Symbol();
function readCookie(name) {
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
mariocesar / main.yml
Created May 7, 2023 20:11
My espanso triggers configuration
View main.yml
- trigger: "!today"
replace: "{{mydate}}"
- name: mydate
type: date
format: "%d/%m/%Y"
- trigger: "!now"
mariocesar / index.html
Last active April 16, 2023 02:49
Example Python + Websockets to emulate tail -f
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tail </title>
body {font-family: monospace;}
p{ margin: 0;}
ul{padding: 0;}
mariocesar /
Created April 5, 2023 14:20
A simple daemon script that I used for debugging running Docker containers in AWS ECS.


{"name": "worker", "level": "INFO", "message": "Service start", "timestamp": "2023-04-05 14:04:48.974687279", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "ping", "timestamp": "2023-04-05 14:04:48.975945036", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Received signal: SIGTERM", "timestamp": "2023-04-05 14:04:53.979013322", "ip": "", "pid": 7}
{"name": "worker", "level": "INFO", "message": "Stopping", "timestamp": "2023-04-05 14:04:53.980930837", "ip": "", "pid": 7}