Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Marreck pmarreck

  • formerly desk.com, thredup.com and lifebooker.com. currently a contractor
  • Long Island, NY
View GitHub Profile
@pmarreck
pmarreck / lspci output
Created May 9, 2022
output of lspci on my system76 thelio desktop
View lspci output
❯ lspci
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Root Complex
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Starship/Matisse IOMMU
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
00:01.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
00:03.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
00:04.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
00:05.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
00:07.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge
@pmarreck
pmarreck / backup_metadata.bash
Created Feb 14, 2022
Back up file or directory permissions and owner metadata on a linux filesystem
View backup_metadata.bash
echo "Creates a script file that restores your current filesystem permissions and owners in the event there's a mishap."
echo "Note: May need to be modified to handle double-quotes in filenames, excluding directories like proc or mnt, etc."
echo "Also, since 'find' does breadth-first traversal, it might make more sense to run the chmod and chown with -R,"
echo "although that will make it take MUCH longer as it will be re-applying more specific permissions"
echo "on the way down."
sudo find / -name '*' -printf 'chmod %#m "%p"\nchown -h %u:%g "%p"\n' > fix-permissions.sh
echo "Complete. Now do 'chmod +x fix-permissions.sh; chown <yourusername> fix-permissions.sh' and run when you need to."
@pmarreck
pmarreck / coinflip.bash
Created Feb 9, 2022
Simplest way to simulate a coin flip or toss on the Linux command line (in Bash; may work in other shells)
View coinflip.bash
# return code is either 0 (success) or 1 (fail), so you can use it straight-up in logical statements
coinflip() { return $(($RANDOM%2)); }
coinflip && echo "heads" || echo "tails"
@pmarreck
pmarreck / thanos_all_the_files.bash
Created Feb 8, 2022
destroy a random half of your files, Thanos-style, in linux or bash shell
View thanos_all_the_files.bash
# Wrote this on a whim. Consider it performance-art shell scripting.
# To really do this, set FFS=true, otherwise, only the paths to the files that would have been destroyed are printed.
# I take no responsibility for the use of this. Even writing it was scary, and I didn't test the whole thing (YET).
# You have been warned.
coinflip() { return $(($RANDOM%2)); }
thanos_logic() { while read -r line; do coinflip && echo "$line"; done; }
thanos_infinity_gauntlet_completed() {
@pmarreck
pmarreck / pman.bash
Created Feb 8, 2022
Shell function(s) to get a pretty man page viewed as a PDF up in a PDF viewer on (any?) Linux distro
View pman.bash
# helper function
needs () {
local bin=$1;
shift;
command -v $bin > /dev/null 2>&1 || {
echo "I require $bin but it's not installed or in PATH; $*" 1>&2;
return 1
}
}
@pmarreck
pmarreck / ShowListeners.ps1
Created Jan 21, 2022
On Windows, use PowerShell to get a list of open ports and the process and service names (sometimes with paths) that are holding them open
View ShowListeners.ps1
# Script: ShowListeners.ps1
# Author: MotoX80 and Evgenij Smirnov on MS forums
# pmarreck note: If you get a security block, you may need to run the following first:
# Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
# (or use CurrentUser for the -Scope if you want it to apply outside the current session, less secure though)
# For more, see: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.2
$rpt = @()
$services = Get-CimInstance -Class Win32_Service -Filter 'State="Running"' | Select Name, ProcessID
$Listeners = Get-NetTCPConnection | Where-Object {$_.State -eq "Listen"}
View kick_homebrew.sh
for tab in $(grep -l -o '[a-z0-9-]*proto' $(brew --cellar)/*/*/INSTALL_RECEIPT.json)
do
formula=$(basename $(dirname $(dirname $tab)))
brew remove --ignore-dependencies $formula
brew install $formula
done
@pmarreck
pmarreck / uninstall_brews.sh
Created Jan 6, 2022
uninstall all brews from homebrew
View uninstall_brews.sh
while [[ `brew list | wc -l` -ne 0 ]]; do
#Iterate over each installed package
for EACH in `brew list`; do
#Uninstall each package
brew uninstall --ignore-dependencies $EACH --force
done
done
@pmarreck
pmarreck / random_password.sh
Last active Jan 4, 2022
Generate random strings or dictionary words in Bash
View random_password.sh
#!/usr/bin/env bash
# get a random-character password
# First argument is password length
# Can override the default character set by passing in PWCHARSET=<charset> as env
randompass() {
# globbing & history expansion here is a pain, so we store its state, temp turn it off & restore it later
local maybeglob="$(shopt -po noglob histexpand)"
set -o noglob # turn off globbing
set +o histexpand # turn off history expansion
@pmarreck
pmarreck / aoc_1.exs
Last active Dec 4, 2021
possible AOC #1 solution in Elixir
View aoc_1.exs
defmodule Increases do
def count_increases(string) when is_binary(string) do
string
|> String.split("\n")
|> Enum.map(fn x -> Integer.parse(x) end)
|> Increases.count_increases
end
def count_increases(list) when is_list(list), do: count_increases(list, 0)