Skip to content

Instantly share code, notes, and snippets.

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

Alok Sharma aloksharma1

🏠
Working from home
View GitHub Profile
@veyselerCS
veyselerCS / ReflectionComparisonTest
Last active August 1, 2023 09:13
Performance test script for setting a field with various ways c#
using System;
using System.Reflection;
using System.Reflection.Emit;
using NUnit.Framework;
using Unity.PerformanceTesting;
public class ReflectionComparisonTest
{
//Test environment
private int _warmupCount = 5;
@duongphuhiep
duongphuhiep / MediatR vs MassTransit Mediator - Part 2 - Simplify MassTransit Consumers.md
Last active March 13, 2025 20:18
MediatR vs MassTransit Mediator - Part 2 - Simplify MassTransit Consumers

Read Part 1: MediatR vs MassTransit Mediator - Differences

The MassTransit Mediator implementation is more powerful than MediatR implementation, but also more complicate to use. Unit Testing a MassTransit Consumer is not a nice experience.

In this article I will propose some techniques to simplify the MassTransit Consumer and to make them look as straight forward as a MediatR handler.

Case study

We will study a very common use case (the most common use case which I can think of):

@duongphuhiep
duongphuhiep / MediatR vs MassTransit Mediator - Part 1 - Differences.md
Last active March 13, 2025 20:18
MediatR vs MassTransit Mediator / Part 1 / Differences

Why mediator?

In a ASP.NET Web application. You don't need mediator

  • If you prefers to make controlers depends directly to the Application Codes instead of indirectly via the Mediator.
  • If you prefers to make a normal ASP.NET Web Application instead of a Mediator Application

Frankly it is not a Bad choice, no need to use a Mediator framework or make a Mediator Application just because everyone did.. Though, There are benefits in making a Mediator Application:

  • Event sourcing (Messages broadcast), CQS pattern..
  • Decouple the Controler (presentation) from Application codes, so that you could swap the presentation technology. For eg, if you make a "MassTransit" application, then you can swap the presentation layer to Mediator or RabbitMQ, or Grpc.. => you are not to be sticked with or limited by ASP.NET presentation => but rather sticked with and limited by your mediator framework!
@patharanordev
patharanordev / convert-pt-to-onnx.md
Created March 6, 2021 04:27
How-to-convert `.pt` to `.onnx` model file format.

Convert .pt to .onnx

The function using in Scaled-YOLOv4, please refer to Scaled-YOLOv4 repository.

Before start, the export script requires onnxsim, you need to install it first :

$ pip install -q onnx-simplifier

Web Api

Download Resume

make download resumable using c#

Resuming files is done by specifying the byte range of the file you would like to download using the Range HTTP header. This can be done in .NET with the HttpWebRequest.AddRange function.

For example:

@hallidev
hallidev / gist:300c50fa1bab3a44c3ee2fcb45c6eb1e
Created December 5, 2019 15:47
Emit MediatR Events to EventGrid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MyApp.AppServices.Configuration;
using MyApp.AppServices.EventBus.Command;
using MyApp.AppServices.Model.EventGrid;
using Framework.EventBus.Command;
using Framework.Model;
@eneko
eneko / list-of-curl-options.txt
Last active April 19, 2025 09:46
List of `curl` options
$ curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--alt-svc <file name> Enable alt-svc with this cache file
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <file> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
@ReubenBond
ReubenBond / ILFieldBuilder.cs
Created October 12, 2016 01:58
Generating static fields on the fly in C# (for use in other codegen)
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Reflection.Emit;
internal class ILFieldBuilder
{
private static readonly AssemblyBuilder AssemblyBuilder =
AssemblyBuilder.DefineDynamicAssembly(
new AssemblyName(nameof(ILFieldBuilder)),
@auremoser
auremoser / graph.md
Last active December 27, 2018 17:16
Parsons: Webgraphs
@martijn00
martijn00 / RecyclerViewActivity.cs
Last active March 18, 2024 22:13
Load more / endless scroll for Xamarin RecyclerView
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = base.OnCreateView(inflater, container, savedInstanceState);
var recyclerView = view.FindViewById<RecyclerView>(Resource.Id.my_recycler_view);
if (recyclerView != null)
{
recyclerView.HasFixedSize = true;
var layoutManager = new LinearLayoutManager(Activity);