Skip to content

Instantly share code, notes, and snippets.

View yassineAlouini's full-sized avatar
⚙️
PyTorch Exploration...

Yassine Alouini yassineAlouini

⚙️
PyTorch Exploration...
View GitHub Profile
@yassineAlouini
yassineAlouini / denoise.py
Created December 17, 2023 16:30
A short script to denoise the audio of a noisy video.
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'
@yassineAlouini
yassineAlouini / day15.py
Created February 2, 2022 09:31
Solution for day 15 AoC 2021
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):
@yassineAlouini
yassineAlouini / bfs_shortest_path.py
Created January 1, 2022 14:48
Find shortest path in an unweighted undirected graph using BFS
# 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
@yassineAlouini
yassineAlouini / aoc_24_2021.py
Created December 24, 2021 15:54
Solution to AOC 2021 Day 24
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])}
@yassineAlouini
yassineAlouini / install_cuda.sh
Created February 27, 2021 09:42
In case your latest Ubuntu update breaks everything for CUDA. :p
# 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
@yassineAlouini
yassineAlouini / model.py
Created January 19, 2021 14:44
Bad QA code
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
@yassineAlouini
yassineAlouini / total_variations.py
Created February 14, 2020 09:30
Compute the variations of the total column
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()
@yassineAlouini
yassineAlouini / remote_jupyter.sh
Created November 4, 2019 09:33
Remote Jupyter access to my desktop aliases
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"'
@yassineAlouini
yassineAlouini / df_csv_bz2_to_s3.py
Created February 28, 2019 15:58
Save DataFrame to S3 as a CSV with bz2 compression
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:
@yassineAlouini
yassineAlouini / upload_image.html
Created February 24, 2019 13:26
A simple image uploading HTML form
<!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>