This file contains 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 numerical_derivative(func, func_input, respect_to_index=0, h=0.0001): | |
"""Compute the numerical derivative of a function | |
Args: | |
func (function): A function | |
func_input (list): A list of inputs given to the function | |
respect_to_index (int): The index of the value the derivative is calculated with respect to | |
h (float): the amount to tweak the function with to compute the gradient | |
Returns: |
This file contains 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 a bunch of models | |
from sklearn.linear_model import LinearRegression | |
from sklearn.svm import SVR | |
from sklearn.neighbors import KNeighborsRegressor | |
from sklearn.tree import DecisionTreeRegressor | |
from sklearn.ensemble import GradientBoostingRegressor | |
from sklearn.gaussian_process import GaussianProcessRegressor | |
from sklearn.cross_decomposition import PLSRegression | |
from sklearn.ensemble import AdaBoostRegressor |
This file contains 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
""" | |
Small utility that lets you compute and compare cryptographically secure password hashes | |
""" | |
def hash_password(password, salt=None, iterations=100000): | |
""" | |
Compute hash for a string using SHA1 | |
input: | |
String: password |
This file contains 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 send_email(user, pwd, recipient, subject, body): | |
import smtplib | |
gmail_user = user | |
gmail_pwd = pwd | |
FROM = user | |
TO = recipient if type(recipient) is list else [recipient] | |
SUBJECT = subject | |
TEXT = body |
This file contains 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 base64 | |
def encode(key, string): | |
encoded_chars = [] | |
for i in xrange(len(string)): | |
key_c = key[i % len(key)] | |
encoded_c = chr(abs(ord(string[i]) + ord(key_c) % 256)) | |
encoded_chars.append(encoded_c) | |
encoded_string = "".join(encoded_chars) |
This file contains 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 PIL import Image | |
import numpy as np | |
img = Image.open('img.jpg', "r") | |
pixels = np.asarray(img) | |
add = [0,0,0] | |
index = 0 | |
for row in pixels: |
This file contains 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 numpy | |
dict_weighted = {"word1" : 0.1, "word2" : 0.9} # keys = words, values = weights. Values must sum to 1 | |
def create_d_sentence(dict_weighted): | |
length = random.randint(5,15) | |
keys = [] | |
values = [] | |
NewerOlder