Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Management.Automation;
using Microsoft.PowerShell.Commands;
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class CmdletWithPathBase : PSCmdlet
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Management.Automation;
using System.Security;
using System.Text;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Timers;
public sealed class TitleChange : EventArgs
{
public DateTime TimeGenerated { get; } = DateTime.Now;
Add-Type @'
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Management.Automation;
using System.Runtime.InteropServices;
using Microsoft.PowerShell.Commands;
$ps = Split-Path $PSHOME
$pwsh = @(
Join-Path $ps '7-preview/pwsh.exe'
Join-Path $ps '7/pwsh.exe'
)
$script = {
class SizeConvert {
static [string[]] $Suffix = 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'
@santisq
santisq / .gitignore
Last active September 19, 2024 22:53
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
benchmarks/
BenchmarkDotNet.Artifacts/
tools/dotnet
# User-specific files
*.suo
*.user
Invoke-RestMethod https://gist.githubusercontent.com/santisq/bd3d1d47c89f030be1b4e57b92baaddd/raw/aa78870a9674e9e4769b05e333586bf405c1362c/Measure-Expression.ps1 |
Invoke-Expression
Add-Type @'
using System;
using System.Text;
public static class TestString
{
public static string Create(string @string, int len) =>
Invoke-RestMethod https://gist.githubusercontent.com/santisq/bd3d1d47c89f030be1b4e57b92baaddd/raw/236c79877ebaa75ce81c1806ef568d77abad6724/Measure-Expression.ps1 |
Invoke-Expression
$range = [System.Linq.Enumerable]::Range(1, 100kb)
time @{
'foreach + if' = {
param($range)
$result = foreach ($i in $range) { if ($i % 2) { $i } }
@santisq
santisq / nonblockingform.ps1
Created June 5, 2024 21:03
easiest example i could think of using a runspace
using namespace System.Management.Automation.Runspaces
using namespace System.Windows.Forms
using namespace System.Drawing
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
$form = [Form]@{ StartPosition = [FormStartPosition]::CenterScreen }
$iss = [initialsessionstate]::CreateDefault2()
$iss.Variables.Add([SessionStateVariableEntry]::new('form', $form, ''))
$PrintWindowCode = @'
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
public class ScreenCapture
{
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect);