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)
=> self?.Select((item, index) => (item, index)) ?? new List<(T, int)>();
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.
x = x << 1; // x = x * 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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. |