Skip to content

Instantly share code, notes, and snippets.

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

Moaid Hathot MoaidHathot

🏠
Working from home
View GitHub Profile
@MoaidHathot
MoaidHathot / IAsyncQueue<T>.cs
Last active March 7, 2022 09:42
David Fowler's challange to implement 'UberQueue<T>' //https://twitter.com/davidfowl/status/1426453915357175819
async Task Main()
{
var queues = new AsyncQueue<int>[]
{
new (100, TimeSpan.FromSeconds(1), Increment),
new (200, TimeSpan.FromSeconds(2), Increment),
new (300, TimeSpan.FromSeconds(3), Increment),
new (400, TimeSpan.FromSeconds(4), Increment),
};
@MoaidHathot
MoaidHathot / SignalRRbacClient.cs
Last active July 19, 2021 21:04
SignalR Aad Managed Identity Auth issue
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace SignalRConsoleClient
{
public static class Program
{
public static async Task Main(string[] args)
@MoaidHathot
MoaidHathot / SwitchToWindow
Last active July 24, 2020 16:51
Script for bringing windows to the front
void Main(string[] args)
{
var mainTitle = args?.FirstOrDefault();
var secondaryTitle = args?.Skip(1).FirstOrDefault();
var processName = args?.Skip(2).FirstOrDefault();
//Example
//(mainTitle, secondaryTitle, processName) = ("TechCrunch", "Startup", "chrome");
@MoaidHathot
MoaidHathot / Program.cs
Last active August 1, 2019 17:30
Classes for the blog post about Debugger attributes
[assembly: DebuggerTypeProxy(typeof(ScientistTypeProxy), Target = typeof(Scientist))]
[assembly: DebuggerDisplay("Name: {Name}, Birthday: {Birthday}", Target = typeof(Scientist))]
[assembly: DebuggerVisualizer(typeof(ScientistVisualizer), Target = typeof(Scientist))]
class Program
{
static void Main(string[] args)
{
var scientists = new[]
@MoaidHathot
MoaidHathot / OrientationStackPanel.cs
Last active August 24, 2017 09:55
OrientationStackPanel
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace WPFLayoutTests
@MoaidHathot
MoaidHathot / TypesForTesting.cs
Created February 8, 2017 09:01
Types for testing the KnownTypes.Fody extention. Blog Post version.
using KnownTypes.Fody;
namespace AssemblyToProcess
{
[KnowsDeriveTypes]
public class A
{
}
public class B : A
@MoaidHathot
MoaidHathot / WeaverTests.cs
Created February 8, 2017 08:37
KnownType.Fody Unit Tests for Blog Post
using System;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using KnownTypes.Fody;
using Mono.Cecil;
using NUnit.Framework;
[TestFixture]
public class WeaverTests
//For testing purposes...throws exception once per <ThrowExceptionForCount>
public class ExceptionThrowerAppender : ConsoleAppender
{
public int ThrowExceptionForCount { get; set; } = 1;
private int _count;
public ExceptionThrowerAppender()
{
ErrorHandler = new PropogateErrorHandler();
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<log4net>
@MoaidHathot
MoaidHathot / Bit.cs
Created September 18, 2016 21:09
Type-Safe Enum Pattern applied for representing a bit in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OzCodeLinqTests
{
public sealed class Bit : IEquatable<Bit>, IComparable, IComparable<Bit>
{