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 / remove-empty.sh
Created July 1, 2024 19:46
Recursively delete all empty files and directories in a path. Starts as deeply as possible, removes all files first, then the parent directory if empty.
#!/bin/bash
# Recursive Delete - All empty files and directories
# Check if a directory is provided
if [ -z "$1" ]; then
echo "Usage: $0 [directory]"
exit 1
fi
@jimdiroffii
jimdiroffii / gitclone.ps1
Created June 10, 2024 05:02
Fix "Fatal: early EOF" clone issue with large git repository
# Credit: ingyhere | https://stackoverflow.com/a/22317479/8077665
# Fixes this error during `git clone`
#
# fetch-pack: unexpected disconnect while reading sideband packet
# fatal: early EOF
# fatal: fetch-pack: invalid index-pack output
#
# First, turn off compression:
git config --global core.compression 0
# Next, let's do a partial clone to truncate the amount of info coming down:
@jimdiroffii
jimdiroffii / nmap.sh
Last active July 10, 2024 19:25
inline bash cli command for running nmap, just update host IP
host=10.10.11.224 && ports=$(sudo nmap -p- --min-rate=1000 -T4 $host -Pn | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//) && sudo nmap -p $ports -sV -sC $host -Pn -oN 'nmap_tcp.txt'
@jimdiroffii
jimdiroffii / printv.cpp
Created November 18, 2023 20:13
C++ :: Templated vector print function
// Credit: @bweinman | C++ Templates and the STL
// printv() iterates a vector, printing space separated elements
template<type T>
void printv(vector<T> &v) {
if(v.empty()) return;
for(T &i : v) cout << i << " ";
cout << endl;
}
@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 */
@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 / 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 / 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 / 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 / for_management.ps1
Created October 18, 2023 20:39
Count Lines
(gci -include *.cpp,*.h -recurse | select-string .).Count