Skip to content

Instantly share code, notes, and snippets.

View AfroThundr3007730's full-sized avatar
🔧
Hacking all the things...

Eddie Carswell AfroThundr3007730

🔧
Hacking all the things...
View GitHub Profile
@AfroThundr3007730
AfroThundr3007730 / Hide-ConsoleWindow.ps1
Last active October 4, 2024 21:38
Hides a console window (even the new WindowsTerminal.exe)
# Adapted from https://stackoverflow.com/a/74976541/4087397
function Hide-ConsoleWindow() {
# Import 'ShowWindowAsync' method to properly hide windows
Add-Type -Name User32 -Namespace Win32 -MemberDefinition `
'[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
# Mangle the window title to ensure it's unique and allow us to find it
$Host.UI.RawUI.WindowTitle = [Guid]::NewGuid()
# Find our process by the mangled window title and hide it
[Win32.User32]::ShowWindowAsync(
(Get-Process).where{ $_.MainWindowTitle -eq $Host.UI.RawUI.WindowTitle }.MainWindowHandle, 0)
@AfroThundr3007730
AfroThundr3007730 / Install-PythonRelease.ps1
Last active January 8, 2024 23:12
Install the Python language interpreter
Set-StrictMode -Version Latest
#Requires -Version 7
function Install-PythonRelease {
<# .SYNOPSIS
Install the Python language interpreter #>
param(
# Install for all users (requires admin)
[Switch]$AllUsers,
# Use beta build instead of latest stable
@AfroThundr3007730
AfroThundr3007730 / Update-LocalNugetRepository.ps1
Created June 27, 2023 20:23
Update a local Nuget repo from a remote repo
Set-StrictMode -Version Latest
# Inspired by: https://weblogs.asp.net/jongalloway/downloading-a-local-nuget-repository-with-powershell
function Update-LocalNugetRepository {
<# .SYNOPSIS
Update a local Nuget repo from a remote repo #>
Param(
# Remote repository feed URL
[Uri]$FeedURLBase = 'https://aka.ms/sme-extension-feed',
# Local repository directory
@AfroThundr3007730
AfroThundr3007730 / Get-GHRepoList.ps1
Last active October 4, 2024 21:39
Gets a list of repositories of a GitHub user
Set-StrictMode -Version Latest
function Get-GHRepoList {
<# .SYNOPSIS
Gets a list of repositories of a GitHub user. #>
Param(
# User to enumerate
[string]$User,
# Page size to request
[int]$Size = 100
@AfroThundr3007730
AfroThundr3007730 / xdg_dirs.sh
Last active March 30, 2024 23:20
Profile snippet to redirect $HOME clutter to the proper XDG directory
#!/bin/sh
#/etc/profile.d/xdg_dirs.sh
# SPDX-License-Identifier: GPL-3.0-or-later
###############################################################################
# XDG variables
###############################################################################
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
@AfroThundr3007730
AfroThundr3007730 / Invoke-GithubFileRequest.ps1
Created April 3, 2023 18:41
Powershell function to retrieve a file from a Github repository
Set-StrictMode -Vesion Latest
function Invoke-GithubFileRequest {
<# .SYNOPSIS
Retrieves a file from a Github repository. #>
[Alias('gh_curl')]
Param(
# URL of file to download
[Parameter(Mandatory)]
[Uri]$URL,
@AfroThundr3007730
AfroThundr3007730 / draw_grid.py
Created March 14, 2023 01:49
Draws a grid of conigurable size
#!/usr/bin/python
from PIL import Image
def draw_grid(size_x=1920, size_y=1080, grid_x=3, grid_y=3, border=2, img_x=0, img_y=0):
if img_x == 0 or img_y == 0:
img_x, img_y = size_x, size_y
img = Image.new('RGB', (img_x, img_y), 'white')
pixels = img.load()
@AfroThundr3007730
AfroThundr3007730 / Get-ArpEntry.ps1
Last active March 7, 2024 23:19
PowerShell wrapper of C# function to retrieve system ARP table entries
Set-StrictMode -Version Latest
function Get-ArpEntry {
<# .SYNOPSIS
Retrieve system ARP table entries #>
Param(
# Retrieve all entries (not just learned)
[switch]$All
)
@AfroThundr3007730
AfroThundr3007730 / Check-Elevation.ps1
Last active December 9, 2024 07:08
Guard functions for powershell version and elevation level
# Only run if elevated as administrator
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$admin = [Security.Principal.WindowsBuiltInRole]::Administrator
if (!([Security.Principal.WindowsPrincipal]$identity).IsInRole($admin)) {
Write-Output 'We are not elevated, launching elevated powershell...'
Start-Process -FilePath powershell.exe -Verb RunAs -ArgumentList $MyInvocation.MyCommand.Source
Start-Sleep 10
exit 0
}
@AfroThundr3007730
AfroThundr3007730 / Edit-VMDKHeader.ps1
Created October 24, 2022 20:12
Edit the metadata header of a VMDK file
Set-StrictMode -Version Latest
function Edit-VMDKHeader {
<# .SYNOPSIS
Edit the metadata header of a VMDK file #>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
Param(
# The VMDK file to edit
[Parameter(Mandatory)]
[string]$VMDKFile