Skip to content

Instantly share code, notes, and snippets.

View anuraj's full-sized avatar
🏠
Working from home

Anuraj anuraj

🏠
Working from home
View GitHub Profile
@anuraj
anuraj / CSSIsolationActionFilter.cs
Created March 1, 2022 01:54
CSS Isolation Action Filter for .NET Framework MVC projects
public class CSSIsolationActionFilterAttribute : ActionFilterAttribute
{
public CSSIsolationActionFilterAttribute()
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
ViewResult viewResult = filterContext.Result as ViewResult;
RazorView view = viewResult?.View as RazorView;
@anuraj
anuraj / feature-flags.json
Last active January 26, 2022 04:04
Feature Flags
{
"showSecondCTA": true
}
@anuraj
anuraj / MinimalAPIs.md
Created September 11, 2021 11:29 — forked from davidfowl/MinimalAPIs.md
Minimal APIs at a glance

Minimal APIs

WebApplication

Creating an application

var app = WebApplication.Create(args);

app.MapGet("/", () => "Hello World");
@anuraj
anuraj / index.js
Created April 23, 2021 12:41
index.js
'use strict';
const express = require('express');
// Constants
const PORT = 8095;
const HOST = '0.0.0.0';
// App
const app = express();
@anuraj
anuraj / function.csx
Created June 12, 2020 17:30
Azure Function
private static readonly AzureKeyCredential Credentials = new AzureKeyCredential("KEY");
private static readonly Uri Endpoint = new Uri("ENDPOINT");
private static readonly string SearchApiKey = "KEY";
private static readonly string BitlyKey = "KEY";
private static readonly string TwitterConsumerKey = "CONSUMERKEY";
private static readonly string TwitterConsumerSecret = "CONSUMERSECRET";
private static readonly string TwitterAccessToken = "ACCESSTOKEN";
private static readonly string TwitterAccessTokenSecret = "ACCESSTOKENSECRET";
private static readonly string[] searchTerms = new[] { "Application Technology", "Architecture",
"Artificial Intelligence", "Open Source", "SAAS", "Business Transformation",
@anuraj
anuraj / NewsSearch.cs
Created June 12, 2020 17:29
News Search using Bing News Search API
//Add reference of Microsoft.Azure.CognitiveServices.Search.NewsSearch Package
using Microsoft.Azure.CognitiveServices.Search.NewsSearch;
public static async Task<News> GetSearchResults(string searchTerm)
{
var searchClient = new NewsSearchClient(new ApiKeyServiceClientCredentials(SearchApiKey));
return await searchClient.News.SearchAsync(query: searchTerm, market: "en-us", count: 5);
}
@anuraj
anuraj / createtweet.cs
Created June 12, 2020 17:27
Create and Publish tweet.
//Add reference of Tweetinvi
using Tweetinvi;
using Tweetinvi.Models;
public static void CreateTweet(string text)
{
var credentials = new TwitterCredentials(TwitterConsumerKey,
TwitterConsumerSecret,
TwitterAccessToken,
TwitterAccessTokenSecret);
@anuraj
anuraj / ExtractKeyPhrases.cs
Last active June 12, 2020 17:28
Extract Key Phrases using Text Analytics
//Add reference of Azure.AI.TextAnalytics
using Azure;
using Azure.AI.TextAnalytics;
using Microsoft.Azure.CognitiveServices.Search.NewsSearch.Models;
public static async Task<string> GetKeywords(string text)
{
var client = new TextAnalyticsClient(Endpoint, Credentials);
var response = await client.ExtractKeyPhrasesAsync(text);
var tags = new List<string>();
@anuraj
anuraj / CreateShortURL.cs
Last active June 12, 2020 17:26
Azure Function - AI + Tweets
//Add reference of BitlyAPI package
public static async Task<string> CreateShortURL(string url)
{
var bitly = new BitlyAPI.Bitly(BitlyKey);
var shortLink = await bitly.PostShortenLink(url);
return shortLink;
}
@anuraj
anuraj / zoomqna.cs
Created June 5, 2020 10:33
QnA Maker Zoom Integration code.
var kbServiceUrl = "https://appservice.azurewebsites.net/qnamaker/knowledgebases/id/generateAnswer";
var kbAuthKey = "authkey";
var answer = string.Empty;
using (var httpClient = httpClientFactory.CreateClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("EndpointKey", kbAuthKey);
var question = new JObject();
question["question"] = cmd;
var questionContent = new StringContent(question.ToString(), Encoding.UTF8, "application/json");