Skip to content

Instantly share code, notes, and snippets.

View geblanco's full-sized avatar

Guillermo Blanco geblanco

View GitHub Profile
@geblanco
geblanco / extract_ipython_code.py
Last active June 25, 2019 12:47
Extracts all the content inside an *.ipynb file and write it to a file of code, non code cells go as comments
import os
import sys
import json
languages = dict(
python=dict(ext='py', comment='#'),
javascript=dict(ext='js', comment='//')
)
if len(sys.argv) < 2:
@geblanco
geblanco / evaluate-squad-v2.0.py
Last active December 4, 2019 10:12
Modified version of SQuAD 2.0 evaluate script to save exact and f1 scores for each question.
"""Official evaluation script for SQuAD version 2.0.
In addition to basic functionality, we also compute additional statistics and
plot precision-recall curves if an additional na_prob.json file is provided.
This file is expected to map question ID's to the model's predicted probability
that a question is unanswerable.
"""
import argparse
import collections
import json
@geblanco
geblanco / generateSquareIcon.js
Last active May 25, 2020 12:07
Generate a square icon of any given size with a given text. Useful to easily create favicons based on text. Used in https://github.com/m0n0l0c0/Pomodoro
// requires canvas, npm i canvas
var Canvas = require('canvas')
var fs = require('fs')
// Constants
var DIM = { width : 24, border : 1.3, font : 14 }
var COLOR = { light: '#ec9a97', text:'#3189cc' , border:'#e13d35' }
function paintCircularText(filePath=null, text=null, fill=false, border=true, callback=null){
5a6,8
> import json
>
> import sklearn.metrics as metrics
6a10,11
> from sklearn.metrics import precision_recall_curve
> from dvc.api import make_checkpoint
10c15
< if len(sys.argv) != 3:
---
@geblanco
geblanco / sklearn.classification_report.py
Created March 5, 2021 12:44
Pretty print classification report from a previous classification report dict (Useful when saving dict to disk and later print without recalculating everything). Not tested for multi labeled data
# extracted from: https://github.com/scikit-learn/scikit-learn/blob/0fb307bf3/sklearn/metrics/_classification.py#L1825
def classification_report(data_dict):
"""Build a text report showing the main classification metrics.
Read more in the :ref:`User Guide <classification_report>`.
Parameters
----------
report : string
Text summary of the precision, recall, F1 score for each class.
Dictionary returned if output_dict is True. Dictionary has the
@geblanco
geblanco / interactive_map_from_addresses.py
Created May 5, 2021 11:28
Simple script to paint in an interactive map a set of addreses from a csv file.
# !pip install requests urllib3 geopy pandas folium
# partially taken from:
# https://towardsdatascience.com/pythons-geocoding-convert-a-list-of-addresses-into-a-map-f522ef513fd6\
import requests
import json
import urllib
from geopy.geocoders import Nominatim, GoogleV3
import pandas as pd
import folium
@geblanco
geblanco / process_singleton.py
Last active August 23, 2021 12:03
A singleton class that syncronizes across processes
# requires: zmq
import sys
import zmq
import threading
from time import sleep
from filelock import FileLock, Timeout
@geblanco
geblanco / obs_project_scaffold.py
Last active May 18, 2023 16:37
Project scaffold for Obsidian. It is a simple structure containing a Readme, Meetings, Todo and Index files.
#!/bin/env python
import argparse
from pathlib import Path
from shutil import rmtree
from typing import Any, List, Optional
# You must override this value!
PROJS_BASE = None
DEF_FILES = ["index", "readme", "todo", "meetings"]
FILES_W_CONTEXT = ["todo", "meetings"]
@geblanco
geblanco / upgrade_py_pkgs.sh
Last active November 20, 2023 13:24
Script to automatically upgrade all python packages given a requirements.txt or a pyproject.toml (works over conda)
#!/bin/bash
# If a requirements.txt file is supplied, it will be updated with the latest versions of each package.
# If a pyproject.toml is required, package upgrades will just be printed.
echo "Careful:"
echo " - Conda is required"
echo " - If any of your PYPY packages contain the strin 'http', it is possible that it gets astray, manually inspect it"
env_name="pkgs_upgrade"
@geblanco
geblanco / gen_init.py
Last active October 25, 2022 13:01
Naive __init__.py generator
"""Generate __init__.py for a given folder
Very naive generator, just parses the AST of every subfile in the provided folder to get the list of exported variables.
ToDo :=
- Recursively parse subfolders and previous __init__.py files
- Improve pkg base adding
"""
import os
import ast