Skip to content

Instantly share code, notes, and snippets.

View iamsunny's full-sized avatar

Sunny Sharma iamsunny

View GitHub Profile
@iamsunny
iamsunny / important-azure-powershell-commands.md
Last active March 1, 2023 13:28
Important Azure PowerShell commands
View important-azure-powershell-commands.md

Azure Cloud Shell has an up to date PowerShell instance

show current account in context

az account show

change the subscription in context

az account set --subscription

assign role to an existing ServicePrincipal for another resource group

@iamsunny
iamsunny / Get-StorageAccountSize.ps1
Created March 14, 2021 14:19
Get Azure Storage Size using PowerShell | Get Azure Storage Capacity using PowerShell
View Get-StorageAccountSize.ps1
param($resourceGroup, $storageAccountName)
# usage
# Get-StorageAccountSize -resourceGroup <resource-group> -storageAccountName <storage-account-name>
# Connect to Azure
Connect-AzureRmAccount
@iamsunny
iamsunny / Generate PFX from cert and key using openssl
Created April 27, 2020 10:25
Generate PFX from cert and key using openssl.txt
View Generate PFX from cert and key using openssl
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt
@iamsunny
iamsunny / SQL Server Performance Tuning Queries .sql
Last active December 3, 2019 05:40
Queries for SQL Server Performance Tuning
View SQL Server Performance Tuning Queries .sql
/* Get top 100 executed Stored Procedures ordered by Execution Count */
-----------------------------------------------------------------------------------------------------
    SELECT TOP 100 qt.text AS 'SP Name', qs.execution_count
AS 'Execution Count',  
    qs.execution_count/DATEDIFF(Second, qs.creation_time, GetDate()) AS 'Calls/Second',
    qs.total_worker_time/qs.execution_count AS 'AvgWorkerTime',
    qs.total_worker_time AS 'TotalWorkerTime',
    qs.total_elapsed_time/qs.execution_count AS 'AvgElapsedTime',
    qs.max_logical_reads, qs.max_logical_writes, qs.total_physical_reads,
    DATEDIFF(Minute, qs.creation_time, GetDate()) AS 'Age in Cache'
@iamsunny
iamsunny / Loop PowerShell Invoke-WebRequest.ps1
Last active August 8, 2022 13:49
Loop Invoke-WebRequest in Powershell
View Loop PowerShell Invoke-WebRequest.ps1
class TrustAllCertsPolicy : System.Net.ICertificatePolicy {
[bool] CheckValidationResult([System.Net.ServicePoint] $a,
[System.Security.Cryptography.X509Certificates.X509Certificate] $b,
[System.Net.WebRequest] $c,
[int] $d) {
return $true
}
}
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new()
@iamsunny
iamsunny / post-data-to-google-sheets-from-html-form.js
Created August 19, 2019 20:58
post to google sheets from html form using ajax
View post-data-to-google-sheets-from-html-form.js
function subscribe() {
var email = $("#emailId").val();
$.ajax({
url: "https://docs.google.com/forms/d/e/1FAIpQLSc8TP0eS1iPwap4dVM6IlEWtkw_kHfpmDedlLWc5lQ88_2xCw/formResponse?",
data: { "entry.1709137143": email}, // replace the numeric part of "entry.______" with the actual field name. more fields can be added in the data object
type: "POST",
success: function(d) {alert("thank you, you're subscribed to ngIndia 2020 updates")},
error: function(d) {alert("oops! something went wrong, please try again.")}
});
@iamsunny
iamsunny / failed-to-initialize-microsoft-azure-storage-emulator
Last active August 27, 2019 10:49
Failed to initialize Microsoft Azure storage emulator
View failed-to-initialize-microsoft-azure-storage-emulator
// install SQL Server Express if not installed
// ensure SQL Server Express is running
// start cmd with Admin Priviledge
// navigate to C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
cd C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
// run
AzureStorageEmulator.exe init -server . -sqlinstance SQLEXPRESS -forcecreate
@iamsunny
iamsunny / azure-powershell-create-custom-role.ps1
Created July 30, 2019 12:49
Create Custom Roles in Azure using Powershell
View azure-powershell-create-custom-role.ps1
$role = [Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition]::new()
$role.Name = "Custom Role"
$role.IsCustom = $true
$role.Description = "Can perform assigned activities"
$perms = 'Microsoft.Compute/virtualMachines/read','Microsoft.Compute/virtualMachines/write'
$role.Actions = $perms
$role.assignableScopes = "/subscriptions/11111111-1111-1111-1111-111111111111"
New-AzRoleDefinition -Role $role
@iamsunny
iamsunny / debug-custom-domain-on-localhost.bat
Last active June 25, 2019 05:42
Debug Custom Domain on Localhost (Windows)
View debug-custom-domain-on-localhost.bat
netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.65.43.21 connectport=31661 connectaddress=127.0.0.1
netsh interface portproxy show v4tov4
netsh interface portproxy delete v4tov4 listenport=80 listenaddress=127.65.43.21
// append hosts file
127.65.43.21 <the domain name you want to debug>
@iamsunny
iamsunny / dotnetcore_httpclient_filedownload.cs
Created February 6, 2019 06:27
Download files using HttpClient in .NET Core
View dotnetcore_httpclient_filedownload.cs
var urlsFilePath = @"file.txt"; // file contains a tab separated filename/fileUrl combination on each line
var lines = File.ReadAllLines(urlsFilePath);
var outFileFolder = "images";
var httpClient = new HttpClient();
foreach (var line in lines)
{
var fileName = line.Split('\t')[0];