Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / wslMount.ps1
Last active December 3, 2023 20:13
Attach one or more physical disks to a wsl instance, using encryption and formatting options `wsl --mount` doesn't support
<# 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 October 17, 2024 20:12
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
<#
#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 April 17, 2023 14:16
A workaround for Windows official openssh client not supporting -f nor -N
#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)
#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
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
#
pdfimages -all big.pdf . #poppler-utils
rename -v 's/^[^0-9]*//' .*.jpg
convert '*.jpg' -resize 50% %03d.jpeg #imagemagick
convert '*.jpeg' small.pdf
@Hashbrown777
Hashbrown777 / baka_deluge.js
Last active January 22, 2022 13:53
Update deluge's total uploaded byte tally via `state/torrents.fastresume`
(async () => {
const output = open().document;
//generate a script to run over your deluge state file
output.write(
`<pre>#!/bin/bash
mkdir _
cd _
#split up the file and name them correctly, disregard the byte-counts
awk \\
'BEGIN { RS="[de]40:"; ORS=FS=":" } { if ($1 != "") { for (i = 2; i <= NF; i++) print $i > substr($1, 0, 40) } }' \\
&{ Param($hostname, $port)
try {
$tmp = [Net.Sockets.TcpClient]::new($hostname, $port)
$tmp.Connected
$tmp.close()
return
}
catch [System.Net.Sockets.SocketException] {
$Error[0].Exception | Out-Host
}
@Hashbrown777
Hashbrown777 / 1_sort.js
Created December 7, 2021 12:45
Non-comparative sorting with flexible chunking
function sort(array, radix, getDigit) {
const counts = new Uint32Array(radix);
const jobs = [{start:0, end:array.length, offset:0}];
while (jobs.length) {
const {start, end, offset} = jobs.pop();
counts.fill(0);
counts[null] = start;
const sorting = array.slice(start, end);
for (let index = 0; index < sorting.length; ++index) {