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 / TryCatchExtensions2.cs
Last active July 27, 2024 17:29
Demonstrating a "TryCatch" Extension method over IEnumerable, this version with more ValueTuples
using Dumpify;
Enumerable.Range(0, 10)
.Where(i => i % 2 == 0)
.Select(i => i == 6 ? throw new Exception("Oops") : i)
.Select(i => i * 2)
.CatchExceptions(ex => ex.Dump())
.Dump();
public static class TryCatchExtensions
@MoaidHathot
MoaidHathot / TryCatchExtensions.cs
Last active July 27, 2024 00:19
Demonstrating a "TryCatch" Extension method over IEnumerable
using Dumpify;
Enumerable.Range(0, 10)
.Where(i => i % 2 == 0)
.Select(i => i == 6 ? throw new Exception("Oops") : i)
.Select(i => i * 2)
.CatchExceptions(ex => ex.Dump())
.Dump();
public static class TryCatchExtensions
@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();
}