Skip to content

Instantly share code, notes, and snippets.

View vexx32's full-sized avatar
💜
Turn your faults into faultlore and share them with the world.

Rain Sallow (/u/ta11ow) vexx32

💜
Turn your faults into faultlore and share them with the world.
View GitHub Profile
@vexx32
vexx32 / VS Code Settings.json
Created August 6, 2018 04:09
Personal settings for VS Code
{
"files.defaultLanguage": "powershell",
"editor.fontFamily": "'Anonymous Pro', Consolas",
"editor.cursorBlinking": "phase",
"files.autoSave": "onWindowChange",
// Powershell Settings
"powershell.codeFormatting.openBraceOnSameLine": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
@vexx32
vexx32 / UnRemovableModule.ps1
Created August 10, 2018 15:42
Creates a test module that unconditionally throws an exception during the remove-module call
$Module = New-Module -Name 'ImportMe' -ScriptBlock {
class TryMeException : System.Exception {
TryMeException() : base() {}
TryMeException([string]$Message) : base($Message) {}
}
$onremove = {
throw [TryMeException]::new("HOW DARE YOU STEAL THAT CAR")
}
$ExecutionContext.SessionState.Module.OnRemove += $onremove
}
if (suffix == 'u' || suffix == 'U')
{
if (UInt32.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out uint u))
{
ulong testresult = u * (ulong) multiplier;
if (testresult > UInt32.MaxValue)
{
result = testresult;
}
else

Keybase proof

I hereby claim:

  • I am vexx32 on github.
  • I am ta11ow (https://keybase.io/ta11ow) on keybase.
  • I have a public key ASBjV0F0zB7el1gfWjEiPjwpe1RdXDwJ_GJQ1TZsJSfvigo

To claim this, I am signing this object:

// Generic this --> multiple type handling
internal static bool TryConvertSByte(double value, out sbyte outValue)
{
if (value < sbyte.MinValue || value > sbyte.MaxValue)
{
outValue = 0;
return false;
}
@vexx32
vexx32 / BenchMarkDotNet.ParseBinary.cs
Created October 4, 2018 15:53
benchmark for binary parsing in PS Core
///////////////////////////////////////
////////// BENCHMARK RESULTS //////////
///////////////////////////////////////
// * Summary *
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17134.286 (1803/April2018Update/Redstone4)
Intel Core i3-3240 CPU 3.40GHz (Ivy Bridge), 1 CPU, 4 logical and 2 physical cores
Frequency=3312801 Hz, Resolution=301.8594 ns, Timer=TSC
.NET Core SDK=2.1.402
@vexx32
vexx32 / CSV_NoHeader.ps1
Created November 2, 2018 15:07
Trim the header row of a CSV
$Properties = 'GivenName', 'Surname', 'Department', 'EmailAddress', 'Office'
Get-ADUser -Filter 'Department -like "*"' -Properties $Properties |
Select-Object -Property $Properties |
ConvertTo-Csv -NoTypeInformation | # Convert to CSV string data without the type metadata
Select-Object -Skip 1 | # Trim header row, leaving only data columns
Set-Content -Path "c:\emailaddress.csv"
@vexx32
vexx32 / Invoke-PSNotification.ps1
Last active November 9, 2018 14:08 — forked from TylerLeonhardt/Invoke-PSNotification.ps1
Show notifications on Linux using PowerShell! Thanks to notify-send(1)
function Invoke-PSNotification {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param(
[Parameter(Position=0, Mandatory, ValueFromPipeline)]
[object[]]
$Body,
[string]
$Summary = 'PowerShell Notification',
# allow self-referential definitions
[Flags()]
enum Food {
Apple
Banana
Celery
Grape
Fruit = Apple -bor Banana -bor Grape
}
type TransformToSKColorAttribute() =
inherit ArgumentTransformationAttribute()
let matchColor name =
seq {
match name with
| knownColor when ColorNames.Contains(knownColor) -> yield ColorLibrary.[knownColor]
| clear when String.Equals(clear, "transparent", StringComparison.OrdinalIgnoreCase) -> yield SKColor.Empty
| patternString when WildcardPattern.ContainsWildcardCharacters(patternString) ->
let pattern = WildcardPattern(patternString, WildcardOptions.IgnoreCase)