Skip to content

Instantly share code, notes, and snippets.

@juanboterotech
juanboterotech / pdf_to_base64.py
Created May 29, 2025 05:47
Convert PDF file to Base64, better way for send files through an API or saving to a DB
'''
1) Declare the path of the file (Absolute path or relative)
2) Open using 'with' statement
3) Create the base64 bytes then "translate" to ascii format, save it to encode_string var
4) Print the encoded string in base64
'''
file_path = './somefile.pdf'
with open(file_path, 'rb') as file:
encoded_string = base64.b64encode(file.read()).decode('ascii')
print(f"File in Base64: {encoded_string}")
@juanboterotech
juanboterotech / backup_wordpress.sh
Created January 5, 2024 04:05
Backup your WordPress website
#!/bin/bash
# get current date
now = `date +"%Y-%m-%d"`
# copying WordPress files inside public_html folder
cd ~/public_html
tar -zcf "~/wordpress_$_now.tar.gz" wordpress_folder
# Database backup with mysqldump