Skip to content

Instantly share code, notes, and snippets.

View gabriel-vanca's full-sized avatar

Gabriel Vanca gabriel-vanca

View GitHub Profile
@gabriel-vanca
gabriel-vanca / Invoke-CommandWithRetries.psm1
Last active July 19, 2024 03:07 — forked from deadlydog/PowerShellUtilities.psm1
Invoke-CommandWithRetries.psm1 - Retries a Powershell command n-times upon failure.
<#
.SYNOPSIS
Retries a Powershell command n-times upon failure.
.DESCRIPTION
The cmdlet is capable of retrying a PowerShell command passed as a [ScriptBlock] according to the user defined number of retries and time between retries.
.PARAMETER ScriptBlock
PoweShell command(s) as a ScriptBlock that will be executed and retried in case of Errors.
Make sure the script block throws an error when it fails, otherwise the cmdlet won't run the retry logic.
@gabriel-vanca
gabriel-vanca / Disable-SSLv3.ps1
Last active July 20, 2024 04:41 — forked from markthiessen/DisableSslv3.ps1
Disable-SSLv3 - PowerShell script for disabling SSLv3 - Refactored
# MS Security bulletin: https://learn.microsoft.com/en-us/security-updates/SecurityAdvisories/2015/3009008
# NOTE: This registry change requires that the system be restarted.
Function Test-RegKeyExists {
param (
$key
)
If (!(Test-Path -Path $key)) {
@gabriel-vanca
gabriel-vanca / PowerShellSingleFileScriptTemplate.ps1
Last active July 21, 2024 21:33 — forked from deadlydog/PowerShellSingleFileScriptTemplate.ps1
PowerShell template for a single-file script
<#
.SYNOPSIS
A brief description of the function or script. This keyword can be used only once in each topic.
.DESCRIPTION
A detailed description of the function or script. This keyword can be used only once in each topic.
.COMPONENT
The name of the technology or feature that the function or script uses, or to which it is related.

Inspired by this article. Neat tricks for speeding up integer computations.

Note: cin.sync_with_stdio(false); disables synchronous IO and gives you a performance boost. If used, you should only use cin for reading input (don't use both cin and scanf when sync is disabled, for example) or you will get unexpected results.

Multiply by a power of 2

x = x << 1; // x = x * 2

@gabriel-vanca
gabriel-vanca / C#_foreach-with-index.md
Last active September 14, 2024 17:46 — forked from Ninjanaut/foreach-with-index.md
C#_foreach-with-index
using System.Collections.Generic;
using System.Linq;

namespace Utility.Extensions
{
    public static class IEnumerableExtensions
    {
        public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self)
 =&gt; self?.Select((item, index) =&gt; (item, index)) ?? new List&lt;(T, int)&gt;();