Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / prompt.Microsoft.PowerShell_profile.ps1
Last active October 16, 2023 14:45
neat coloured prompt for powershell that shows `user@pcname:pwd\nwinsymbol>` where winsymbol changes between red and green if the last command resulted in an error or no
#let the user know the current user, machine, directory, and success status of last command
$Script:prompt = '>'
function Prompt {
$error = !$?
Write-Host
Write-Host -NoNewline -ForegroundColor Yellow ([Environment]::UserName)
Write-Host -NoNewline '@'
Write-Host -NoNewline -ForegroundColor Cyan ([Environment]::MachineName)
Write-Host -NoNewline ':'
Write-Host -ForegroundColor Magenta $PWD.ProviderPath
@Hashbrown777
Hashbrown777 / alignbytes.ps1
Last active September 28, 2023 02:32
Resizes files anchoring to EOF
'3705688449 ,setup_cyberpunk_2077_build_4902785change_6408866_with_ep1_rl_(64bit)_(67718)-25.bin
2124976 ,setup_cyberpunk_2077_build_4902785change_6408866_with_ep1_rl_(64bit)_(67718).exe
30669496 ,setup_cyberpunk_2077_redmod_build_4902785change_6408866_with_ep1_rl_(64bit)_(67718).exe' -split '\n' `
| %{
$expected,$name = $_ -split ','
$expected = [UInt32]$expected
$diff = (gci $name).Length - $expected
if (!$diff) {
return
@Hashbrown777
Hashbrown777 / _wireguard.ps1
Last active September 7, 2023 14:45
Multiple wireguard connexions with an open port on each (azirevpn)
./single.ps1 bob paris
./private.ps1 steve newyork
./private.ps1 greg seattle
./private.ps1 emma newyork
<#
Will create
a wireguard tunnel to paris using bob's credentials in the init [non-]namespace,
a tunnel to seattle with the interface name "seattle" using greg's config under the namespace "greg",
and two tunnels to newyork (interfaces both called 'newyork') using options from steve and emma (under namespaces of the same name respectively)
@Hashbrown777
Hashbrown777 / #WSL stuff
Last active August 28, 2023 07:57
wsl stuff
#todo explanation
class RC {
hidden $type = $NULL
hidden $code = $NULL
hidden $size = $NULL
hidden RC($type) {
$this.type = $type
$this.size = $type::New(1)[0]::MaxValue + 1
}
@Hashbrown777
Hashbrown777 / free.ps1
Created July 8, 2023 15:22
free up space on my c drive
cd $env:LOCALAPPDATA
(
'Ubisoft*',
'Grip',
'Evil*',
'ride3',
'Squad*',
'Remnant',
'Mordhau',
'Dead*',
@Hashbrown777
Hashbrown777 / audioTabBbCode.ps1
Last active July 6, 2023 13:35
Grab all music metadata and output it in bbcode
. './metadata.ps1'
Function Bbcode-Row {
Param ([switch]$Heading, $From)
Begin {
'[tr]'
}
Process {
('[th]','[td]')[!$Heading]
if ($From) {
@Hashbrown777
Hashbrown777 / resize.ps1
Last active June 23, 2023 02:14
Resizes high-resolution images to appropriate sizes for use in websites
Add-Type -AssemblyName System.Drawing
# https://gist.github.com/Hashbrown777/fae023538705a1f3f01cd795a2314e61#file-metadata-ps1
. './metadata.ps1'
Filter PointF {
[System.Drawing.PointF]::new($_[0], $_[1])
}
Function ToArray {
Begin { $output = [System.Collections.ArrayList]::new() }
@Hashbrown777
Hashbrown777 / _punchHoles.ps1
Last active June 22, 2023 17:01
In files identified as containing corrupted blocks punch holes in the valid blocks so they don't take up as much space
$blockSize = 4KB
$buffer=[byte[]]::new($blockSize)
Get-ChildItem -File `
| Sort-Object -Property Length
| %{
"$($_.Name)`t$($_.Length / 1MB -bor 0)MB"
$path = $_.FullName
#useful if your files are patchable eg torrent-sourced
sudo cp --reflink=always $path "${path}_rescued"
@Hashbrown777
Hashbrown777 / _NetLbfoTeam.ps1
Created June 19, 2023 15:53
After extracting the needed files, get `New-NetLbfoTeam` working in win10
try {
Switch ($args[0]) {
#entrypoint
$NULL {
if (!(Start-Process `
-FilePath 'PsExec' `
-ArgumentList (
'-s',
'-nobanner',
'-accepteula',