Skip to content

Instantly share code, notes, and snippets.

@Xainey
Xainey / TargetPath.Tests.ps1
Last active March 11, 2016 20:31
Resolving paths in Pester TestDrive
function Set-Shortcut
{
[CmdletBinding()]
param (
[string] $ShortcutPath,
[string] $TargetPath
)
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($PSCmdlet.GetUnresolvedProviderPathFromPSPath($ShortcutPath))
$Shortcut.TargetPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($TargetPath)
@Xainey
Xainey / QuickOpen.ahk
Created March 21, 2016 14:44
Open, maximize, or minimize a program with a hotkey
; Open / Bring to Front / Minimize Program
; For hotkey syntax - https://autohotkey.com/docs/Hotkeys.htm
; Example Alt-C to open Conemu
!c::OpenProgram("c:\PortableApps\ConEmu64.exe")
ToggleWindow(TheWindowTitle)
{
SetTitleMatchMode,2
DetectHiddenWindows, Off
@Xainey
Xainey / Solve-RPN.ps1
Created March 24, 2016 14:19
Powershell Concept for Reverse Polish Notation
#Powershell concept for Revese Polish Notation
#Based on ealier JS and Java variants: http://codepen.io/xainey/pen/ojbZdj
function Solve-RPN
{
[CmdletBinding()]
[OutputType([System.Double])]
param
(
[parameter(Mandatory = $true)]
@Xainey
Xainey / tasks.json
Created March 24, 2016 15:44
run .vscode pester tests
// A task runner that invokes Pester to run all Pester tests under the
// current workspace folder.
// NOTE: This Pester task runner requires an updated version of Pester (>=3.4.0)
// in order for the problemMatcher to find failed test information (message, line, file).
// If you don't have that version, you can update Pester from the PSGallery like so:
//
// PS C:\> Update-Module Pester
//
// If that gives an error like:
# Concept Based Off Faker: https://github.com/fzaninotto/Faker
function Random-Name
{
[CmdletBinding()]
[OutputType([System.Double])]
param
(
[parameter(Mandatory = $false)]
[ValidateSet('male', 'female')]
/*
Create an application named MarketDemo that creates instance of class Stock.
This class can contain collection of objects of a class Fruit or Vegetable, or Beverage (use generics).
Class Stock must contain a method of displaying goods and a method of sorting by price.
Each class must contain
* constructors (with parameters and without parameters),
* properties (title, price, weight)
* overridden method ToString.
*/
function SIDtoUsername($sid)
{
$objSID = New-Object System.Security.Principal.SecurityIdentifier($sid)
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
return $objUser.Value
}
function getPrinters($computer)
{
$spacer = "-" * 99
$Adder = {
param ([int] $x)
return (
{
param ([string] $y)
return ($x + $y)
}.GetNewClosure()
)
}
@Xainey
Xainey / Send-WakeOnLan.ps1
Created May 18, 2016 17:05
Send WOL Packet
function Send-WakeOnLan
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, Position=1, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
[Alias("Name")]
[string[]] $ComputerName
)
Begin
@Xainey
Xainey / PoshLagrange.ps1
Last active May 24, 2016 19:56
Lagrange Interpolation in Powershell
<#
Lagrange Interpolation Example
#>
function Point($x, $y)
{
return [pscustomobject]@{
PSTypeName = 'Point'
x = $x
y = $y