Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / attachsmb.ps1
Last active April 17, 2024 09:14
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) {
(async () => {
const ignore = /^http:\/\/waltercosand.com\/CosandScores\/Composers%20[^/]+\//;
const urls = [
'http://waltercosand.com/CosandScores/Composers%20A-D/',
'http://waltercosand.com/CosandScores/Composers%20E-K/',
'http://waltercosand.com/CosandScores/Composers%20L-P/',
'http://waltercosand.com/CosandScores/Composers%20Q-Z/'
].reverse();
const skip = [
'http://waltercosand.com/CosandScores/Composers%20L-P/Mozart,%20W.%20A/Mozart%20-%20Complete%20Works%20for%20Piano/'