Skip to content

Instantly share code, notes, and snippets.

Avatar
🐙
Hail Hydra!

Nishan Chathuranga Wickramarathna nishanc

🐙
Hail Hydra!
View GitHub Profile
View settings.json
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command": "paste",
"keys": "ctrl+v"
},
{
View Microsoft.PowerShell_profile.ps1
oh-my-posh init pwsh --config "https://gist.github.com/nishanc/2a574ff608ac7c6164e31a2eaae7f483#file-nishan-posh-config-json" | Invoke-Expression
Import-Module -Name Terminal-Icons
Import-Module -Name PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
View nishan-posh-config.json
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#21c7c7",
"style": "plain",
"template": "\u256d\u2500",
View HomeController.cs
using Microsoft.Extensions.Caching.Distributed;
namespace RedisOnDotnet6Demo.Controllers
{
public class HomeController : Controller
{
private IDistributedCache _cache;
public HomeController(IDistributedCache cache)
{
View UserRepository.cs
public async Task<List<User>> GetUsersAsync()
{
List<User> output = new()
{
new() { FirstName = "William", LastName = "Jackson" },
new() { FirstName = "Maria", LastName = "Moody" },
new() { FirstName = "Sarah", LastName = "King" },
new() { FirstName = "Gregory", LastName = "Estrada" },
new() { FirstName = "Juan", LastName = "Russell" },
new() { FirstName = "James", LastName = "Bryant" },
View HomeController.cs
public async Task<IActionResult> Index()
{
List<User>? users;
string recordKey = $"Users_{DateTime.Now:yyyyMMdd_hhmm}";
users = await _cache.GetRecordAsync<List<User>>(recordKey); // Get data from cache
if (users is null) // Data not available in the Cache
{
users = await _userRepository.GetUsersAsync(); // Read data from database
View CacheHelper.cs
public static class CacheHelper
{
public static async Task SetRecordAsync<T>(this IDistributedCache cache,
string recordId,
T data,
TimeSpan? absoluteExpireTime = null,
TimeSpan? slidingExpireTime = null)
{
var options = new DistributedCacheEntryOptions();
View appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Redis": "localhost:5002"
View Program.cs
builder.Services.AddStackExchangeRedisCache(options => {
options.Configuration = builder.Configuration.GetConnectionString("Redis");
options.InstanceName = "RedisDemo_";
});
View UnnecessaryJoinsBenchmark.cs
[MemoryDiagnoser]
public class UnnecessaryJoinsBenchmark : Benchmark
{
[Benchmark]
public async Task<List<CustomView>> WithJoins()
{
var books = await (from authors in Context.Authors
where authors.Id > 5
join book in Context.Books on authors.Id equals book.AuthorId select book)