Skip to content

Instantly share code, notes, and snippets.

View poojarsn's full-sized avatar

santosh poojari poojarsn

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Unit Circle and Sine Wave Animation</title>
<style>
body {
margin: 0;
}
canvas {
display: block;
const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');
const path = require('path');
const { URL } = require('url');
// Base URL for the WACE exams directories
const BASE_URL = 'https://www.vaultofthewace.xyz/biology/WACE%20exams/';
// Local base directory to save downloaded content
@poojarsn
poojarsn / DIscoped.cs
Last active September 17, 2024 02:46
How to inject a scoped service into a singleton service?
public class SomeSingletonService(IServiceScopeFactory serviceScopeFactory)
: SingletonService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using IServiceScope scope = serviceScopeFactory.CreateScope();
var dbContext = scope
.ServiceProvider
.GetRequiredService<ApplicationDbContext>();
@poojarsn
poojarsn / sample.json
Last active October 9, 2024 03:18
Sample
{
"openapi": "3.0.1",
"info": {
"title": "Payment Experience API",
"description": "This API is meant to be used as a starting point for any new Experience APIs",
"contact": {
"name": "Thunder Team",
"email": "[email protected]"
},
"version": "1.0"
@poojarsn
poojarsn / AzureB2c-CodeVerifier
Created January 10, 2024 02:34
Code Verifier and Nonce
#region private methods
private void RememberCodeVerifier(RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> n, string codeVerifier)
{
var properties = new AuthenticationProperties();
properties.Dictionary.Add("cv", codeVerifier);
//if left blank or set to 0, the setting is not used. OOTB default is 15min
if(ConfigurationManager.AppSettings[AzureB2CConstants.Keys.NonceLifetime] != null &&
double.TryParse("30", out double lifetime) && lifetime > 0)
{
@poojarsn
poojarsn / reactjs.tsx
Created December 3, 2023 22:08
Reactjs-Starter
//----1-----
function SomeComponent()
{
return <d><H1>Hellow World</H1><>;
}
export default SomeComponent;
//Concise Way
export default SomeComponent()
{
@poojarsn
poojarsn / externallogincallback.cs
Created January 15, 2023 12:27
Sitecore Azure AD B2C User.Identity.IsAuthenticated is false Set AuthenticationManager
/*
Reference
https://blog.baslijten.com/federated-authentication-in-sitecore-error-unsuccessful-login-with-external-provider/
*/
public void SignIn(string returnUrl)
{
// The param returnUrl is configured in Azure B2C Identity Provider.
// The redirect URL is to redirect to externallogincallback method of Sitecore Owin and then load returnUrl Sign-in
var properties = new AuthenticationProperties() { RedirectUri = "https://abc/identity/externallogincallback?ReturnUrl=/sign-in" };
//Azure AD B2C Owin Context is null , once the token is acquired by authorization code flow
//Set Authentication Manager profile
var authenticated = HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");
// Send Access Token bearer to api to get logged user details
var loggedInUser = AuthenticationManager.BuildVirtualUser(string.Format(@"{0}\{1}", "external", "User-ID"), true);
loggedInUser.RuntimeSettings.AddedRoles.Add(authenticated.Result.Identity.Claims.First().Value);
loggedInUser.Profile.FullName = string.Format("{0} {1}", authenticated.Result.Identity.Name, authenticated.Result.Identity.Claims.Last().Value);
loggedInUser.Profile.Save();
@poojarsn
poojarsn / swagger.cs
Created July 16, 2022 11:19
Get all controller action mvc asp.net
Assembly asm = Assembly.GetAssembly(typeof(MyWebDll.MvcApplication));
var controlleractionlist = asm.GetTypes()
.Where(type=> typeof(System.Web.Mvc.Controller).IsAssignableFrom(type))
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
.Where(m => !m.GetCustomAttributes(typeof( System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
.Select(x => new {Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute",""))) })
.OrderBy(x=>x.Controller).ThenBy(x => x.Action).ToList();
@poojarsn
poojarsn / Redis Cache Get Set
Created October 14, 2021 09:54
Redis Cache Get Set PrivateSetterContractResolver
public class SessionService : ISessionService
{
private readonly ICryptoService _cryptoService;
private readonly string _encryptionKey = ConfigurationManager.AppSettings[AppSettingKeys.Common.SessionEncryptionKey];
public SessionService(ICryptoService cryptoService)
{
_cryptoService = cryptoService;
}