Skip to content

Instantly share code, notes, and snippets.

View risadams's full-sized avatar
💡
I may be slow to respond.

Ris Adams risadams

💡
I may be slow to respond.
View GitHub Profile
# PowerShell
function Test-PendingReboot
{
$svc = "HKLM:\Software\Microsoft\Windows\CurrentVersion\" `
+ "Component Based Servicing\RebootPending";
$wupd = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\" `
+ "WindowsUpdate\Auto Update\RebootRequired"
@risadams
risadams / rip.sh
Created February 1, 2024 12:13
execute a command in parallel
#!/bin/env bash
rip() {
local cmd=$1 # Target command
local max_proc=$(($(nproc) / 2))
mapfile -t args < <(printf '%s\n' "${@:2}")
printf '%s\n' "${args[@]}" | xargs --verbose -I % -P $max_proc bash -c "${cmd} %"
}
# Example usage

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
#!/bin/bash
last_login=$(last -1 $USER | awk '{print $5,$6,$7}') # Get the last login timestamp
last_boot=$(who -b | awk '{print $3,$4}') # Get the system boot timestamp
if [[ $last_boot > $last_login ]]; then # Compare timestamps
echo "The system has rebooted since the last login."
else
echo "The system has not rebooted since the last login."
fi
@risadams
risadams / AlphaSort.ps1
Created May 20, 2023 16:27
Sort all files into alphanumeric folders based on the first letter of the file name
$list = @()
65..90 | ForEach-Object {
$letter = [char]$_
New-Item -Path .\ -Name $letter -ItemType "directory"
move-item .\$letter`?* $letter
$list += $letter
}
$rest = get-childitem -path .\ -exclude $list
New-Item -Path .\ -Name "0-9" -ItemType "directory"
@risadams
risadams / task_graph.groovy
Last active May 17, 2022 12:01 — forked from jrodbx/task_graph.groovy
Mermaid visualization of a Gradle project's task graph
gradle.taskGraph.whenReady {
println ''
println '----------------------------------------'
println ''
println 'Generating Task Graph:'
def mermaid = new File(rootProject.buildDir, 'project.mermaid')
mermaid.delete()
def command = "./gradlew " + gradle.startParameter.getTaskNames().join(" ")
This is an OpenPGP proof that connects [my OpenPGP key](https://keyoxide.org/741993E3066955B189CE0E181584258FC2159299) to [this Github account](https://github.com/risadams). For details check out https://keyoxide.org/guides/openpgp-proofs
[Verifying my OpenPGP key: openpgp4fpr:741993E3066955B189CE0E181584258FC2159299]
### Keybase proof
I hereby claim:
* I am risadams on github.
* I am risadams (https://keybase.io/risadams) on keybase.
* I have a public key whose fingerprint is 7419 93E3 0669 55B1 89CE 0E18 1584 258F C215 9299
To claim this, I am signing this object: