Skip to content

Instantly share code, notes, and snippets.

View iamsunny's full-sized avatar

Sunny Sharma iamsunny

View GitHub Profile
@iamsunny
iamsunny / AsyncMethods
Last active March 12, 2018 08:05
C# Class with an Async Method
class AsyncMethods
{
/// <param name="sleepTime">sleep time in seconds</param>
public async Task<bool> SleepAsync(int sleepTime)
{
Console.WriteLine($"SleepAsync for {sleepTime} seconds starts");
await Task.Delay(sleepTime*1000);
Console.WriteLine($"SleepAsync for {sleepTime} seconds completes");
return true;
}
@iamsunny
iamsunny / Test AsyncAwait Execution Times
Last active March 12, 2018 08:31
Methods to Test Async/Await execution
static void Main(string[] args)
{
//initialize an stopwatch
var sw = new Stopwatch();
// run "TestAsyncMethods"
sw.Start();
Execute().GetAwaiter().GetResult();
sw.Stop();
Console.WriteLine($"Done! Completed in {sw.Elapsed}");
@iamsunny
iamsunny / temp
Last active April 16, 2018 04:33
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Huic ego, si negaret quicquam interesse ad beate vivendum quali uteretur victu, concederem, laudarem etiam; Hanc se tuus Epicurus omnino ignorare dicit quam aut qualem esse velint qui honestate summum bonum metiantur. Idem etiam dolorem saepe perpetiuntur, ne, si id non faciant, incidant in maiorem. Duo Reges: constructio interrete. <i>Cyrenaici quidem non recusant;</i> <a href="http://loripsum.net/" target="_blank">Id Sextilius factum negabat.</a> Velut ego nunc moveor. Illis videtur, qui illud non dubitant bonum dicere -; <i>Haec para/doca illi, nos admirabilia dicamus.</i> <mark>Eam tum adesse, cum dolor omnis absit;</mark> Callipho ad virtutem nihil adiunxit nisi voluptatem, Diodorus vacuitatem doloris. <a href="http://loripsum.net/" target="_blank">Nulla erit controversia.</a> </p>
<p>Quis est, qui non oderit libidinosam, protervam adolescentiam? De malis autem et bonis ab iis animalibus, quae nondum depravata sint, ait optime iudicari. <a href
@iamsunny
iamsunny / LetsEncryptClient.cs
Created May 11, 2018 13:07 — forked from ayende/LetsEncryptClient.cs
ACME v2 client for Let's Encrypt
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@iamsunny
iamsunny / handy-links.md
Last active July 27, 2018 10:02
Handy links
@iamsunny
iamsunny / dotnetcore_httpclient_filedownload.cs
Created February 6, 2019 06:27
Download files using HttpClient in .NET Core
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];
@iamsunny
iamsunny / debug-custom-domain-on-localhost.bat
Last active June 25, 2019 05:42
Debug Custom Domain on Localhost (Windows)
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 / azure-powershell-create-custom-role.ps1
Created July 30, 2019 12:49
Create Custom Roles in Azure using Powershell
$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 / failed-to-initialize-microsoft-azure-storage-emulator
Last active August 27, 2019 10:49
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 / post-data-to-google-sheets-from-html-form.js
Created August 19, 2019 20:58
post to google sheets from html form using ajax
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.")}
});