Skip to content

Instantly share code, notes, and snippets.

View theinventor's full-sized avatar

Troy Anderson theinventor

View GitHub Profile
@theinventor
theinventor / async_file_download_from_urls.js
Created May 7, 2024 02:16
A simple function in a stimulus controller in rails. It will post IDs of your objects to an endpoint to fetch their public URLs, then zip up all those files from the public URLs and give them a download.zip file.
async download(event) {
event.preventDefault();
console.log("Download function initiated");
const spinner = document.querySelector('.downloadLoading'); // Show the spinner
spinner.classList.remove('hidden');
const contentIds = this.selectedIds;
const csrfToken = document.querySelector("[name='csrf-token']").content;
@theinventor
theinventor / gist:5ef2aeeb1ffb84c5aa372e696ef04583
Created May 7, 2024 02:15
async_download_remote_files.js
async download(event) {
event.preventDefault();
console.log("Download function initiated");
const spinner = document.querySelector('.downloadLoading'); // Show the spinner
spinner.classList.remove('hidden');
const contentIds = this.selectedIds;
const csrfToken = document.querySelector("[name='csrf-token']").content;
#!/usr/bin/python
import subprocess
import re
# Get process info
ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], stdout=subprocess.PIPE).communicate()[0].decode()
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0].decode()
# Iterate processes
@theinventor
theinventor / bad-events.txt
Created February 22, 2018 15:27
Things you might want to watch for in windows eventlog
EventID,Source,LogName,EventType,Message,Severity
9,%,%,0,%did not respond within the timeout period%,High
11,%,%,0,%controller error%,High
1000,%Microsoft-Windows-DHCP-Server%,%,0,%The DHCP service received the unknown option%,Critical
1064,%Microsoft-Windows-DHCP-Server%,%,0,%There are no IP addresses available for BOOTP clients%,Critical
1069,%Microsoft-Windows-DHCP-Server%,%,0,%Iashlpr cannot contact the NPS service%,Critical
1070,%Microsoft-Windows-DHCP-Server%,%,0,%Iashlpr initialization failed%,Critical
1142,%Microsoft-Windows-DHCP-Server%,%,0,%The DHCP server is unable to reach the NPS server%,Critical
3,%Microsoft-Windows-DNS-Server-Service%,%,0,%The DNS server has shut down%,Critical
10,%Microsoft-Windows-DNS-Server-Service%,%,0,%The DNS server could not start because it is dependent on the NTDS service which is not started%,Critical
@theinventor
theinventor / rc-car-highbeams.c
Created February 22, 2018 06:18
Simple arduino code to handle pwm and drive rc car headlights (LEDs) from a receiver (power and signal)
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
To upload to your Gemma or Trinket:
1) Select the proper board from the Tools->Board Menu
2) Select USBtinyISP from the Tools->Programmer
3) Plug in the Gemma/Trinket, make sure you see the green LED lit
@theinventor
theinventor / syncro-sample-rest-api.ps1
Last active September 29, 2021 23:27
A sample powershell script with some functions to work with the SyncroMSP HTTP REST API
Import-Module $env:SyncroModule
###########################################################################################
# First, some functions, these are just declarations that get used lower down the script. #
###########################################################################################
function Query-Syncro-Tickets ($SyncroSubdomain,$SyncroAPIKey,$Query) {
$uri = "https://$SyncroSubdomain.syncromsp.com/api/v1/tickets?api_key=$SyncroAPIKey&query=$Query"
$response = Invoke-RestMethod -Uri $uri
$response
@theinventor
theinventor / syncro-install.ps1
Created January 15, 2018 05:40
Download Syncro agent and install it from command line
# Download the installer
$source = "https://rmm.syncromsp.com/GetThisURLfromYourCustomerDetailPageAndPutItHere.exe"
$destination = "C:\temp\syncro-installer.exe"
# Check if Invoke-Webrequest exists otherwise execute WebClient
if (Get-Command 'Invoke-Webrequest'){
Invoke-WebRequest $source -OutFile $destination
} else {
$WebClient = New-Object System.Net.WebClient
@theinventor
theinventor / laundry-monitor.groovy
Created January 15, 2018 00:19
laundry monitor II
import groovy.time.*
definition(
name: "Laundry Monitor II", namespace: "HDFLucky", author: "Mr. Lucky",
description: "This application is a modification of the SmartThings 'Laundry Monitor' SmartApp. Instead of using a vibration sensor, it utilizes Power (wattage) sensing.",
category: "My Apps",
iconUrl: "https://dl.dropboxusercontent.com/u/52901840/laundry.png",
iconX2Url: "https://dl.dropboxusercontent.com/u/52901840/laundry@2x.png",
iconX3Url: "https://dl.dropboxusercontent.com/u/52901840/laundry@3x.png")
Import-Module $env:SyncroModule
# this depends on bemcli being installed!
#Setting default CLI
import-module bemcli
#Getting Alerts
$Alerts = Get-BEAlert
#Looping through the alerts and setting them.
Import-Module $env:SyncroModule
$Date=Get-Date; $Date=$Date.AddDays(-1).ToShortDateString()
$WBS=Get-WBSummary
$LastBackupResult=$WBS.LastBackupResultDetailedHR
$LastSuccessfulBackup=$WBS.LastSuccessfulBackupTime.ToShortDateString()
$LastBackup=$WBS.LastBackupTime
$Versions=$WBS.NumberOfVersions
$ErrorDesc=Get-WBJob -Previous 1; $ErrorDesc=$ErrorDesc.ErrorDescription