Skip to content

Instantly share code, notes, and snippets.

@gagregrog
gagregrog / bash_menu.sh
Created August 23, 2021 03:29
Ephemeral Interactive Bash Menu with Up/Down selection or numeral selection
# Original solution sourced from:
# https://unix.stackexchange.com/questions/146570/arrow-key-enter-menu
#
# Updated to do the following:
# - Display index with each option
# - Choose options 1-9 with numeric input
# - Clear the menu and reset the cursor when an option is selected
#
# Arguments:
# array of options
@gagregrog
gagregrog / rtsp_stream.py
Last active April 10, 2024 04:02
View an RTSP stream in python with OpenCV
import cv2
import imutils
from imutils.video import VideoStream
# replace this with the url generated by the Wyze app
rtsp_url = "rtsp://<camera_name>:<some_uuid>@<some_ip>/live"
vs = VideoStream(rtsp_url).start()
while True:
@gagregrog
gagregrog / Using Github Deploy Key.md
Last active October 4, 2022 22:15 — forked from zhujunsan/Using Github Deploy Key.md
Using Github Deploy Key

What / Why

Deploy key is a SSH key set in your repo to grant client read-only (as well as r/w, if you want) access to your repo.

As the name says, its primary function is to be used in the deploy process, where only read access is needed. Therefore keep the repo safe from the attack, in case the server side is fallen.

How to

  1. Generate a ssh key
@gagregrog
gagregrog / github_deploy_keys_with_pm2.md
Last active September 4, 2022 20:15
Using GitHub Deploy Keys with PM2

PM2, EC2, and Github

Set Up Deploy Key on Remote Server

  1. SSH into the target machine
  2. Make a deploy_keys folder and change into it
    1. mkdir ~/.ssh/deploy_keys
    2. cd ~/.ssh/deploy_keys
  3. Create a new key pair
  4. ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
@gagregrog
gagregrog / fresh-raspberries-for-devs.md
Last active January 27, 2021 01:47
Fresh install process on a Raspberry Pi, targeted at developers

Fresh Raspberries for Devs

Fresh Install Process on the Raspberry Pi, specifically for Developers.

  1. Download the Raspberri Pi OS tool for flashing your SD card from The Raspberry Pi Foundation.
  2. Plug in your SD card and use tghe tool to flash the 32-bit os to the card.
  3. When the flasher finishes, remove the card and then place it back in.
  4. Enable SSH
    $ cd /Volumes/boot
    

$ nano ssh

@gagregrog
gagregrog / io.js
Last active October 28, 2020 22:49
Storage solution for simple JSON data
const path = require('path');
const fs = require('fs-extra');
const ROOT = path.resolve(`${__dirname}/..`);
const RESULTS = `${ROOT}/results.json`;
if (!fs.pathExistsSync(RESULTS)) {
fs.writeJSONSync(RESULTS, []);
}
@gagregrog
gagregrog / html.js
Last active October 28, 2020 22:39
Grab key value pairs of data cells for rows 1,3,4,5
const cheerio = require('cheerio');
const re = new RegExp('[1345]');
const parseHtml = (html) => {
const $ = cheerio.load(html);
const trs = $('#result-card > div > table > tbody > tr');
const results = [];
trs.each((trIdx, tr) => {
if (re.test(trIdx)) {
@gagregrog
gagregrog / process.js
Created October 27, 2020 23:15
Piecing it all together
const io = require('./io');
const alert = require('./alert');
const getTime = require('./time');
const parseHtml = require('./html');
const areEqual = require('./compare');
const getTestResultsAsHtml = require('./request');
const processOne = async (config) => {
const html = await getTestResultsAsHtml(config);
const fields = parseHtml(html);
@gagregrog
gagregrog / alert.js
Last active October 27, 2020 22:53
Send an email with Nodemailer
const nodemailer = require('nodemailer');
const smtpTransport = require('nodemailer-smtp-transport');
const options = {
service: 'gmail',
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: process.env.FROM,
@gagregrog
gagregrog / index.js
Last active October 27, 2020 22:51
Process Covid Results
require('dotenv').config();
const processOne = require('./lib/process');
const DEFAULT_DELAY = 1;
const ENV_HRS = Number(process.env.DELAY_HRS);
const DELAY_HOURS = ENV_HRS > 0 ? ENV_HRS : DEFAULT_DELAY;
const DELAY_MS = DELAY_HOURS * 1000 * 60 * 60; // X hrs * 1000 ms/sec * 60 sec/min * 60 min/hr
const loop = async () => {
try {