Skip to content

Instantly share code, notes, and snippets.

#Thread-safe data structure to store prompt strings and communicate about state
$prompt = [Collections.Concurrent.ConcurrentDictionary[String,String]]@{}
$prompt.infix = ''
Set-PSReadlineOption -ExtraPromptLineCount 1 # For 2-line prompt
Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -Action {
if($prompt.state -eq 'rerender') {
$prompt.isIdleRender = 'yes'
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
$prompt.isIdleRender = 'no'
@brianmed
brianmed / duSort.csx
Created March 28, 2018 03:20
dotnet script for sorting du output.. yay
#! "netcoreapp2.0"
#r "nuget: NetStandard.Library, 2.0.0"
# [bpm@Orfgum] c:~/playground/c>sudo du -k ~ | dotnet script ./duSort.csx > joy
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using (var stdin = new StreamReader(Console.OpenStandardInput()))
if ([Environment]::OSVersion.Version.Major -lt 10)
{
Write-Error "Windows 10 or above is required to run this script"
exit -1
}
Add-Type -Language CSharp -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
@General-Gouda
General-Gouda / Encryption.ps1
Last active December 8, 2020 15:31
Encryption helper cmdlets
#----------------------------------------------------#
# Decrypts password using Certificate
#----------------------------------------------------#
function Get-DecryptedPassword
{
[CmdletBinding()]
param
(
$EncryptedPassword,
$EncryptedKey,
@Jaykul
Jaykul / Set-CodeCmd.ps1
Last active March 7, 2018 19:21
This makes it so you can type just `code` to start VS Code (even Insiders) in the current folder, even ... in Explorer!
#requires -RunAsAdministrator
<#
.Synopsis
Creates (or alters) a "code" command for opening Visual Studio Code (or VS Code Insiders)
.Description
Recreates the "code.cmd"" batch file command that starts Visual Studio Code (or VS Code Insiders)
1. Adds logic to make it open in the current folder if you don't pass parameters.
2. Makes "code" work as a command in Windows 10 Explorer's address bar.
#>
[CmdletBinding()]
@Jaykul
Jaykul / FileTypes.ANSI.Format.ps1xml
Last active March 13, 2018 00:10
ANSI Escape Sequences
<?xml version="1.0" encoding="utf-8" ?>
<!-- *******************************************************************
This is Joel "Jaykul" Bennett's coloring format file for PowerShell 5.1
******************************************************************** -->
<Configuration>
<SelectionSets>
<SelectionSet>
<Name>FileSystemTypes</Name>
<Types>
<TypeName>System.IO.DirectoryInfo</TypeName>
@indrora
indrora / 00readme.md
Last active November 12, 2021 07:24
DeadUpdate: Kickin' it bigtime.

... my first disclosure. Man, it feels weird doing this.

update 6/6/16 I would like to stress something: I'm not saying "Don't buy an ASUS device" -- I see a lot of people who want to lambaste ASUS for this and boycott their hardware. This isn't what I want people to be doing by any stretch. Stupidly, I like the ASUS hardware I have (it's nice for the price) and I would rather see a pressure on ASUS as an OEM to stop shipping "value added software" to consumers; If you want to help Microsoft in pushing this mentality, go buy a signature machine from them. Microsoft provides support, but also only ships windows and a few select utilities that are essential to the functioning of the system (think: Radeon/Optimus and nVidia control panels) and fall heavily on the hardware makers (ATI, nVidia, Intel) to provide support for the harware.

Consider an ASUS device all you want. Start putting pressure on Microsoft that consumers want bloat-free devices and start voting with your money. Microsoft's store

@Jaykul
Jaykul / You Need To Implement Non-Generic.md
Created April 27, 2016 01:48
Implementing IEnumerator<T> in PowerShell

In order to implement IEnumerator<T> you have to explicitly implement the Current member for IEnumerator<T> and IEnumerator ... but PowerShell won't let you have two different implementations of the same property, nor will it let you explicitly implement an interface member. So we do one at a time, like this:

First, make a non-generic IEnumerator, but implemented with the type you want in the end:

    class __Generator : System.Collections.IEnumerator {
        [int]$Actual = 0

        [object]get_Current() {
            return $this.Actual
@davidfowl
davidfowl / Example1.cs
Last active September 2, 2024 12:36
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
@Jaykul
Jaykul / Manifest.psm1
Last active December 28, 2023 05:34
Update Module Version ... or anything else
function Update-Manifest {
#.Synopsis
# Update a PowerShell module manifest
#.Description
# By default Update-Manifest increments the ModuleVersion, but it can set any key in the Module Manifest, its PrivateData, or the PSData in PrivateData.
#
# NOTE: This cannot currently create new keys, or uncomment keys.
#.Example
# Update-Manifest .\Configuration.psd1
#