Skip to content

Instantly share code, notes, and snippets.

View pradeepn's full-sized avatar

Pradeep Nagendiran pradeepn

  • Chennai, IN
View GitHub Profile
@pradeepn
pradeepn / Program.cs
Created March 20, 2024 06:51
ASP.NET Core 6.0 Bootstrapping
///NEW .net 6.0 WAY
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
@pradeepn
pradeepn / Program.cs
Created March 20, 2024 06:46
ASP.NET Core 3.1 to 5.0 Bootstrapping
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
@pradeepn
pradeepn / Program.cs
Created March 20, 2024 06:44
ASP.NET Core 2.1 Bootstrapping
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
@pradeepn
pradeepn / google-cloud-pubsub-example.cs
Created December 16, 2022 13:56 — forked from yetanotherchris/google-cloud-pubsub-example.cs
Google Cloud Pub/Sub C# example
//
// Google Cloud Pub/Sub C# example
// NOTE: This is a .NET Core 1.1 console app.
// Use "dotnet run" to run it, run setup.ps1 first.
//
using System;
using System.Collections.Generic;
using Google.Cloud.PubSub.V1;
using Google.Protobuf;
public static class TaskHelper
{
/// <summary>
/// Runs a TPL Task fire-and-forget style, the right way - in the
/// background, separate from the current thread, with no risk
/// of it trying to rejoin the current thread.
/// </summary>
public static void RunInBackground(this Task task, Action action)
{
task.Run(action).ConfigureAwait(false);
//install or update nvm using following curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
//see latest nvm version
nvm version
//see list of node versions locally installed
nvm list
//see list of node version available in remote
@pradeepn
pradeepn / RedisStore.cs
Created February 20, 2021 13:22
Redis Store Implementation
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DistributedCaching.Core
{
@pradeepn
pradeepn / MinifyHtmlAttribute.cs
Created May 7, 2020 07:22 — forked from herman1vdb/MinifyHtmlAttribute.cs
Minify HTML with inline css/javascript for MVC C# as a ActionFilterAttribute
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using ZetaProducerHtmlCompressor.Internal;
namespace PmdWebsite.Helpers.ActionFilters
@pradeepn
pradeepn / LoadCPU.cs
Created April 26, 2020 19:31
Gist to load CPU by 80%
///https://stackoverflow.com/questions/2514544/simulate-steady-cpu-load-and-spikes
int percentage = 80;
for (int i = 0; i < Environment.ProcessorCount; i++)
{
(new Thread(() =>
{
Stopwatch watch = new Stopwatch();
watch.Start();
while (true)
{
@pradeepn
pradeepn / AccountsController.cs
Created August 22, 2019 08:41
JWT Token Generation, Validation and Refresh Token in .NET Core
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;