Skip to content

Instantly share code, notes, and snippets.

View AnthonyMastrean's full-sized avatar
🏡
Working remotely

Anthony Mastrean AnthonyMastrean

🏡
Working remotely
View GitHub Profile
@AnthonyMastrean
AnthonyMastrean / Disable-WindowsUpdateAutoReboot.ps1
Last active August 10, 2017 23:16
Prevent Windows update from forcibly rebooting the computer
$key = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
if(-not(Test-Path $key)) {
New-Item $key -Force
}
New-ItemProperty -Path $key -Name "NoAutoRebootWithLoggedOnUsers" -PropertyType DWORD -Value 1
@AnthonyMastrean
AnthonyMastrean / Behaviors_Functionality.cs
Created September 9, 2013 20:52
A comparison of unit mask converters
[Behaviors]
public class UnitMaskConverterBehaviors
{
It should_convert_0_to_A = () => _converter.Convert(0).ShouldEqual('A');
It should_convert_1_to_B = () => _converter.Convert(1).ShouldEqual('B');
It should_convert_2_to_C = () => _converter.Convert(2).ShouldEqual('C');
It should_convert_4_to_D = () => _converter.Convert(4).ShouldEqual('D');
It should_convert_8_to_E = () => _converter.Convert(8).ShouldEqual('E');
It should_convert_16_to_F = () => _converter.Convert(16).ShouldEqual('F');
It should_convert_32_to_G = () => _converter.Convert(32).ShouldEqual('G');
@AnthonyMastrean
AnthonyMastrean / Connect-VM.ps1
Last active December 21, 2015 03:49
Somehow, the Hyper-V PowerShell module does not contain a connection function.
#requires -Version 3.0
function Connect-VM {
[CmdletBinding(DefaultParameterSetName='name')]
param(
[Parameter(ParameterSetName='name')]
[Alias('cn')]
[System.String[]]$ComputerName=$env:COMPUTERNAME,
[Parameter(Position=0,
Mandatory,ValueFromPipelineByPropertyName,
@AnthonyMastrean
AnthonyMastrean / rakefile.rb
Created August 13, 2013 14:42
Args for custom Rake tasks
task :default => [ :puts ]
def says(*args, &block)
copy = block
body = proc {
copy.call
puts args.message
}
@AnthonyMastrean
AnthonyMastrean / Invoke-RakeTabExpansion.ps1
Last active March 10, 2022 05:32
PowerShell tab completion for Rake tasks via PowerTab
if(Test-Path Function:Register-TabExpansion) {
Register-TabExpansion -Name 'rake' -Type Command -Handler {
rake -T | %{ $_ -match '(^rake)(?<task>.*)(#.*)' } | %{ $matches['task'] } | %{ $_.Trim() }
}
}
@AnthonyMastrean
AnthonyMastrean / Export-ChocolateyPackages.ps1
Last active September 11, 2017 15:57
Export installed Chocolatey packages to a packages.config
$packages = Get-ChildItem (Join-Path $ENV:chocolateyinstall 'lib')
@AnthonyMastrean
AnthonyMastrean / New-FileSystemWatcher.ps1
Last active December 12, 2015 12:19
Lame implementation of Guard in PowerShell
function New-FileSystemWatcher {
param(
[ValidateNotNullOrEmpty()]
[string] $Path = (Split-Path $MyInvocation.MyCommand.Definition)
)
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $path
$watcher.IncludeSubdirectories = $true
@AnthonyMastrean
AnthonyMastrean / IAmAnAction.cs
Created October 25, 2012 14:13
Request handler redux
public interface IAmAnAction
{
void Handle(dynamic data = null);
}
@AnthonyMastrean
AnthonyMastrean / InstallShieldConfiguration.rb
Created October 22, 2012 15:06
InstallShield multi version support
module InstallShield
class InstallShieldConfiguration
attr_accessor :command, :parameters, :ism, :product_version, :product_code
attr_reader :new_product_code
def initialize
@command = File.join ENV['ProgramFiles(x86)'], 'InstallShield/2010 StandaloneBuild/System/IsCmdBld.exe'
@parameters = []
end
@AnthonyMastrean
AnthonyMastrean / nuspec.rb
Created September 27, 2012 21:32
Automatic discovery of NuGet dependencies.
def auto_add_dependencies(projects)
projects.each do |project|
each_project_dependency do |dependency|
@dependencies.push dependency
end
end
end
def get_packages_config(project)
return File.join File.dirname project, 'packages.config'