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 / 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 / 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 / results3.json
Created October 27, 2020 21:27
Covid Results Phase 3
[
[
"Your Result",
"Negative: SARS-CoV-2 (COVID-19) NOT detected"
],
[
"Date resulted",
"2020-10-27 04:16:00"
],
[
@gagregrog
gagregrog / results2.json
Created October 27, 2020 21:23
Covid Results phase 2
[
[
"Your Result",
"Awaiting result"
],
[
"Date resulted",
"None"
],
[
@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 {
@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 / 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 / results.json
Created October 27, 2020 20:16
Sample results after processing html
[
[
"Your Result",
"Specimen not received by lab"
],
[
"Date resulted",
"None"
],
[
@gagregrog
gagregrog / getText.js
Created October 27, 2020 20:10
Get plain text from nested DOM nodes
function getText(node) {
const getTextRecursively = (currentNode) => {
const { type, data, children } = currentNode;
if (type === 'text') {
return data.replace(/ /g, '').replace(/\n/g, '');
} else if (type === 'tag' && children) {
let childrenText = '';
children.forEach(child => {
childrenText += getTextRecursively(child);