Skip to content

Instantly share code, notes, and snippets.

View mikeesto's full-sized avatar
🙂

Michael Esteban mikeesto

🙂
View GitHub Profile
@mikeesto
mikeesto / hotspot.md
Last active April 19, 2023 07:47
Create a local WiFi hotspot with a Raspberry Pi with custom routing

Create a local WiFi hotspot with custom routing on the Raspberry Pi

This setup lets you:

  • SSH into the Pi directly (e.g. ssh pi@raspberrypi)
  • Access things running on the Pi (e.g. a web server)
  • Set up fun domains that only exist within the local network, and can route to your services running on the Pi
  • Prevents any access to the internet which can be useful if you are running the Pi as a tech demo, or for teaching etc

This is a modified/shorter version from the official Pi docs.

@mikeesto
mikeesto / csv2bib.py
Created March 29, 2023 23:22
Convert CSV file to BibTeX
import csv
def generate_bibtex_key(authors, year):
"""Generate a BibTeX key from the first author's last name and the year"""
last_names = authors.split(",")[0].split()
last_name = last_names[-1] if len(last_names) > 0 else ""
return f"{last_name.lower()}{year}"
def convert_csv_to_bibtex(csv_file, bibtex_file):
"""Convert a CSV file to BibTeX format"""
@mikeesto
mikeesto / script.sh
Created October 24, 2022 03:30
Run Python scripts on boot with PM2
pm2 start script.py --interpreter python3
@mikeesto
mikeesto / cors.js
Last active October 4, 2022 17:45
Set CORS for Cloudflare R2
import aws from "aws-sdk";
const s3 = new aws.S3({
endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
accessKeyId: process.env.CLOUDFLARE_ACCESS_KEY,
secretAccessKey: process.env.CLOUDFLARE_SECRET_ACCESS_KEY,
signatureVersion: "v4",
});
const config = {
@mikeesto
mikeesto / docker.sh
Created September 21, 2022 04:28
Run a docker container and access the shell
docker run -i --entrypoint=/bin/sh ...
@mikeesto
mikeesto / docker.sh
Created September 21, 2022 04:26
Build x86_64 Docker image on M1/M2 architecture
docker buildx build --platform=linux/amd64 -t myimage .
@mikeesto
mikeesto / install.sh
Created January 5, 2022 12:44
Install Tensorflow 2 on a Raspberry Pi
# a fresh start
sudo apt-get -y update
sudo apt-get -y upgrade
# remove old versions, if not placed in a virtual environment (let pip search for them)
sudo pip uninstall tensorflow
sudo pip3 uninstall tensorflow
# install the dependencies (if not already onboard)
sudo apt-get install -y gfortran
sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev
sudo apt-get install -y libatlas-base-dev libopenblas-dev libblas-dev
@mikeesto
mikeesto / get_line.js
Created November 1, 2021 23:22
Bresenham's Line Algorithm - Produces a list of points from start to end
function get_line(start, end) {
let [x1, y1] = start;
let [x2, y2] = end;
let dx = x2 - x1;
let dy = y2 - y1;
const is_steep = Math.abs(dy) > Math.abs(dx);
// Rotate line
@mikeesto
mikeesto / date.sh
Last active June 14, 2021 03:46
How to update date/time on Raspberry Pi
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
@mikeesto
mikeesto / reset-usb.md
Last active September 21, 2022 04:19
Reset USB ports on Raspberry Pi (useful for USB audio)

Reset USB ports on Raspberry Pi on boot

Add to /etc/rc.local:

# To shut off power on USB ports (this shuts power on ethernet as well):
echo '1-1' | tee /sys/bus/usb/drivers/usb/unbind

# To turn power back on
echo '1-1' | tee /sys/bus/usb/drivers/usb/bind