Skip to content

Instantly share code, notes, and snippets.

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

NamelessGod NamelessG0d

🏠
Working from home
View GitHub Profile
@NamelessG0d
NamelessG0d / ConcurrentWaitableBag.cs
Created June 9, 2023 02:21
ConcurrentBag that uses ConcurrentDictionary wtih ManualResetEventSlim to allow to wait on removal of a specific item
public class ConcurrentWaitableBag<T> where T : notnull
{
private ConcurrentDictionary<T, ManualResetEventSlim> dict = new ConcurrentDictionary<T, ManualResetEventSlim>();
public bool TryAdd(T item)
{
var semaphore = new ManualResetEventSlim(false);
return dict.TryAdd(item, semaphore);
}
@NamelessG0d
NamelessG0d / AccessLevelAttribute.cs
Last active February 16, 2023 21:04
Custom Controller Attribute to execute code before execution (C# Asp.Net Mvc)
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Security.Claims;
namespace ASP.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class AccessLevelAttribute : ActionFilterAttribute
{
private readonly int _role_level;