Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
@mariocesar
mariocesar / README.md
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
mariocesar / api.js
Created September 26, 2017 04:21
Axios single configured instance
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
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
<!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.

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}
@mariocesar
mariocesar / README.md
Last active April 5, 2023 14:18
Docker command and utils.

Useful Docker commands

Show all the files in a docker volume, use: docker-list-volume-contents volume_name

function docker-list-volume-contents() {
    docker run --rm -v ${1}:/data -it alpine find /data -type f
}
@mariocesar
mariocesar / telegram-notify
Created April 5, 2017 04:22
Send telegram messages! send text, photos, videos, stickers, and documents within the console
#!/usr/bin/env python
import argparse
import os
import sys
import requests
apiurl = 'https://api.telegram.org/bot{token}/{method}'.format
@mariocesar
mariocesar / email_parse.py
Last active February 25, 2023 13:41
Parse a raw email
"""
$ cat source.email | python email_parse.py
"""
import fileinput
import email
from email.Utils import parseaddr
def parse():
raw_message = ''.join([line for line in fileinput.input()])
@mariocesar
mariocesar / README.md
Last active February 9, 2023 15:12
NPM and Javascript fixes
import sys
import math
import re
def verhoeff(num, times):
d = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],