Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / mongo-index-on-fields-in-array.md
Last active April 12, 2024 18:37
Hello World of MongoDB playing with Index on Embedded Document Fields within Arrays
@rms1000watt
rms1000watt / mongo-wildcard-index-single-field.md
Last active April 12, 2024 18:36
Hello World MongoDB Create Wildcard Index on Single Field
@rms1000watt
rms1000watt / jinja2-omit-comma-from-item.txt.j2
Created October 18, 2019 21:10
Jinja2 omit comma from last item in list
# Courtesy of: https://stackoverflow.com/a/11974399
{%- for item in items %}
[
"{{item}}"{{ "," if not loop.last }}
]
{%- endfor %}
@rms1000watt
rms1000watt / python-printJS-in-pdf.py
Last active March 29, 2024 11:24
Python script to add JS to pdf so the pdf will print immediately when opened
# IE users need: https://get.adobe.com/reader/
from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
ipdf = PdfFileReader(open('old.pdf', 'rb'))
for i in xrange(ipdf.getNumPages()):
page = ipdf.getPage(i)
output.addPage(page)
@rms1000watt
rms1000watt / remount-storage.sh
Created March 25, 2024 15:44
remount my removable storage on my raspberry pi
#!/usr/bin/env bash
set -e
# check if disk is attached
sda1_attached=false
sdb1_attached=false
if lsblk | grep -q "sda1"; then
sda1_attached=true
@rms1000watt
rms1000watt / main.js
Created March 15, 2024 23:08
nodejs list, cleanup, create event listeners on process sigint
// from chatgpt
// list all event listeners on process
const eventNames = process.eventNames();
eventNames.forEach((eventName) => {
const listeners = process.listeners(eventName);
console.log(`Event: ${eventName}`);
console.log(`Listeners:`);
listeners.forEach((listener, index) => {
console.log(` Listener ${index + 1}: ${listener.toString()}`);
// Note: listener.toString() might not always give meaningful information,
@rms1000watt
rms1000watt / haproxy-rdp-filtering
Created June 15, 2016 20:19
HAProxy RDP Filtering
frontend rdp
mode tcp
bind 192.168.1.11:3389
tcp-request inspect-delay 2s
tcp-request content accept if RDP_COOKIE
acl userID_a19281 rdp_cookie(mstshash) -i user123
use_backend backend_a19281 if userID_a19281
acl userID_8721bc rdp_cookie(mstshash) -i user456
@rms1000watt
rms1000watt / gcloud-install-usage.sh
Last active August 15, 2023 07:27
gcloud install and usage
asdf plugin add gcloud https://github.com/jthegedus/asdf-gcloud
echo "gcloud 410.0.0" >> ~/.tool-versions
asdf install
gcloud auth login
gcloud projects list
gcloud config set project $GCP_PROJECT_ID
# pull logs from cloudbuild
# add grep to this command for specific hash.. then cut -d' ' -f1 for the ID.. maybe can filter directly
@rms1000watt
rms1000watt / golang-template-if-and.go
Last active July 13, 2023 20:10
Golang script for using templates with IF and AND
package main
import (
"fmt"
"os"
"text/template"
)
type Person struct {
Name string
@rms1000watt
rms1000watt / docker-run-init-sigint-success.sh
Created July 13, 2023 18:03
docker run with --init so SIGINT ctrl+c succeeds
docker run -it --rm --init "${DOCKER_IMAGE}"