Skip to content

Instantly share code, notes, and snippets.

View GustavoAmerico's full-sized avatar

Gustavo Américo GustavoAmerico

View GitHub Profile
@GustavoAmerico
GustavoAmerico / install-gamerico-helps.ps1
Last active June 7, 2025 15:52
This script should used for install help functions for work with git, azure cli and k8s. All ClI should be installed on the machine for helps works.
$runAsElevated =($PSVersionTable.OS -match "Windows" -and [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")) -or
($PSVersionTable.OS -match "Linux" -and $EUID -eq 0);
if($runAsElevated){
$ProfileFile = $($PROFILE | Select-Object AllUsersAllHosts).AllusersAllHosts;
}else{
$ProfileFile = $($PROFILE | Select-Object CurrentUserAllHosts).CurrentUserAllHosts;
}
$ProfilePath = $ProfileFile.Substring(0, $ProfileFile.LastIndexOf("\") + 1);
$FileExists = [System.IO.File]::Exists($ProfileFile);
@GustavoAmerico
GustavoAmerico / git-help.ps1
Last active July 12, 2025 19:36
Essa função é responsável por centralizar alguns comandos verbosos do git
#Author: Gustavo Américo
#Repository: https://gist.github.com/GustavoAmerico
function Git-Update-All-BranchsFromBase {
#Esse script é responsável por executar um merge automático de uma branch base para todas as outras branchs. Em caso de conflitos o script faz rollback e pula a branch conflitante
param([Parameter(Mandatory = $true)][String]$branchNamePattern, $remoteName = 'origin', $branchBase = 'master')
$branchsToUpdate = (git branch --all | % { $_.ToString().Replace("remotes/$remoteName/", '').Trim() } | Select-String -Pattern $branchNamePattern);
$branchsToUpdate | % {
git checkout $_;
git pull --all;
@GustavoAmerico
GustavoAmerico / azurecli-help.ps1
Last active July 29, 2025 13:44
Esse arquivo centraliza alguns comandos muito utilizados, por mim, que exigem uma montagem verbosa
function Get-PublicIPV6 {
#This function return the public IP of the machine
#It is used to register the IP on Azure SQL Server firewall rules
try {
$mypublicip = (Invoke-WebRequest https://v6.api.ipinfo.io/ip | Select-Object -Property Content).Content.Trim();
}
catch {
}
@GustavoAmerico
GustavoAmerico / kubectl-help.ps1
Last active June 7, 2025 12:53
Gets the list of certificates (cert-manager) that are scheduled to renew in the next X days
function k8s-certificates-renew {
param([Parameter()][int]$days = 15)
((kubectl get certificates -A -o json | ConvertFrom-Json).items) |
? { [Datetime]($_.status.renewalTime) -lt (Get-Date).AddDays($days) } |
% { [pscustomobject]@{Name = $_.metadata.name; RenewAt = [DateTime]$_.status.renewalTime; Namespace = $_.metadata. Namespace } }
}
function k8s-Select-Resources {
@GustavoAmerico
GustavoAmerico / CopyPRTagsToBuild.ps1
Last active October 22, 2022 18:02
Script to copy Azure DevOps pullrequest tags to AzureDevOps Pipeline Build
$tagNameExpression = "target-*"
# Define the PR URI based in azure devops pipeline runtime variables
$prUri = "$(System.CollectionUri)/$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)/labels?api-version=6.0-preview.1";
$buildUri= "$(System.CollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/tags";
# Get PullRequest Details
$FoundTags = Invoke-WebRequest `
-Uri $prUri `
-Authentication Bearer `
@GustavoAmerico
GustavoAmerico / AddOrUpdateTableAndColumnDescription
Last active April 22, 2021 17:32
Procedure for add or update SQL Server table and column description
CREATE PROCEDURE dbo.PROC_AddOrUpdateTableAndColumnDescription
@fullName varchar(255),
@description varchar(255)
AS
/*
Table exemple: <schema>.<table name> dbo.MyTable
Column Exemple: <schema>.<table name>.<column name> dbo.MyTable.Id
*/
/*Extrai o primeiro valor antes do ponto, representa o schema*/
@GustavoAmerico
GustavoAmerico / azure-database-export.ps1
Created September 18, 2019 02:26
Script para executar a exportação do Azure SQL Database para um Azure Storage
#Esse script pode ser utilizado em tarefa do AzureDevOps para executar o backup da base de dados dentro do processo de Build ou Release
param(
$BaseStorageUri = "https://<your-storage>.blob.core.windows.net/backup-database",
$StorageKey = "<Shared key>",
$DatabaseName = @( "db1","db2","db3"),
$ResourceGroupName = "<database-resource-group-name>",
$ServerName = "<database-server-name>",
$serverAdmin = "<database-user-with-permission-login>",
$serverPassword = "<database-user-with-permission-password>"