Skip to content

Instantly share code, notes, and snippets.

View dlwyatt's full-sized avatar

Dave Wyatt dlwyatt

  • Ontario, Canada
  • 09:51 (UTC -05:00)
  • X @MSH_Dave
View GitHub Profile
@dlwyatt
dlwyatt / autofocus.ahk
Created July 2, 2020 03:44
Tweaked autofocus
; joyfocus 1.1 LazyTech
; A public domain work under the UnLicense. See LICENSE for details.
#Persistent
axesToWatch := { 2JoyX: 0, 2JoyY: 0, 2JoyZ: 0, 2JoyU: 0, 2JoyR: 0, 2JoyV: 0, 3JoyX: 0, 3JoyY: 0, 3JoyZ: 0, 3JoyR: 0, 3JoyU: 0, 3JoyV: 0}
for key, val in axesToWatch
{
axesToWatch[key] := GetKeyState(key)
}
SetTimer, WatchAxis, 100 ; milliseconds
@dlwyatt
dlwyatt / profile.ps1
Last active September 1, 2017 14:06
Stop putting System. at the beginning of type tab completion!
function TabExpansion2
{
<# Options include:
RelativeFilePaths - [bool]
Always resolve file paths using Resolve-Path -Relative.
The default is to use some heuristics to guess if relative or absolute is better.
To customize your own custom options, pass a hashtable to CompleteInput, e.g.
return [System.Management.Automation.CommandCompletion]::CompleteInput($inputScript, $cursorColumn,
@{ RelativeFilePaths=$false }
@dlwyatt
dlwyatt / ScriptingGames122015.ps1
Last active December 8, 2015 13:10
December scripting games - Dave Wyatt
$list = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
8 Maids a milking
9 Ladies dancing
@dlwyatt
dlwyatt / PesterVersionCheck.ps1
Last active September 4, 2015 16:06
TeamCity Example Code
try
{
$path = '%system.teamcity.build.checkoutDir%'
Set-Location $path
$psd1 = Join-Path $path Pester.psd1
Import-Module $psd1 -ErrorAction Stop
$xml = Join-Path $path Test.Version.xml
@dlwyatt
dlwyatt / Oops.ps1
Last active September 26, 2016 18:38
Flags Enum without explicit values
# Add an enum with All constant
Add-Type -TypeDefinition @'
using System;
[Flags]
public enum EnumSample
{
One,
Two,
Three,
@dlwyatt
dlwyatt / Test-Flags.ps1
Last active September 26, 2016 18:38
Flags Enum parameter demo
Add-Type -TypeDefinition @'
using System;
[Flags]
public enum MyEnum
{
Option1 = 0x1,
Option2 = 0x2,
Option3 = 0x4,
All = Option1 | Option2 | Option3
@dlwyatt
dlwyatt / SetupComplete.cmd
Last active September 26, 2016 18:38
Vagrant base box with Sysprep
@powershell.exe -NonInteractive -ExecutionPolicy Bypass -NoProfile -File "%~dp0\SetupComplete.ps1"
@dlwyatt
dlwyatt / ParseIt.ps1
Created May 7, 2015 00:21
Parse CSVDE-style SID string
$funky = '010500000000000515000000AA7045F3F11474788C4A5F8AE9030000'
try
{
$bytes = [byte[]]@(
for ($i = 0; $i -lt $funky.Length - 1; $i += 2)
{
[byte]::Parse($funky.Substring($i, 2), [System.Globalization.NumberStyles]::AllowHexSpecifier)
}
)
@dlwyatt
dlwyatt / ConvertTo-Hashtable.ps1
Created March 5, 2015 14:40
ConvertTo-Hashtable
function ConvertTo-Hashtable
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[psobject[]] $InputObject
)
process
{
@dlwyatt
dlwyatt / example.Tests.ps1
Created February 14, 2015 13:25
Pester Example
# Import the stuff you'll be testing. Could be dot-sourcing a ps1 file here, importing a module, whatever you need.
# If importing a mdoule, make sure you've only got one copy of it imported, or weird things can happen when you start
# to get into mocking.
Remove-Module [S]omeDscResource
Import-Module $PSScriptRoot\SomeDscResource.psm1
# All of the Pester tests in a script must go inside a Describe block; you can mave many Describe blocks in the same
# script, if you like. Make sure to put the opening brace on the same line as Describe, since this is just a function
# pretending to be a keyword; no assistance from the parser allowing us to put opening braces on their own lines.