This file contains 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
# Imports to download the wav file. Not necessary for local files. | |
from requests import get | |
from io import BytesIO | |
# Import to read the wav file. | |
from scipy.io import wavfile | |
# Import to plot the waveform. | |
import matplotlib.pyplot as plt |
This file contains 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 pathlib import Path | |
import cv2 | |
import numpy as np | |
def make_mosaic(cap, n_rows=4, n_cols=5): | |
n_frames = n_rows * n_cols | |
cap_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) | |
floor = int(cap_frames*0.05) | |
ceil = int(cap_frames*0.95) | |
frames_indexes = np.linspace(floor, ceil, n_frames).astype(int) |
This file contains 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
#!/home/bms/miniconda3/bin/python3 | |
# This script toggles status (enabled/disabled) of my notebook touchpad. My | |
# notebook is a Thinkpad 440p and its touchpad is a Synaptics TM2722-001. The | |
# system is Linux Mint. I map it to a keyboard shortcut (alt+F11 in my case). | |
# | |
# I tried just using: xinput disable 14 | |
# ... but the device id keeps changing after boot. | |
# | |
# I tried just using: xinput disable "Synaptics TM2722-001" |
This file contains 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 math | |
def human_readable_size(size_bytes, base=1024, decimal_places=2): | |
suffixes = 'B KB MB GB TB PB EB ZB YB'.split(' ') | |
if size_bytes == 0: | |
return '0B' | |
magnitude_index = int(math.floor(math.log(size_bytes, base))) | |
magnitude_bytes = math.pow(base, magnitude_index) | |
size = size_bytes / magnitude_bytes | |
suffix = suffixes[magnitude_index] |
This file contains 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 pathlib import Path | |
# Input parameters | |
folders = ['/my/video/folder1', '/my/video/folder2'] | |
video_file_types = 'avi flv m4v mkv mov mp4 mpg wmv'.split(' ') | |
# Folders as pathlib objects | |
folders = [Path(folder) for folder in folders if Path(folder).is_dir()] | |
# List and sort all files from all folders |
This file contains 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 pandas as pd | |
from random import choice, randint | |
names = ['David', 'James', 'John', 'Michael', 'Richard', 'Robert', 'William'] | |
surnames = ['Davis', 'Jones', 'Lee', 'Miller', 'Moore', 'Smith', 'Taylor'] | |
colors = ['Black', 'Blue', 'Green', 'Purple', 'Red', 'White', 'Yellow'] | |
pets = ['', 'Dog', 'Cat', 'Bird', 'Fish', 'Bunny', 'Hamster', 'Guinea Pig'] | |
def random_person(): |
This file contains 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 zipfile import ZipFile | |
def create_zip_with_fake_files(zip_filepath, fake_file_list): | |
with ZipFile(zip_filepath, 'w') as zip_archive: | |
for relative_filepath in fake_file_list: | |
zip_archive.writestr(relative_filepath, 'a') | |
def main(): | |
fake_files = [ | |
r'file0.txt', |
This file contains 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 | |
def im_hstack(images): | |
min_height = min([im.height for im in images]) | |
for im in images: | |
if im.height != min_height: | |
im.thumbnail((im.width, min_height)) | |
total_width = sum([im.width for im in images]) | |
panorama = Image.new('RGB', (total_width, min_height)) | |
x_offset = 0 |
This file contains 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 streamlit as st | |
import streamlit.components.v1 as components | |
def left_callback(): | |
st.write('Left button was clicked') | |
def right_callback(): | |
st.write('Right button was clicked') |
This file contains 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 urllib.request import urlopen | |
import unicodedata | |
def remove_accents(input_str): | |
nfkd_form = unicodedata.normalize('NFKD', input_str) | |
return u"".join([c for c in nfkd_form if not unicodedata.combining(c)]) | |
def has_letters(word, letters=''): |
OlderNewer