Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar
Focusing

Mario-César mariocesar

Focusing
View GitHub Profile
@mariocesar
mariocesar / README.md
Last active November 9, 2023 12:29
Git useful commands
View README.md

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
mariocesar / wait_for_signals.sh
Created April 8, 2018 21:48
Bash script that runs forever and wait for signals.
View wait_for_signals.sh
#!/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
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)
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 4, 2023 03:03
Django admin decorator to create a confirmation form action, like the default delete action works
View admin.py
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
mariocesar / dyndns_route53.py
Created November 25, 2012 06:08
Update a Route53 Record if your public IP changes. Like DynDNS
View dyndns_route53.py
"""
Requeriments:
$ sudo pip install boto dnspython
Edit ~/.boto to use your AWS credentials
"""
import time
import sys
@mariocesar
mariocesar / README.md
Last active May 24, 2023 10:12
Django load secrets and settings from a safe file
View README.md

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
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
mariocesar / main.yml
Created May 7, 2023 20:11
My espanso triggers configuration
View main.yml
matches:
- trigger: "!today"
replace: "{{mydate}}"
vars:
- name: mydate
type: date
params:
format: "%d/%m/%Y"
- trigger: "!now"
@mariocesar
mariocesar / index.html
Last active April 16, 2023 02:49
Example Python + Websockets to emulate tail -f
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tail </title>
<style>
body {font-family: monospace;}
p{ margin: 0;}
ul{padding: 0;}
@mariocesar
mariocesar / README.md
Created April 5, 2023 14:20
A simple daemon script that I used for debugging running Docker containers in AWS ECS.
View README.md

Outputs

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