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 April 12, 2024 14:09
Prueba de revisión. Code Challenge. Programming Skills

Instrucciones para el candidato

Adjunto encontrarás un script de Python llamado script.py y un archivo CSV llamado data.csv.

  1. El archivo data.csv contiene datos de productos con las siguientes columnas: product_id, name, category_name, price, quantity.
  2. El script script.py carga los datos del archivo CSV, calcula la media, el promedio y la moda de los precios de los productos agrupados por categoría, y muestra los resultados en la consola.
  3. Tu tarea es revisar el código del script script.py y proponer cambios, mejoras o identificar cualquier problema, similar a lo que harías en una revisión a un Merge Request.
  4. Prepara tus comentarios, sugerencias y mejoras propuestas para discutirlas durante la siguiente entrevista.

El objetivo de este ejercicio es evaluar tus habilidades para identificar problemas, proponer mejoras y más que todo comunicar tus ideas de manera efectiva.

@mariocesar
mariocesar / admin.py
Last active December 28, 2023 19:17
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
mariocesar / telegram.py
Created June 13, 2017 19:52
Send a telegram message with python requests
import requests
api_url = 'https://api.telegram.org/bot{token}/{method}'.format
TELEGRAM_ACCESS_TOKEN = os.environ.get('TELEGRAM_ACCESS_TOKEN', None)
def telegram_command(name, data):
url = api_url(token=TELEGRAM_ACCESS_TOKEN, method=name)
return requests.post(url=url, json=data)
@mariocesar
mariocesar / README.md
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
mariocesar / wait_for_signals.sh
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
mariocesar / access.lua
Last active November 5, 2023 07:16
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 / dyndns_route53.py
Created November 25, 2012 06:08
Update a Route53 Record if your public IP changes. Like DynDNS
"""
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

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);
}