Skip to content

Instantly share code, notes, and snippets.

View dyerrington's full-sized avatar
💭
I may be slow to respond.

David Yerrington dyerrington

💭
I may be slow to respond.
View GitHub Profile
@dyerrington
dyerrington / basic_python_efficiency.ipynb
Last active October 21, 2024 22:03
Efficient List Creation in Python: Comparing .append(), +=, List Comprehension, and Duplication Description: This notebook explores different approaches to creating and modifying lists in Python, comparing the efficiency of methods like .append(), +=, list comprehension, and list duplication ([0] * n). Includes insights on performance and trade-…
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import time
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
class ApiClient:
def __init__(self):
pass
@RateLimiter(rate_limit=5, rate_unit="seconds")
def make_request(self, data):
import regex
import unicodedata
# Precompile the regex pattern for removing unwanted characters (do this outside of any iteration since it's an expensive operation)
remove_pattern = regex.compile(r'[\p{P}\p{S}\p{M}\p{C}\p{Z}]+', regex.UNICODE)
def clean_unicode_text(text):
# Normalize the Unicode text
normalized_text = unicodedata.normalize('NFKD', text)
@dyerrington
dyerrington / google_translate_api_demo.ipynb
Last active November 9, 2022 19:35
Google Translate API demo tested with Python 3.9.x. I want to say this may not work so well with Python 3.10 for some reason but if you follow the guide I referenced otherwise, you should be in business. Highly recommended that you create a new Python environment before engaging with any serious development if you haven't done so.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Installation

It's recommended that you install the requirements for these t5 models in a new environment since they are known to conflict with common Python package requirements in the scientific Python Stack.

Conda ENV Setup

Create

conda create -n nlp-t5
import finplot as fplt
import yfinance
df = yfinance.download('AAPL')
d = df[['Open', 'Close', 'High', 'Low']].reset_index(drop=True)
fplt.candlestick_ochl(d)
fplt.show()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dyerrington
dyerrington / m1_fix_5.1.2.event_loops_py.patch
Last active December 12, 2020 18:50
Jupyter restarting patch fix for Apple M1 Processors.
--- eventloops.py-orig 2020-12-12 10:22:08.633178000 -0800
+++ eventloops.py 2020-12-12 10:22:56.335735100 -0800
@@ -20,7 +20,7 @@
Checks if we are on OS X 10.9 or greater.
"""
- return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9')
+ return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9') and platform.mac_ver()[2] != 'arm64'
@dyerrington
dyerrington / multi-roc_curve.py
Last active September 5, 2020 00:48
I can't tell you how many times I've plotted a roc curve for a multi-class problem from scratch. Too many times. I decided to make this gist to demonstrate how to implement a multi-class ROC (Receiver Operator Characteristic) plot in the most simple manner possible using Python.
## import any sklearn models and collect predictions / probabilities beforehand
import matplotlib.pyplot as plt
from cycler import cycler
## Line color config -- rather than create a structure with a finite color palette, use your own to cycle through a list.
default_cycler = (cycler(color=['r', 'g', 'b', 'y']) +
cycler(linestyle=['-', '--', ':', '-.']))
plt.rc('axes', prop_cycle = default_cycler)
@dyerrington
dyerrington / gist:6850e459c37b3f01e4049505c1634256
Created July 13, 2020 16:42
Debugged fetch_states for Cesar
def fetch_states():
"""
Return all <option> values for the <select> element with all states.
"""
data = {}
states = tree.xpath('//select[@name="state"]')
try:
for state in states[0].xpath('option'):
data[state.attrib['value']] = state.text_content()
except: