Skip to content

Instantly share code, notes, and snippets.

View schittli's full-sized avatar

Tom-- schittli

  • Biel / Bienne, Switzerland
  • 09:24 (UTC +02:00)
View GitHub Profile
@dfch
dfch / CacheManagerBase.cs
Created March 3, 2017 07:32
CacheManager - Strongly typed caching with System.Runtime.Caching.MemoryCache - https://d-fens.ch/2017/03/02/nobrainer-strongly-typed-caching-with-system-runtime-caching-memorycache/
/**
* Copyright 2017 d-fens GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Jaykul
Jaykul / Install-LegacyFirefox.ps1
Created February 21, 2017 00:05
How to install a specific version of Firefox and make sure it doesn't get updated
# NOTE: Hard-coded to 64bit, default install, MaintenanceService off
$FFxVersion = '44.0'
$locale = 'en-US'
$Downloads = Convert-Path $Home\Downloads
$IsoPath = Join-Path $Downloads agent.iso
$FFxPath = Join-Path $Downloads ffx.exe
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest "https://download.mozilla.org/?product=firefox-${FFxversion}-SSL&os=win64&lang=${locale}" -Outfile $FFxPath
@jdhitsolutions
jdhitsolutions / Check-ModuleUpdate.ps1
Last active May 30, 2023 11:17
Test installed PowerShell modules against online versions in the PowerShell Gallery.
[cmdletbinding()]
[outputtype("moduleInfo")]
Param(
[Parameter(Position = 0, HelpMessage = "Enter a module name or names. Wildcards are allowed.")]
[ValidateNotNullorEmpty()]
[string[]]$Name = "*"
)
Write-Verbose "Getting installed modules"
Try {
@Jaykul
Jaykul / ValidateUnique.md
Last active May 7, 2022 01:13
Validating PowerShell class properties

The simplest way to enforce rules on PowerShell class properties is to set the Type of the property, of course. But sometimes you want something a little bit more clever than that. One solution is to use a Validate* attribute, like ValidateRange or ValidateLength or ValidateSet attribute...

However, you can write your own, by just deriving from ValidateArguments() or something that derives from that, like the ValidateEnumeratedArguments class allows you to validate a whole array of items.

For instance, a simple validator would be one that validates uniqueness, based on a specific property. Our validator will be created fresh each time it's used, and then each item in the array will be passed through ValidateElement, so this works:

using namespace System.Collections.Generic
usin
@richpeck
richpeck / default
Last active June 7, 2017 12:35
NGinx SSL Setup
# /etc/nginx/sites-enabled/default
##########################################
##########################################
## General Server Setup ##
##########################################
##########################################
@Jaykul
Jaykul / Controller-Original.ps1
Last active April 15, 2023 23:24
Remote Invoke Concept
#.Synopsis
# Copy a script to a remote session and invoke it
[CmdletBinding()]
param(
# Path to script to run remotely
[Alias('PSPath')]
[string]$ScriptPath,
# Hashtable or array for splatting to script
[Alias('Args')]
@Jaykul
Jaykul / New-RootSignedCert.ps1
Created February 3, 2017 00:20
Generate a self-signed root certificate, and then an SSL cert signed by that root
#.Synopsis
# Generate a self-signed root certificate and then generate an SSL certificate signed by it.
#.Description
# Generates a self-signed root certificate and an SSL certificate signed by it.
# Puts the root public key in a .pem file for adding to PHP's CAcert.pem
param(
# Used as the CN for the Root certificate
$RootName = "NO LIABILITY ACCEPTED - Test Root $(get-date -f "yyyy-MM-dd")",
# Used as the CN for the SSL certificate
$Subject = "${Env:ComputerName}.${Env:UserDnsDomain}",
@Jaykul
Jaykul / Must.ps1
Last active March 13, 2018 00:34
An alternative to `Should` which uses normal PowerShell syntax, and supports -All and -Any
# The Must assertion for Pester tests.
Set-Alias Must Assert-That
function Assert-That {
[CmdletBinding(DefaultParameterSetName='equal', HelpUri='http://go.microsoft.com/fwlink/?LinkID=113423', RemotingCapability='None')]
param(
[Parameter(ValueFromPipeline=$true)]
[psobject]
${InputObject},
[Switch]
@Jaykul
Jaykul / PoshStep.psm1
Created January 26, 2017 06:35
Invoke-Step with dependencies
class DependsOn : System.Attribute {
[string[]]$Name
DependsOn([string[]]$name) {
$this.Name = $name
}
}
function Invoke-Step {
@alan-null
alan-null / UnicornDependencyGraphGenerator.ps1
Last active October 14, 2024 18:16
Generate unicorn dependency graph using PowerShell. Analyse and improve your configurations or easily fix existing issues
function Get-ComputedDependencyGraphUrl {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0 )]
[Hashtable]$allDependenciesClean
)
begin {
Write-Verbose "Cmdlet Get-ComputedDependencyGraphUrl - Begin"
}