Skip to content

Instantly share code, notes, and snippets.

Avatar
☠️

Santiago Espinosa Saigesp

☠️
View GitHub Profile
@Saigesp
Saigesp / nginx-proxy-pass
Last active May 21, 2020
Nginx proxy pass example to avoid CORS on development
View nginx-proxy-pass
server {
listen 8000;
server_name localhost;
add_header 'Access-Control-Allow-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 / {
proxy_pass https://your.url.com/;
@Saigesp
Saigesp / pre-commit
Last active Jan 12, 2020
git pre-commit hook to run some tests and linters
View pre-commit
# 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 Jan 5, 2020
Custom TestRunner and APITestCase to work with django, mongodb and django rest framework
View django.mongo.testsutils.py
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 Dec 11, 2019
Convert a 3 columns csv to a hierarchical json with d3 sunburst default format
View csv_to_hierarchical_json.py
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
Created Nov 3, 2019
SSH useful commands
View ssh.md

SSH Useful commands

Copy file from server with ssh key and different port

scp -i ~/.ssh/id_rsa.pub -P <port> <user>@<server>:/path/to/remoto/file /path/to/local/output/folder
@Saigesp
Saigesp / geolocorutm.py
Last active Oct 20, 2019
Python script to get longitude and latitude from google maps API or transform from UTM (provided in file)
View geolocorutm.py
# -*- coding: UTF-8 -*-
import csv
import os
import sys
import json
import time
import pyproj
import argparse
from urllib import parse, request
if sys.version_info[0] < 3: raise Exception("Python 3 required")
@Saigesp
Saigesp / activate.bat
Created Oct 4, 2019
Script with useful actions to work with virtualenvwrapper on windows
View activate.bat
set "VIRTUAL_ENV=C:\Users\YOURUSER\Envs\YOURENVNAME"
:: Set variables
set "ENVIRONMENT=develop"
:: Change directory
cd C:\Users\YOURPROJECTPATH
:: Remove __pycache__ folders
for /d /r ".\API" %%a in (__pycache__) do if exist "%%a" rmdir /s /q "%%a"
@Saigesp
Saigesp / image_resize.py
Last active Sep 25, 2019
Python script to resize images, with command line arguments. Adapted from https://gist.github.com/ihercowitz/642650/f01986c0b1ebd04be588b196eb3ffefe9853e113
View image_resize.py
#!/usr/bin/env python
import os
import sys
import argparse
from PIL import Image
"""
Reduce images size
Images are resized keeping the aspect ratio
Usage: python image_resize.py -d /home/images -o /home/output_dir -s 1024 768
@Saigesp
Saigesp / .conkyrc
Last active Nov 2, 2019
Conky configuration file
View .conkyrc
background no
font Snap.se:size=8
xftfont Snap.se:size=8
use_xft yes
xftalpha 0.1
update_interval 3.0
total_run_times 0
own_window yes
own_window_type normal
own_window_transparent yes
@Saigesp
Saigesp / .block
Last active Oct 22, 2018
D3v4 Mean barchart
View .block
4ab7848d451694667830d91712759cc5
You can’t perform that action at this time.