Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / datesort.ps1
Created January 16, 2023 17:19
Sorting captures from holidays into folders named by date
View datesort.ps1
$ErrorActionPreference = 'Stop'
$shell = New-Object -ComObject 'Shell.Application'
&{
gci -File `
| ?{
#leave these in the root directory
$_.Name -notmatch '^(IMG_\d{4}.JPG|sort.ps1|Untitled.png)$'
}
@Hashbrown777
Hashbrown777 / dirdiff.ps1
Created January 16, 2023 08:52
Sees if there are any differences between two folder structures and file contents therein using a multithreaded process
View dirdiff.ps1
#folders you want checked that are found in each root
$paths = 'Pics of cats', 'Pics of dogs'
#roots to compare, must include terminating slash
$roots = '//?/D:/PicsBackup/', '//?/C:/Users/Hashbrown/Desktop/'
#any files that are permitted to differ and wont be checked
$skip = `
'Pics of cats/test.ps1',
'Pics of cats/tabby/download.log'
#periodically the script outputs the last sucessfully checked path.
#upon failure you can start from exactly where you were, skipping all previously checked files
@Hashbrown777
Hashbrown777 / clonepage.js
Created November 25, 2022 09:22
Clones the selected element in the console into a new window, copying all styles and re-inserting any pseudo elements.
View clonepage.js
(function (element, asBody) {
let copy = open().document;
copy.open();
copy.write('<!doctype html>\n<html><head></head><body></body></html>');
copy.close();
if (asBody) {
for (const name of element.getAttributeNames())
copy.body.setAttribute(name, element.getAttribute(name));
for (const node of element.children)
@Hashbrown777
Hashbrown777 / ChunkSum.ps1
Created November 23, 2022 17:17
Get multiple checksum hashes on a per-chunk basis from a single file.
View ChunkSum.ps1
<# Similar to a CheckSum, but you receive one for every chunk of a given size in the file as if hashing several files each of that size.
You could use this to assess where in a file it differs from another (say, over a network, where comparing digests is infinitely better than comparing the real byte streams)
-File
Can be a string or file reference (it's passed to Get-Item internally anyway)
-ChunkSize
The size to 'break' the file into to report each hash on.
A chunksize greater or equal to the filesize is equivalent to a normal Get-FileHash call.
This figure does not have to be a multiple of BufferSize (nor vice versa); the streaming is robust.
-BufferSize
The amount, in bytes, to read at a time before passing it on to the hashing algorithm.
@Hashbrown777
Hashbrown777 / wslMount.ps1
Last active November 19, 2022 06:08
Attach one or more physical disks to a wsl instance, using encryption and formatting options `wsl --mount` doesn't support
View wslMount.ps1
<# calling the wslMount function will attach one or more physical disks to a wsl instance
-drives
This parameter specifies which disks, and is an array of what Windows calls the Friendly Name.
You can see these by calling `Get-PhysicalDisk`.
-count
The list of friendly names are not necessarily unique (eg if you have multiple of the same model of drive).
Count is required so that you know how many disks have been matched, and will be passed to WSL.
-wsl
The name of the wsl install you want to interact with, defaults to the default wsl instance.
-mount
@Hashbrown777
Hashbrown777 / attachsmb.ps1
Last active January 20, 2023 13:25
A set of functions that enable you to make use of multiple local SMB servers (eg ssh -L), or get explorer to interact with samba shares of other machines on non-standard ports
View attachsmb.ps1
<#
#Required:
Install-Module -Name LoopbackAdapter -MinimumVersion 1.2.0.0
#run in admin terminal
#you do NOT need to disable/remove SMB 1.0/CIFS
#Troubleshooting:
#You can check [attempted] forwardings and [successful] listeners here, respectively
netsh interface portproxy show v4tov4
@Hashbrown777
Hashbrown777 / ssh.ps1
Last active December 7, 2022 06:45
A workaround for Windows official openssh client not supporting -f nor -N
View ssh.ps1
#accepts all arguments for ssh except command, -N and -f
#command can be piped in
Filter ssh-f {
$N = $False
if (!$_) {
#the same as -N
$_ = 'read'
$N = $True
}
$_ = 'echo SUCCESS;' + $_
@Hashbrown777
Hashbrown777 / grep.ps1
Last active October 23, 2022 12:28
SilverSearcher on Windows. Asynchronous simultaneous file searches and pretty match highlights cropped to window (by default)
View grep.ps1
#https://gist.github.com/Hashbrown777/a5a02e2fd3eeed4485d4ba073ef3b143
. "$PSScriptRoot/async.ps1"
. "$PSScriptRoot/files.ps1"
. "$PSScriptRoot/style.ps1"
#default switches of $True emulate grep/ag behaviour, use `-flag:$False` to disable
Function Grep { [CmdletBinding(PositionalBinding=$False)]Param([Parameter(ValueFromPipeline)]$Input,
#display params
[switch]$OnlyMatching, [switch]$Files, $Max=-1,
#async params
View randomalphanumeric.sh
cat /dev/urandom \
| tr -dc '[:upper:][:digit:]' \
| fold -w ${1:-8} \
| head -1
@Hashbrown777
Hashbrown777 / _hashes
Last active January 31, 2022 07:47
Hashing stuff