Skip to content

Instantly share code, notes, and snippets.

Kasper Fredenslund kasperfred

Block or report user

Report or block kasperfred

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
def numerical_derivative(func, func_input, respect_to_index=0, h=0.0001):
"""Compute the numerical derivative of a function
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
# 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
kasperfred /
Created Jun 26, 2017
Small utility that lets you compute and compare cryptographically secure password hashes
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
String: password
kasperfred /
Created Jun 22, 2017
send email using python
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
kasperfred /
Created Feb 13, 2017
Simple encode/decode functions (cryptographically not safe)
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_string = "".join(encoded_chars)
from PIL import Image
import numpy as np
img ='img.jpg', "r")
pixels = np.asarray(img)
add = [0,0,0]
index = 0
for row in pixels:
kasperfred /
Last active Jan 6, 2017
Weighted random sentence constructor from dictionary words and weights
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 = []
You can’t perform that action at this time.