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 | |
1/(0 or np.nan) # Avoid ZeroDivisionError | |
def get_odds(bet, profit): | |
_ = lambda x: x + min(-(x % 5), 5 - (x % 5), key=abs) | |
return round(_(100*(max(profit, bet) / min(bet, -profit, key=abs)))) | |
assert get_odds(1, 1.25) == 125 | |
assert get_odds(1, 1.32) == 130 | |
assert get_odds(1, 0.8) == -125 |
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
watch -d -n 0.5 free -m | |
tail -lf /var/log/log.txt | |
sudo service service@{1..10} restart |
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
# Based on https://github.com/miketheman/pytest-socket/blob/master/pytest_socket.py | |
import socket | |
import requests | |
_true_socket = socket.socket | |
def _blank(*args, **kwargs): | |
raise ValueError('socket') |
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 random | |
import tempfile | |
import os | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def r_sqr(yi, fi): | |
ss_res = np.sum((yi - fi) ** 2) | |
ss_tot = np.sum((yi - np.mean(yi)) ** 2) | |
if ss_tot == 0: |
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
https://cvxopt.org/examples/index.html |
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
pts = [(-1, 1), (0, 1), (1, 0), (2, 2), (3, 3), (4, 2)] | |
def fd(*points, values=None): | |
if values is None: | |
values = [] | |
if len(points) == 2: | |
x0, y0 = points[0] | |
x1, y1 = points[1] | |
val = (y1 - y0) / (x1 - x0) | |
values.append(val) |
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 scipy.spatial import cKDTree | |
import time | |
import numpy as np | |
np.random.seed(42) | |
st = time.time() | |
a = np.random.rand(40000, 25) | |
b = np.random.rand(40000, 25) | |
t0 = cKDTree(a) |
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
# Automatically sets upstream tracking | |
git config --global push.default current | |
# Autocomplete | |
brew install git bash-completion | |
# Create local branch which tracks existing remote branch | |
# https://stackoverflow.com/a/9537923/8927098 | |
git checkout --track origin/<branch_name> |
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
wget http://ftp.wayne.edu/apache/spark/spark-2.4.4/spark-2.4.4-bin-hadoop2.7.tgz | |
# or another mirror from https://www.apache.org/dyn/closer.lua/spark/spark-2.4.4/spark-2.4.4-bin-hadoop2.7.tgz | |
tar -xzf spark-2.4.4-bin-hadoop2.7.tgz | |
export SPARK_HOME=/vagrant/spark-2.4.4-bin-hadoop2.7 | |
export PATH=$SPARK_HOME/bin:$PATH |
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: https://math.stackexchange.com/a/2647450/635480 """ | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_rotated_ellipse(cx=1, cy=2, rx=3, ry=0.5, theta=np.pi/4): | |
alpha = np.linspace(0, 2*np.pi, 100) | |
x = rx*np.cos(alpha)*np.cos(theta) - ry*np.sin(alpha)*np.sin(theta) + cx | |
y = rx*np.cos(alpha)*np.sin(theta) + ry*np.sin(alpha)*np.cos(theta) + cy | |
plt.plot(x, y) |