Skip to content

Instantly share code, notes, and snippets.

View elibroftw's full-sized avatar
😮‍💨

Elijah Lopez elibroftw

😮‍💨
View GitHub Profile
@elibroftw
elibroftw / sound_wave.py
Last active December 20, 2022 21:37
Generate sound waves for any audio file
import soundfile as sf
import numpy as np
import matplotlib.pyplot as plt
import io
from PIL import Image
def get_audio_wave(file):
data, samplerate = sf.read(file)
n = len(data)
@elibroftw
elibroftw / update_monerod.sh
Created April 29, 2022 21:14
Auto update monerod (Linux)
# sudo chmod +x update_monerod.sh
sudo sytemctl stop monerod
mkdir -p ~/Downloads && cd ~/Downloads
echo "Downloading and extracting Monero binaries"
curl -L https://downloads.getmonero.org/cli/linux64 | tar xj
rm -r -f ~/bin/monero && mkdir -p ~/bin
mv monero-*-linux-* monero
mv monero ~/bin
sudo systemctl start monerod
@elibroftw
elibroftw / get_multiple_file_types.py
Created April 4, 2022 05:19
Python get files of multiple extensions
# abstracted from https://github.com/elibroftw/music-caster/blob/master/src/music_caster.py :: get_audio_uris
import glob
import os.path
from pathlib import Path
MY_EXTS = {'.mp3', '.flac', '.m4a', '.mp4', '.aac', '.mpeg', '.ogg', '.opus', '.wma', '.wav'}
def valid_file_ext(uri) -> bool:
"""
@elibroftw
elibroftw / xlsx_to_js.py
Last active March 27, 2022 17:50
Excel file (xlsx) to Javascript array
import pandas as pd
import openpyxl
df = pd.read_excel(r'C:\Users\maste\Downloads\countries.xlsx')
javascript_1 = 'export const countries = [\n'
javascript_2 = 'export const countries_fr = [\n'
for _, row in df.iterrows():
row['EN'] = row['EN'].replace('’', "'")
@elibroftw
elibroftw / .bashrc
Last active February 11, 2022 02:05
Linux Add Directories to ENV::PATH
# ...
# .env_path format:
# path1
# path2
if [ -f ~/.env_path ]; then
export PATH=$PATH:$(python3 -c "import os; print(':'.join((line.strip() for line in open('.env_path').readlines() if line.strip())))")
fi
# Python code:
@elibroftw
elibroftw / resolve_known_folders.py
Last active November 17, 2021 07:05
A better way to resolve special or known folder names to their usable paths
"""
No Copyright. Public Domain.
Version: 1.0.4
Known Issues: Common home folders like Documents, Music, Videos, arem missing.
"""
from functools import lru_cache
from contextlib import suppress
import sys
from uuid import UUID
from pathlib import Path
@elibroftw
elibroftw / multiprocessing_ipc.py
Last active November 14, 2021 19:24
Interprocess Communication in Python using multiprocessing.connection's Listener, Client
"""
No Copyright by the way.
Usage:
0. Have two terminals
1. In the first terminal run `test.py`
2. In the second terminal run `test.py a`
3. Magic! If you don't see anything, the arbitrary port 12025 may be in use so use another port
Practical applications (requires more than just copy pasting this code):
- Simple message queueing:
@elibroftw
elibroftw / monero_wallet_decryption.py
Last active March 13, 2024 10:08
A script to decrypt MyMonero wallet files. Simply use decrypt_mymonero( WALLET_FOLDER_PATH ).
"""
Supports: MyMonero
Instructions (terminal, assuming you have python installed):
pip install cryptography
python[3] monero_wallet_decryption.py [path_to_wallet_dir]
License: Public Domain
You are permitted to run/edit/use any or all of this code without attribution.
Free implies that there are no warranties.
@elibroftw
elibroftw / monero_rpc_example.py
Last active April 23, 2026 21:41
How to use Monero RPC without headaches
import requests
import os
from contextlib import suppress
from subprocess import Popen, PIPE, DEVNULL, CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW
from requests import Session
import platform
from getpass import getpass
from pathlib import Path
from requests.auth import HTTPDigestAuth
from pprint import pprint
@elibroftw
elibroftw / concurrent_requests.py
Last active May 15, 2022 21:46
Concurrency and Parallel Requests
import requests
import concurrent.futures
def get_todo(i, optional_arg=None):
if i < 1: raise ValueError
r = requests.get(f'https://jsonplaceholder.typicode.com/todos/{i}')
return r.json()