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 / Search-HashTable.ps1
Last active July 27, 2024 11:10
Search-HashTable
<#
.SYNOPSIS
This function performs a search of a hash table using a provided key.
.DESCRIPTION
This function performs a search of a hash table using a provided key.
It returns the value matching the key if found, and null otherwise.
The case sensitive search has O(1) time complexity while the case insensitive search has
O(N) time complexity, where N is the number of key-value pairs in the hash table.
#>
@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 / Clean-DotNet.ps1
Last active August 2, 2024 02:36
Clean-DotNet
function Get-InstalledDotNetFrameworkFromRegistry {
<#
.SYNOPSIS
Display version of .net installed on a system
.DESCRIPTION
Query the registry on a local or remote system to display the version of .net installed
.PARAMETER ComputerName
The name of the computer to run the query on
#>
@gabriel-vanca
gabriel-vanca / Get-ReleaseFromGithub.ps1
Last active August 6, 2024 00:54
Get-ReleaseFromGithub
function Test-Repo {
param (
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $Repo
)
$repoName = $NULL
try {
$testUri = "https://api.github.com/repos/$Repo"
$temp = (Invoke-RestMethod -Method GET -Uri $testUri)
@gabriel-vanca
gabriel-vanca / Join-Strings.ps1
Last active August 15, 2024 22:49
Join-Strings
function Join-Strings
{
<#
.SYNOPSIS
Join strings with a specified separator.
.DESCRIPTION
Join strings with a specified separator.
This strips out null values and any duplicate separator characters.
@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;();