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 soundfile as sf | |
import numpy as np | |
import librosa | |
import noisereduce as nr | |
# If you don't have the libraries above: | |
# pip install noisereduce librosa numpy soundfile | |
# Run ffmpeg first to extract the sound from the video | |
# ffmpeg -i 'noisy_video.mp4' -vn -acodec copy 'noisy_signal.aac' |
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
def main(): | |
import networkx as nx | |
import numpy as np | |
data = np.loadtxt("/home/yassinealouini/Documents/code/advent_of_code/aoc/year_2021/data/15.txt", "U") | |
size = int(len(data[0])) | |
data = data.view('U1').astype(int).reshape(data.shape[0], size) | |
# Need digraph since moving from previous to next position is not the same as the reverse. | |
G = nx.DiGraph() | |
def new_grid(data): |
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
# Simple bfs implementation to explore a graph. | |
# An undirected graph as an adjancency representation. | |
from collections import deque | |
G = {0: (1, 2), 1: (0, 6), 6: (1, 3), 3: (2, 4, 6), 5: (2, ), 2: (5, 0, 3), 4: (3, )} | |
source = 6 | |
end = 2 |
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 | |
import numpy as np | |
data = open("/home/yassinealouini/Documents/code/advent_of_code/aoc/year_2021/data/24.txt").read().rstrip() | |
OPERATIONS = {"add": lambda x: sum(x), "mul": lambda x: math.prod(x), | |
"div": lambda x: x[0] // x[1], "mod": lambda x: x[0] % x[1], | |
"inp": lambda x: x[1], | |
"eql": lambda x: int(x[0] == x[1])} |
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 https://heads0rtai1s.github.io/2021/02/25/gpu-setup-r-python-ubuntu/ | |
# Fresh install | |
sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*" | |
sudo apt-get --purge remove "*nvidia*" | |
sudo apt-get autoremove | |
# Drivers | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin |
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 sklearn import svm | |
from sklearn.datasets import load_iris | |
from joblib import dump | |
from joblib import load | |
import sys | |
import os | |
import pathlib | |
import pandas as pd | |
TRAIN = False |
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
def get_input_df(): | |
df = pd.DataFrame({"date": pd.date_range("2017-1-1", "2020-1-1", freq="1D")}) | |
df["open"] = np.random.choice([1, 0], len(df)) | |
df["closed"] = np.random.choice([1, 0], len(df)) | |
df["location"] = np.random.choice(["a", "b", "c"], len(df)) | |
return df | |
def compute_total_variations_df(df): | |
df = df.copy() |
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
alias port_forward='nohup ssh -N -f -L localhost:8889:localhost:8889 deepmeaning' | |
alias remote_notebook_start='nohup ssh -f deepmeaning "jupyter notebook --no-browser --port=8889"; port_forward' | |
alias remote_notebook_stop='ssh deepmeaning "pkill -u yassinealouini jupyter"' |
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 s3fs | |
import pandas as pd | |
import bz2file | |
s3 = s3fs.S3FileSystem() | |
df = pd.DataFrame() # Replace with your DataFrame | |
dest_s3_key = "" # Where to save in S3 | |
with s3.open(dest_s3_key, 'wb') as dest_file: | |
with bz2file.open(dest_file, 'wb') as compressed_file: |
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
<!doctype html> | |
<title>Upload</title> | |
<h1>Upload an image to recognize</h1> | |
<form method=post enctype=multipart/form-data action="{{url_for('upload_img')}}"> | |
<p><input type=file name=file> <input type=submit value=Upload> </p> | |
</form> |
NewerOlder