Skip to content

Instantly share code, notes, and snippets.

View fearthecowboy's full-sized avatar
🏠
Happily Working from home

Garrett Serack fearthecowboy

🏠
Happily Working from home
View GitHub Profile
@fearthecowboy
fearthecowboy / Test.csproj
Last active April 18, 2024 23:37
The definitive way to use PowerShell from an msbuild script
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- #1 Place this line at the top of any msbuild script (ie, csproj, etc) -->
<PropertyGroup><PowerShell># 2>nul || type %~df0|find /v "setlocal"|find /v "errorlevel"|powershell.exe -noninteractive -&amp; exit %errorlevel% || #</PowerShell></PropertyGroup>
<!-- #2 in any target you want to run a script -->
<Target Name="default" >
<PropertyGroup> <!-- #3 prefix your powershell script with the $(PowerShell) variable, then code as normal! -->
<myscript>$(PowerShell)
#!/usr/bin/env -S deno run --reload -A --ext=ts
` <#`;
import { readdir } from "node:fs/promises";
import { join,resolve } from "node:path";
import { argv } from "node:process";
let size = 0;
let count = 0;
@fearthecowboy
fearthecowboy / sample.ts.ps1
Created January 26, 2024 19:34
PowerShell and Deno Script
#!/usr/bin/env -S deno run --reload -A
` <#`
// this is all typescript code here.
console.log("we're running typescript using deno");
/*#>
# this is PowerShell code here.
if (-not (get-command deno)) { irm https://deno.land/install.ps1 | iex }
deno run --reload -A ($MyInvocation.MyCommand.Path) @args
#*/
@fearthecowboy
fearthecowboy / remap-keys-to-winkey.reg
Created January 28, 2014 16:09
Registry settings to Remap CapsLock to Windows Key (import and reboot)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,5b,e0,3a,00,00,00,00,00
#fixed now!
Param(
[string]$html,
[string]$docx
)
# make the powershell process switch the current directory.
$oldwd = [Environment]::CurrentDirectory
[Environment]::CurrentDirectory = $pwd
@fearthecowboy
fearthecowboy / powershell_evil.cs
Last active August 25, 2022 11:02
Snooping the unbound powershell parameters during dynamic parameter generation
/// ... somewhere in your cmdlet (might need to be PSCmdlet?)
private const BindingFlags BindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public;
// provided you have a tasty function to reflect private fields/properties
protected object TryGetProperty(object instance, string fieldName) {
// any access of a null object returns null.
if (instance == null || string.IsNullOrEmpty(fieldName)) {
return null;
}
#!/usr/bin/env -S bash # > NUL 2>&1 || echo off && goto init:
function shh() { return; } ; shh \\<<shh
## THIS IS THE START OF THE POWERSHELL SCRIPT #################################
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
$ProgressPreference='SilentlyContinue'
$ErrorActionPreference = 'Stop'
if ($v) {
$Version = "v${v}"
@fearthecowboy
fearthecowboy / bit-coin.user.js
Last active June 17, 2022 15:37
Tampermonkey script to turn Bitcoin into "Dutch Tulip Bulbs"
// ==UserScript==
// @name Replace 'Bitcoin' On Webpages
// @namespace https://gist.github.com/fearthecowboy
// @description Replaces bitcoin on websites.
// @include http://*
// @include https://*
// @include file://*
// @exclude http://userscripts.org/scripts/review/*
// @exclude http://userscripts.org/scripts/edit/*
// @exclude http://userscripts.org/scripts/edit_src/*
@fearthecowboy
fearthecowboy / FluentConsole.ps1
Created June 9, 2022 19:16
FluentConsole for PowerShell
<##
FluentConsole Functions
(C) 2022 Garrett Serack
License: MIT
Usage:
dot source this into your script (. FluentConsole.ps1 )
and then you can use the colon-prefixed functions.
You can separate colon-function calls with ';' or '|' or a newline.
@fearthecowboy
fearthecowboy / test.ps1
Created April 29, 2022 20:53
This one script can be saved as any of [.cmd, .bat, .ps1, .sh] and will run under cmd.exe, powershell, pwsh, bash and zsh.
#!/usr/bin/env -S bash # > NUL 2>&1 || echo off && goto init:
function shh() { return; } ; shh \\<<shh
## THIS IS THE START OF THE POWERSHELL SCRIPT #################################
write-host "Setting variable in powershell"
$env:abc=300
return;
## THIS IS THE END OF THE POWERSHELL SCRIPT ###################################
<#