Skip to content

Instantly share code, notes, and snippets.

View hsauers5's full-sized avatar

Harry Sauers hsauers5

View GitHub Profile
@hsauers5
hsauers5 / rc4.py
Created November 30, 2020 18:18
Implementation of RC4 cipher in Python.
# Harry Sauers
# rc4.py
# demo of RC4 encryption algorithm
def key_scheduling(key):
sched = [i for i in range(0, 256)]
i = 0
for j in range(0, 256):
'''
An example of using a variable-length argument list as an argument to a function.
This will return the minimum of all arguments.
Example: variable_min(-1, 2, 4, 6) => -1
'''
def variable_min(*args):
minimum = min(args[0], args[1])
for i in range(2, len(args)):
minimum = min(minimum, args[i])
import datetime
import copy
class IncrementableDate:
def __init__(self, date_time=None, datestring=None, dateformat='%Y%m%d'):
if date_time is not None:
self.value = date_time
elif datestring is not None:
self.value = datetime.datetime.strptime(datestring, dateformat)
from textblob import TextBlob
import nltk
nltk.download('movie_reviews')
nltk.download('punkt')
'''
Note that a key weakness of TextBlob is that it was trained on IMDB movie reviews, and will not pick up on everything a human would.
'''
''' returns the sentiment of provided text '''
import nltk, string
from sklearn.feature_extraction.text import TfidfVectorizer
import requests
from bs4 import BeautifulSoup
import gensim
nltk.download('punkt')
stemmer = nltk.stem.porter.PorterStemmer()
remove_punctuation_map = dict((ord(char), None) for char in string.punctuation)
import alpaca_trade_api
key = 'YOUR_KEY'
secret = 'YOUR_SECRET'
base_url = 'https://paper-api.alpaca.markets'
api = alpaca_trade_api.REST(key, secret, base_url, api_version='v2')
account = api.get_account()
print(account.status)
stock_list = ['AAPL', 'GOOG', 'MSN', 'INTC']
def order_target_percent(api, security, weight, order_type='market', time_in_force='day'):
account = api.get_account()
portfolio_value = float(account.portfolio_value)
current_holdings = 0
try:
current_holdings = api.get_position(security).qty
except alpaca_trade_api.rest.APIError:
current_holdings = 0
import requests
import json
import alpaca_trade_api
tickers_list = []
with open('tickers.txt', 'r+') as tickers_file:
tickers_list = tickers_file.read().splitlines()
tenquant_key = 'FAKE_KEY'
def check_if_sorted(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
return False
arr[j], arr[j+1] = arr[j+1], arr[j]
return True
def make_permutation(n=4):
result = []
for i in range(1, n+1):
result.append(i)
return result
def get_all_pairs(permutation=make_permutation()):
pairs = []
for i in range(0, len(permutation)):