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 PIL import Image, ImageEnhance | |
| import warnings | |
| try: import matplotlib | |
| except: warnings.warn('matplotlib not available.') | |
| __all__ = ['PixelfyOps', 'Pixelfy'] | |
| class PixelfyOps: | |
| """ | |
| Stateless toolkit of image processing operations for the pixel art effect. |
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 cv2 | |
| import numpy as np | |
| import sklearn.cluster | |
| import matplotlib.pyplot as plt | |
| # https://pypi.org/project/MemePy/ | |
| # https://kitchencrafthubs.com/how-do-you-make-deep-fried-pictures/ | |
| class Deepfrier: | |
| def __init__(self, path): |
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
| dictionary_path = "/usr/share/dict/words" | |
| # On Unix systems you may have /usr/share/dict/words installed | |
| # but this can really be whatever you provide | |
| with open(dictionary_path) as f: | |
| WORDS = {w.strip().lower() for w in f} | |
| def in_wordlist(word): | |
| return word.lower() in WORDS | |
| def permutations(letters): |
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 os | |
| import re | |
| from PIL import Image | |
| from reportlab.lib.pagesizes import letter | |
| from reportlab.pdfgen import canvas | |
| from datetime import datetime | |
| def get_scan_dirs(dirname): | |
| filelist = os.listdir(dirname) | |
| pattern = re.compile(r'^\d{3}_\d{10}$') |
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 numpy as np | |
| import matplotlib.pyplot as plt | |
| import scipy.stats | |
| def ax_example_correlation(ax, correlation): | |
| """ | |
| Generates a plot of random data with a specified Pearson correlation coefficient. | |
| Parameters: | |
| correlation (float): A number between 0 and 1 representing the Pearson correlation coefficient. |
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 abc import ABC, abstractmethod | |
| import json | |
| class RPSCompetitor(ABC): | |
| @abstractmethod | |
| def play(self): | |
| """ | |
| Returns the competitor's move. | |
| Returns: |
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 numpy as np | |
| import struct | |
| class MonoAudioBuffer: | |
| """ | |
| A class to generate audio data and store it for playback or further processing. | |
| Attributes: | |
| sample_rate (int): The sample rate of the audio data. | |
| audio_buffer (bytearray): The buffer to store the generated audio data. |
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 numpy as np | |
| import matplotlib.pyplot as plt | |
| def fig_time_series(t, y, focus=(0,1)): | |
| fig, axs = plt.subplots(1, 2, figsize=(20,2)) | |
| ax = axs[0] | |
| ax.set_title('mixed signal') | |
| ax.plot(t,y) | |
| ax.axvspan(*focus, color='tab:blue', alpha=0.2) | |
| ax = axs[1] |
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 sympy | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # use sympy to solve for y | |
| x, y = sympy.symbols('x y') | |
| equation = x**2 + (y - sympy.root(x**2, 3))**2 - 1 | |
| solutions = sympy.solve(equation, y) | |
| # nice things up |
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 os | |
| import xarray as xr | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def smooth_timeseries(timeseries: xr.DataArray, window_size: int = 3, method: str = 'running_mean') -> xr.DataArray: | |
| """ | |
| Smooths a timeseries using a specified method. | |
| Parameters: |
NewerOlder