Skip to content

Instantly share code, notes, and snippets.

Guilherme Pires colobas

  • Seattle
Block or report user

Report or block colobas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@colobas
colobas / install-all.py
Created Jul 4, 2019
script to install/uninstall all python packages in a folder, in editable mode
View install-all.py
import os
import subprocess
import sys
import argparse
def install_all():
path = os.path.dirname(os.path.abspath(__file__))
packages = [p for p in next(os.walk(path))[1]
if "setup.py" in os.listdir(p)]
@colobas
colobas / remote_import.py
Created May 24, 2019
util to import remote modules. can be used with gists, for example.
View remote_import.py
import tempfile
import requests
from importlib.machinery import SourceFileLoader
def import_remote_module(module_name, url):
"""
import a file from a URL, given by `url`
---
returns the imported module
@colobas
colobas / bins.py
Last active Nov 23, 2018
Compute the recommended bin size for a histogram, according to the Freedman-Diaconis rule
View bins.py
def bin_size(x):
"""
https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
"""
return (2 * (np.nanquantile(x, 0.75) - np.nanquantile(x, 0.25)) /
np.cbrt(len(x[~np.isnan(x)])))
View longest_common_substring.py
from difflib import SequenceMatcher
def longestSubstring(str1,str2):
# initialize SequenceMatcher object with
# input string
seqMatch = SequenceMatcher(None,str1,str2)
# find match of longest sub-string
# output will be like Match(a=0, b=0, size=5)
View xgboost_skopt.py
from skopt.space import Real, Integer
from skopt.utils import use_named_args
from skopt import gp_minimize
from xgboost import XGBClassifier
from sklearn.model_selection import cross_val_score
cls = XGBClassifier()
View plot_umap.py
import umap
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
def draw_umap(data, n_neighbors=15, min_dist=0.1, n_components=2, metric='euclidean', title='', color=None):
fit = umap.UMAP(
n_neighbors=n_neighbors,
min_dist=min_dist,
n_components=n_components,
View loading.py
import time, sys
while True:
blah="⡿⣟⣯⣷⣾⣽⣻⢿"
for l in blah:
_ = sys.stdout.write(l)
_ = sys.stdout.flush()
_ = sys.stdout.write('\b')
time.sleep(0.2)
View passman_bak.py
from selenium import webdriver
import pyperclip
driver = webdriver.Chrome()
driver.get("http://192.168.1.218")
input("AUTHENTICATE AND GO TO PASSMAN PAGE")
table = driver.find_elements_by_class_name("credential-table")[0]
rows = table.find_elements_by_tag_name("tr")
View pretty_print_dict.py
# credits to: https://stackoverflow.com/a/26209900
def pretty(value, htchar='\t', lfchar='\n', indent=0):
nlch = lfchar + htchar * (indent + 1)
if type(value) is dict:
items = [
nlch + repr(key) + ': ' + pretty(value[key], htchar, lfchar, indent + 1)
for key in value
]
return '{%s}' % (','.join(items) + lfchar + htchar * indent)
elif type(value) is list:
View escaloes.txt
[
(7035, 0.145),
(20100-7035, 0.285),
(40200-20100, 0.37),
(80000-40200, 0.45),
("inf", 0.48)
]
You can’t perform that action at this time.