Skip to content

Instantly share code, notes, and snippets.

View damithg's full-sized avatar

damithg

  • United Kingdom
View GitHub Profile
@damithg
damithg / group-objects-by-property.md
Created October 27, 2022 22:17 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@damithg
damithg / UserPointsQueryController.cs
Created October 19, 2020 18:04
Test class for interview
// Introduction
// First, take some time to read through the code.
// Feel free to make notes as you walk through it.
// Q So: in summary, what does it do?
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Mvc;
@damithg
damithg / debugger pause beforeunload
Last active January 17, 2020 13:05 — forked from carcinocron/debugger pause beforeunload
Chrome: pause before redirect
// Run this in the F12 javascript console in chrome
// if a redirect happens, the page will pause
// this helps because chrome's network tab's
// "preserve log" seems to technically preserve the log
// but you can't actually LOOK at it...
// also the "replay xhr" feature does not work after reload
// even if you "preserve log".
window.addEventListener("beforeunload", function() { debugger; }, false)
using System;
using System.IO;
using System.Security.Cryptography;
using FluentAssertions;
using Jose;
using JWT.Serializers;
using JwtTest.JwtToken;
using Newtonsoft.Json;
using NUnit.Framework;
using Org.BouncyCastle.Crypto;
@damithg
damithg / MediatRExtensions.cs
Created August 7, 2019 18:18 — forked from rmacfie/MediatRExtensions.cs
Register MediatR handlers in Asp.Net 5 / vNext / Core
namespace Microsoft.AspNet.Builder
{
public static class MediatRExtensions
{
public static IServiceCollection AddMediatR(this IServiceCollection services, params Assembly[] handlerAssemblies)
{
services.AddTransient<IMediator>(x => new Mediator(x.GetService<SingleInstanceFactory>(), x.GetService<MultiInstanceFactory>()));
services.AddTransient<SingleInstanceFactory>(x => t => x.GetRequiredService(t));
services.AddTransient<MultiInstanceFactory>(x => t => x.GetServices(t));
@damithg
damithg / 0_reuse_code.js
Created June 2, 2016 15:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console