Skip to content

Instantly share code, notes, and snippets.

View Saigesp's full-sized avatar
🙄

Santiago Espinosa Saigesp

🙄
View GitHub Profile
@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 / 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 / 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 / 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 / InputNumber.vue
Last active July 29, 2021 11:14
Vue2 ElementUI custom InputNumber to add "." as thousand separator and "," as decimal separator
<template>
<div
@dragstart.prevent
:class="[
'el-input-number',
inputNumberSize ? 'el-input-number--' + inputNumberSize : '',
{ 'is-disabled': inputNumberDisabled },
{ 'is-without-controls': !controls },
{ 'is-controls-right': controlsAtRight }
]">
@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 / pre-commit
Last active January 12, 2020 23:14
git pre-commit hook to run some tests and linters
# Run django test before commit, abort if fails
python manage.py test || exit 1
# Run vue tests and linter before commit, abort if fails
EXIT_STATUS=0
npm run lint || EXIT_STATUS=$?
npm run test:unit || EXIT_STATUS=$?
exit $EXIT_STATUS
@Saigesp
Saigesp / django.mongo.testsutils.py
Created January 5, 2020 15:42
Custom TestRunner and APITestCase to work with django, mongodb and django rest framework
from django.test.runner import DiscoverRunner
from django.conf import settings
from mongoengine import connect, disconnect, get_connection
from pymongo import MongoClient
from rest_framework.test import APITestCase
class TestRunner(DiscoverRunner):
"""
Custom test runner for mongoengine
"""
@Saigesp
Saigesp / csv_to_hierarchical_json.py
Last active December 11, 2019 21:55
Convert a 3 columns csv to a hierarchical json with d3 sunburst default format
import csv
import json
import itertools
"""
Convert a 3 columns CSV to a hierarchical JSON
with d3 sunburst default format.
Duplicated CSV column values are nested on the JSON as follows:
input file (CSV):
@Saigesp
Saigesp / ssh.md
Last active January 27, 2021 12:03
SSH useful commands

SSH Useful commands

SCP Commands

Copy file from local to remote

scp file.txt <user>@<server>:/path/to/remote/folder

Copy folder from local to remote