Skip to content

Instantly share code, notes, and snippets.

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

Jim Diroff II jimdiroffii

🏠
Working from home
View GitHub Profile
@jimdiroffii
jimdiroffii / fourJobs.sh
Created July 26, 2023 16:55
Manages concurrent execution of nohup jobs with a maximum limit
#!/bin/bash
# Manages concurrent execution of nohup jobs with a maximum limit.
# Number of maximum concurrent jobs
MAX_JOBS=4
# List of commands you want to run with nohup
declare -a commands=(
"./sleepTest.sh"
@jimdiroffii
jimdiroffii / copy.ps1
Created July 27, 2023 18:33
Local Network Backup with PowerShell
# Define the variables
# The server or root directory
$localserver = "\\<localserver>"
# Share
$share = "\share"
# Source data folders you wish to backup
$dataFolders = @("\backups", "\pics") # You can add more folders to this array if needed
@jimdiroffii
jimdiroffii / blockFiles.ps1
Last active August 26, 2023 16:40
Block all executables in a directory using firewall rules in Windows
# Check for administrator privileges
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Relaunch the script as an administrator
Start-Process powershell -Verb runAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`""
exit
}
# init directory existence check variable
$dirExists = $false
@jimdiroffii
jimdiroffii / backupdir.sh
Created August 15, 2023 01:22
Backup Ubuntu Directory
backup_dir_function() {
# Log the start of the command
logger -p syslog.info "Starting backup process."
# must pass in a directory
directory="$1"
# Convert to absolute path if a relative path is given
if [[ ! "$directory" = /* ]]; then
directory="$(pwd)/$directory"
fi
@jimdiroffii
jimdiroffii / for_management.ps1
Created October 18, 2023 20:39
Count Lines
(gci -include *.cpp,*.h -recurse | select-string .).Count
@jimdiroffii
jimdiroffii / executeUntilString.sh
Created October 23, 2023 00:35
Run a program until some output string is found
#!/bin/bash
counter=0
while true; do
counter=$((counter + 1))
output=$(./MyApp) # Execute the program and store its output
last_line=$(echo "$output" | tail -n 1) # Extract the last line of the output
echo "$output" # Print the output
if [ "$last_line" == "output" ]; then # Change this string to desired match
echo "Output found after: $counter" # Shows number of program executions
@jimdiroffii
jimdiroffii / clone-all-personal.ps1
Last active October 23, 2024 02:37
Clone all personal repos using PowerShell or Bash
# Install Github CLI
winget install -e --id GitHub.cli
# Log into Github
gh auth login
mkdir c:\_all
cd c:\_all
gh repo list | ForEach-Object { gh repo clone $_.Split("`t")[0] }
@jimdiroffii
jimdiroffii / center.cpp
Last active November 18, 2023 21:10
Center text in a fixed-width field using C++
#include "C:\gsl\narrow" // path to GSL include files
#include <string>
/***
* Center text in a fixed-width field
* https://stackoverflow.com/questions/14861018/center-text-in-fixed-width-field-with-stream-manipulators-in-c
*/
std::string center(const std::string& text, int width)
{
/***
@jimdiroffii
jimdiroffii / ElapsedTime.cpp
Last active November 2, 2023 00:30
Calculate elapsed time in C++ program using chrono with high resolution and precision
#include <iostream> // cout
#include <iomanip> // fixed, setprecision
#include <chrono> // time library
{
auto startTime = std::chrono::high_resolution_clock::now();
/* work */
auto endTime = std::chrono::high_resolution_clock::now();
@jimdiroffii
jimdiroffii / quicksort.c
Created November 5, 2023 22:58
K&R Recursive Quicksort in C
/* Pg. 87 - The C Programming Language (2nd Ed) - Recursive Quicksort */
/* qsort: sort v[left]..v[right into increasing order */
void qsort(int v[], int left, int right)
{
int i, last;
void swap(int v[], int i, int j);
if (left >= right) /* do nothing if array contains */
return; /* fewer than two elements */