This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
(7035, 0.145), | |
(20100-7035, 0.285), | |
(40200-20100, 0.37), | |
(80000-40200, 0.45), | |
("inf", 0.48) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words="$(echo | k2pdfopt nickel2016.pdf -h 20000 -w 1200 -pl 100 -pr 100 | grep -Eo "[0-9]* words" | grep -Eo "[0-9]*")" | |
let "reading_time = $words * 1.1 / 275" | |
reading_mins="$(printf "%.0f" $reading_time)" | |
if [[ $reading_mins -le 60 ]]; then | |
echo "approx reading time: $reading_mins mins" | |
else | |
let "hours = $reading_mins / 60" | |
let "mins = $reading_mins % 60" | |
echo "approx reading time: $hours h $mins mins" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
import ctypes, re, sys | |
## Partial interface to ptrace(2), only for PTRACE_ATTACH and PTRACE_DETACH. | |
c_ptrace = ctypes.CDLL("libc.so.6").ptrace | |
c_pid_t = ctypes.c_int32 # This assumes pid_t is int32_t | |
c_ptrace.argtypes = [ctypes.c_int, c_pid_t, ctypes.c_void_p, ctypes.c_void_p] | |
def ptrace(attach, pid): | |
op = ctypes.c_int(16 if attach else 17) #PTRACE_ATTACH or PTRACE_DETACH | |
c_pid = c_pid_t(pid) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retirement(s,y,n,r): | |
""" | |
Considering: | |
- You have 0 debt | |
- You make y per year (yearly income) | |
- You can save a fraction s per year | |
- You can invest at a r-1 yearly interest | |
This function returns the amount you have accumulated after n years. | |
This means you can live with (1-s)*y per year. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.metrics import mutual_info_score | |
def calc_MI(x, y, bins): | |
c_xy = np.histogram2d(x, y, bins)[0] | |
mi = mutual_info_score(None, None, contingency=c_xy) | |
return mi | |
def calc_MI_matrix(A, bins) | |
n = A.shape[1] |