Skip to content

Instantly share code, notes, and snippets.

View oliverswitzer's full-sized avatar
🏠
Working from home

Oliver Switzer oliverswitzer

🏠
Working from home
View GitHub Profile
@oliverswitzer
oliverswitzer / more_complicated_serial_test.py
Created September 29, 2024 01:32
Pimoroni Servo 2040 Serial Testing
import gc
import time
import math
from pimoroni import Button
from plasma import WS2812
from servo import ServoCluster, servo2040
from machine import UART, Pin
"""
An example of applying a wave pattern to a group of servos and the LEDs.
@oliverswitzer
oliverswitzer / extract-orders.js
Last active September 20, 2023 17:58
Extract Amazon orders to a csv file
// Simply copy and paste this entire snippe into the browser console (Cmd + Option + J opens the console) from the Amazon orders page (https://www.amazon.com/gp/css/order-history?ref_=nav_AccountFlyout_orders)
// For now you'll have to navigate to the next page yourself and re-run this on each page.
// Once you've finished running this on all relevant order pages, run the following:
//
//
// const storedData = localStorage.getItem('amazonOrdersCSV');
// downloadCSV(storedData);
//
@oliverswitzer
oliverswitzer / Stepper.h
Created July 18, 2023 16:28
POC For an async stepper in Arduino
class Stepper {
public:
enum StepDirection { FORWARD, REVERSE };
// ... Other members ...
void beginStep(int numSteps, StepDirection direction, int speed) {
// Ignore beginStep if the stepper is already stepping
if (_inMotion) {
return;
@oliverswitzer
oliverswitzer / extract-vanguard-transactions.js
Created June 30, 2023 02:53
Small browser script to extract vanguard transactions to a CSV
// 1. Manually paginate through all rows of the table you want to extract a CSV from
// 2. Fill out the right css selector for `tableRowSelector` for the table you want to extract a csv from
// 2. Copy and paste the lines below into your browser console from this page: https://transactions.web.vanguard.com/
const tableRowSelector = "table[aria-label='Transactions for account Your Name... — Account Name — Account Number (Self-managed)*'] tr"
[...document.querySelectorAll(tableRowSelector)]
.map(n => [...n.cells])
.map(c =>
c.map(n => `"${n.innerText}"`).join(",")
@oliverswitzer
oliverswitzer / rename_phoenix_app.sh
Created April 19, 2023 18:21
A little shell script that helps you rename a templated Phoenix project (note: might be out of date with current version of Phoenix)
#!/bin/bash
rename_cwd() {
cd . || return
new_dir=${PWD%/*}/$1
mv -- "$PWD" "$new_dir" &&
cd -- "$new_dir"
}
@oliverswitzer
oliverswitzer / wifi_logging_test.ino
Created April 5, 2023 23:48
A small script that starts a simple HTTP server on the Arduino
#include <WiFiNINA.h>
char ssid[] = ""; // your network SSID (name)
char pass[] = ""; // your network password
WiFiServer server(80);
void setup() {
Serial.begin(9600);
@oliverswitzer
oliverswitzer / chat_gpt_browser_script.js
Created February 27, 2023 15:05
ChatGPT Browser Script: Use this to programmatically ask ChatGPT questions
SCRIPT TO TALK TO GPT3
const prompt = "why am I getting this error" // change me
let button = document.querySelectorAll("button")[5];
let textarea = document.querySelector("textarea");
textarea.innerText = prompt;
button.dispatchEvent(new Event("click", {bubbles: true}))
@oliverswitzer
oliverswitzer / bulk_rotate_video.exs
Created October 10, 2022 00:58
Simple elixir script to rotate mp4 video in bulk using ffmpeg
# Files need to be in same directory as this script
files = ["rotate_me_1", "rotate_me_2", "rotate_me_3"]
# Read more about rotating videos with ffmpeg here
# https://www.baeldung.com/linux/ffmpeg-rotate-video#:~:text=transpose%20is%20an%20FFmpeg%20filter,the%20values%20from%200%2D3.
# Run this from a new shell session to watch the progress of this script:
# `$ while true; do ps aux | grep ffmpeg; sleep 2; clear; done`
Task.async_stream(
@oliverswitzer
oliverswitzer / bookmarklet.js
Last active August 25, 2021 04:37
Small script that helps you locate hotspots from https://app.hotspotty.net/ in Google Earth. Just click the bookmarklet after navigating to the current selected hotspots "info" tab. To create bookmarklet, copy contents of bookmarklet.js, create a new empty bookmark, and paste into the bookmark. You can also make it yourself using this tool https…
javascript:(function()%7BopenGoogleEarthForHotspot()%3B%0Afunction earthUrl(lat%2C lng) %7B%0A return %60https%3A%2F%2Fearth.google.com%2Fweb%2Fsearch%2F%24%7Blat%7D%2C%24%7Blng%7D%60%3B%0A%7D%0A%0Aasync function openGoogleEarthForHotspot() %7B%0A const hotspotAddress %3D getHotspotAddress()%3B%0A const %7B lat%2C lng %7D %3D await getCoordinates(hotspotAddress)%3B%0A window.open(earthUrl(lat%2C lng))%3B%0A%7D%0A%0Aasync function getCoordinates(hotspotAddress) %7B%0A const res %3D await fetch(%0A %60https%3A%2F%2Fapi.helium.io%2Fv1%2Fhotspots%2F%24%7BhotspotAddress%7D%60%0A ).then((res) %3D> res.json())%3B%0A const %7B lng%2C lat %7D %3D res.data%3B%0A%0A return %7B lng%2C lat %7D%3B%0A%7D%0A%0Afunction getHotspotAddress() %7B%0A var xpath %3D "%2F%2F*%5Bcontains(text()%2C'Hotspot address')%5D"%3B%0A var matchingElement %3D document.evaluate(%0A xpath%2C%0A document%2C%0A null%2C%0A XPathResult.FIRST_ORDERED_NODE_TYPE%2C%0A null%0A ).singleNodeValue%3B%0A%0A return matchingElemen
def find_duplicate(int_array)
current_position = int_array[-1]
# Step 1: Get our cursor to the end of the int array list, so that we
# are guaranteed to be in a loop when we try to find the loop length
(int_array.length - 1).times do
current_position = int_array[current_position - 1]
end
loop_start_position = current_position