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
# 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): |
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
''' | |
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]) |
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 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) |
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 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 ''' |
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 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) |
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 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'] |
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 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 | |
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 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' |
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 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 |
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 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)): |
NewerOlder