Skip to content

Instantly share code, notes, and snippets.

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

Anthony Johnston MrAntix

🏠
Working from home
View GitHub Profile
@MrAntix
MrAntix / Booking-Sequence.md
Last active December 9, 2023 17:11
Booking Sequence
sequenceDiagram
    participant Customer
    participant Database
    participant Book_Handler as Book Handler
    participant Room
    participant Booked_Handler as Booked Handler
    participant Email_Service as Email Service

    Customer->>Database: Search available rooms
export const PROMISE_SINGLETON_REJECTION_REASON = 'rejected by successor';
/**
* Creates a context where by only the last called promise is resolved
* Previous ones would be rejected
*
* @example
*
* const context = createPromiseSingletonContext<string>();
* const someApiCall = (result: string) => new Promise<string>(resolve => {

Keybase proof

I hereby claim:

  • I am mrantix on github.
  • I am mrantix (https://keybase.io/mrantix) on keybase.
  • I have a public key ASBQIl4hmgX25PyYRe25edFEzqNmJOEuBwgnLDrXnvggago

To claim this, I am signing this object:

@MrAntix
MrAntix / Changes.cs
Created March 7, 2018 14:09
Apply changes to a list with a serializable list of add/updates and removes
public class Changes<T>
{
public Changes(
IEnumerable<T> toAddOrUpdate = null,
IEnumerable<T> toRemove = null)
{
ToAddOrUpdate = toAddOrUpdate?.ToImmutableArray() ?? ImmutableArray<T>.Empty;
ToRemove = toRemove?.ToImmutableArray() ?? ImmutableArray<T>.Empty;
}
@MrAntix
MrAntix / entities.ts
Created February 9, 2018 16:16
Some base classes for immutable entities in type script
export module Guid {
export function newGuid(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g,
c => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
@MrAntix
MrAntix / ObservableExtensions.cs
Last active January 19, 2018 23:34
Route events based on type on the same observable
public static class ObservableExtensions
{
public static Builder<TBase> SwitchType<TBase>(
this IObservable<TBase> observable)
{
return new Builder<TBase>(observable);
}
public class Builder<TBase>
{
@MrAntix
MrAntix / UpdateVersionAndPack.cs
Last active December 22, 2017 12:52
DotNetCore - Update project files with passed version and pack
internal class Program
{
static readonly Regex VersionRE = new Regex(@"(\d+\.\d+\.\d+)(\-.*(\-\d+))?");
static void Main(string[] args)
{
var app = new CommandLineApplication();
var pack = app.Command("pack", config =>
{
var versionArg = config.Argument("version", "Semamtic Version to pack e.g. (1.0.0-beta-1)", false);
@MrAntix
MrAntix / scroll.service.ts
Last active December 15, 2017 09:52
smooth scroll to in angular
import { Injectable, NgZone } from '@angular/core';
@Injectable()
export class ScrollService {
constructor(
private ngZone: NgZone) {
}
scrollTo(selector: string, focus?: boolean): void {
@MrAntix
MrAntix / DI Config for a DbContext Factory
Created November 28, 2017 11:48
EF: Allows usual transactions for scope injected instances and a factory method to create contexts which are disposed of by the caller
services.AddDbContext<MyDataContext>(
o => o.UseSqlServer(settings.ConnectionString),
ServiceLifetime.Scoped,
ServiceLifetime.Singleton);
services.TryAddSingleton<Func<MyDataContext>>(sp =>
() => new MyDataContext(sp.GetService<DbContextOptions<MyDataContext>>())
);
@MrAntix
MrAntix / FindImplementationsInSameAssemblyAs.cs
Created May 28, 2017 23:41
Find Implementations In Same Assembly even generics
public static class ReflectionExtensions
{
public static void FindImplementationsInSameAssemblyAs<T>(
this Type type,
Action<Type, Type> action)
{
var assembly = typeof(T).GetTypeInfo().Assembly;
var query =
from implementationType in assembly.GetTypes()