Skip to content

Instantly share code, notes, and snippets.

Avatar
💖
Stay warm

Joel Sallow (/u/ta11ow) vexx32

💖
Stay warm
View GitHub Profile
@vexx32
vexx32 / The Desert Music.svg
Last active Sep 12, 2020
The Desert Music, by William Carlos Williams
View The Desert Music.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Song of Myself.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View The Wasteland.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vexx32
vexx32 / get-classes-and-ids.ps1
Created Jul 13, 2020
PowerShell script to retrieve lists of classes and ids from a html string and output a CSS skeleton for them
View get-classes-and-ids.ps1
[System.Text.RegularExpressions.MatchCollection]$classesAndIds = [regex]::Matches($html, 'class="(?<Classes>[^"]+)"|id="(?<Id>[^"]+)"')
$classes = [System.Collections.Generic.HashSet[string]]::new()
$ids = [System.Collections.Generic.HashSet[string]]::new()
$classesAndIds.Captures.Groups.ForEach{
if ($_.Name -eq 'Classes') {
$_.Value -split '[\s\r\n]' -replace '\{/?block:[^}]\}' |
Where-Object {$_} |
ForEach-Object {
@vexx32
vexx32 / Get-Age.ps1
Last active Jun 20, 2020
for Mark Kraus
View Get-Age.ps1
function Get-Age {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateScript(
{
$_ -lt [datetimeoffset]::UtcNow
}
)]
[datetimeoffset]
@vexx32
vexx32 / ConvertJsonPropertiesToTitleCase.ps1
Created May 15, 2020
Converts a JSON object into a PSObject, replacing these_property_names with ThesePropertyNames
View ConvertJsonPropertiesToTitleCase.ps1
$Object = ConvertFrom-Json '{ "base_url": "https://foo.bar" }'
$Properties = foreach ($property in $Object.PSObject.Properties) {
$newNameFragments = @($property.Name -split '_').ForEach{
[CultureInfo]::CurrentCulture.TextInfo.ToTitleCase($_)
}
# Select-Object property rename via selector hashtable; Name is the new name, Expression is the original name
@{ Name = -join $newNameFragments; Expression = $property.Name }
}
@vexx32
vexx32 / GetEnclosedArea.cs
Last active Mar 24, 2020
Gets the approximate area enclosed by an SKPath instance by comparing its total bounded area to the percentage of evenly-distributed points that are "contained" within the path.
View GetEnclosedArea.cs
internal static float GetEnclosedArea(this SKPath path)
{
SKRect bounds = path.TightBounds;
var boundedArea = bounds.Width * bounds.Height;
var totalPoints = 10000;
var enclosedPoints = 0;
for (float x = bounds.Left; x < bounds.Right; x += bounds.Width / (float)Math.Sqrt(totalPoints))
{
for (float y = bounds.Top; y < bounds.Bottom; y += bounds.Height / (float)Math.Sqrt(totalPoints))
View chrissyregex2.ps1
$string = 'hostname.database.table.schema'
if ($string -match '(?<Hostname>\w+)\.(?<Database>\w+)\.(?<Table>\w+)\.(?<Schema>\w+)') {
$matches.Remove(0)
[PSCustomObject]$matches
}
View JavaMethodGrab.ps1
Get-Content -Path $File | ForEach-Object {
if ($_ -match '(?<MethodName>\w+)\((<Arguments>.*?)\) *(?={)') {
$matches['Method'] = $matches[0]
$matches.Remove(0)
[PSCustomObject]$matches
}
}
View Invoke-ConditionalAction.fs
namespace PSFSharp
open System.Management.Automation
open System.Management.Automation.Internal
[<Cmdlet(VerbsLifecycle.Invoke, "ConditionalAction",
ConfirmImpact = ConfirmImpact.Medium, SupportsShouldProcess = true)>]
[<Alias("?!")>]
type InvokeConditionalActionCommand() =
inherit PSCmdlet()