Skip to content

Instantly share code, notes, and snippets.

View Saigesp's full-sized avatar
🙄

Santiago Espinosa Saigesp

🙄
View GitHub Profile
@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 / .conkyrc
Last active November 2, 2019 23:06
Conky configuration file
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 / geolocorutm.py
Last active October 20, 2019 19:06
Python script to get longitude and latitude from google maps API or transform from UTM (provided in file)
# -*- 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 October 4, 2019 12:55
Script with useful actions to work with virtualenvwrapper on windows
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 / sublime_shortcuts.json
Last active April 12, 2019 18:48
Sublime3 Shortcuts
[
{ "keys": ["ctrl+alt+b"], "command": "toggle_comment", "args": { "block": true } },
{ "keys": ["ctrl+alt+p"], "command": "autoprefixer" },
{ "keys": ["ctrl+alt+c", "ctrl+alt+o", "ctrl+alt+n"], "command": "insert_snippet", "args": {"contents": "console.log($0);"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
{ "keys": ["ctrl+alt+c", "ctrl+alt+o", "ctrl+alt+n"], "command": "insert_snippet", "args": {"contents": "console.log(${0:$SELECTION});"}, "context":
@Saigesp
Saigesp / translate_ine_projection.py
Created September 19, 2018 18:29
Convert between projections epsg:25830 and epsg:4326 used in INE (Instituto Nacional de Estadística, Spain)
# returns latlng
def get_maxmin_latlon_region(region):
lon_max = -180
lon_min = 180
lat_max = -90
lat_min = 90
if region['type'] == 'Polygon':
for polygon in region['coordinates']:
for point in polygon:
@Saigesp
Saigesp / sublime-keymap.js
Last active December 12, 2018 12:03
Default (Linux).sublime-keymap
[
{ "keys": ["ctrl+alt+b"], "command": "toggle_comment", "args": { "block": true } },
{ "keys": ["ctrl+alt+p"], "command": "autoprefixer" },
// console.log()
{ "keys": ["ctrl+alt+c", "ctrl+alt+o", "ctrl+alt+n"], "command": "insert_snippet", "args": {"contents": "console.log($0);"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
@Saigesp
Saigesp / .block
Last active October 26, 2018 17:59
D3v4 Stacked barchart
f2605e92dff3a976d97ae6027d07f6b5