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 / 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;();
@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 / 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 / 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
#>

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 / 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.
@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 / Get-SystemSoftware.ps1
Last active July 23, 2024 06:30
Get-SystemSoftware
Function Get-SystemSoftware{
<#
.SYNOPSIS
Gather software installed on a local or remote device
.DESCRIPTION
Gather Software and information about the software installed on a local or remote device using the registry or WMI
.PARAMETER ComputerName
Computer to gather software on
.PARAMETER QueryType
Specify how you want to gather the information
@gabriel-vanca
gabriel-vanca / Get-DotNet.ps1
Last active August 2, 2024 01:09
Manage DotNet
function Get-InstalledDotNet {
<#
.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-SysInfo.ps1
Last active August 28, 2024 01:55
Get-SysInfo
Function Get-SysInfo {
<#
.SYNOPSIS
Gether system inforamtion
.DESCRIPTION
Gather information such as the Computer Name, OS, Memory Information, Disk Information and CPU Information on a local or remote system.
.PARAMETER Computer
The local or remote system to gather information from
#>
[CmdletBinding()]