Skip to content

Instantly share code, notes, and snippets.

View Saigesp's full-sized avatar
🙄

Santiago Espinosa Saigesp

🙄
View GitHub Profile
@Saigesp
Saigesp / nginx-proxy-pass
Last active December 13, 2021 15:54
Nginx proxy pass example to avoid CORS on development
server {
listen 8008;
server_name localhost;
add_header 'Access-Control-Allow-Origin' '$http_origin';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
location / {
@Saigesp
Saigesp / CsvDB.py
Created January 26, 2022 00:09
POC to use csvs as database
import os
import csv
DATA_FOLDER = os.path.join('data')
class CsvDB:
def __init__(self, dbname: str, verbose: bool=True):
self.verbose = verbose
self.dbname = dbname
os.makedirs(os.path.join(DATA_FOLDER, self.dbname), exist_ok=True)
@Saigesp
Saigesp / merge.py
Created July 19, 2023 22:40
Merge two csvs
import csv
from pathlib import Path
ROOT = Path(__file__).resolve().parent
INPUT_OLD = ROOT / "old.csv"
INPUT_NEW = ROOT / "new.csv"
OUTPUT = ROOT / "final.csv"
# csv data format:
# email,zip_code
@Saigesp
Saigesp / countries.json
Created August 3, 2023 15:26 — forked from devhammed/countries.json
Countries with Name, Dial Code, Emoji Flag and ISO Code
[
{
"name": "Afghanistan",
"flag": "🇦🇫",
"code": "AF",
"dial_code": "+93"
},
{
"name": "Åland Islands",
"flag": "🇦🇽",
@Saigesp
Saigesp / responsive_images.py
Created August 11, 2023 19:05
Python responsive images
# -*- coding: utf-8 -*-
# Create multiple responsive images to generate a srcset
#
# Usage example:
# b64_image = base64.b64decode(b64_image.split(",")[1]) # from base64-encoded image
# file_name = "lorem.ipsum.jpeg"
# srcset_results = []
# for img in create_srcset_images(BytesIO(b64_image), widths):
# srcset_name = f'{".".join(file_name.split(".")[:-1])}-{img["width"]}w.{img["format"]}'
# result = upload_file_to_external_service(img["image"], srcset_name) # <--- it must return a URL
@Saigesp
Saigesp / bashrc
Last active September 3, 2023 16:21
# Virtualenv
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '