Skip to content

Instantly share code, notes, and snippets.

View arnotes's full-sized avatar
😃

arnotes

😃
View GitHub Profile
@arnotes
arnotes / ComponentLabeling.cs
Created May 7, 2021 02:48
component labeling
using System;
using System.Collections.Generic;
using System.Linq;
namespace connected
{
class Program
{
static (int groupNum, char value) nullGroupVal = (-1, '*');
const tapWhenUnsubscribed = <T>(source$: Observable<T>) => (
fn: (x: T) => void
) =>
new Observable<T>(observer => {
let closedFromSource = false;
const subscription = source$.subscribe(
x => {
observer.next(x);
},
e => {
@arnotes
arnotes / deepMerge.ts
Last active February 8, 2021 23:04
deepMerge
function deepMerge(target, source){
const result = {...target,...source};
const keys = Object.keys(result);
for(const key of keys){
const tprop = target[key];
const sprop = source[key];
//if two objects are in conflict
if(typeof(tprop) == 'object' && typeof(sprop) == 'object'){
result[key] = deepMerge(tprop, sprop);
@arnotes
arnotes / forwardReducer.ts
Created May 25, 2020 00:44
becase createSlice doesnt support a 'default case'
import { Slice } from "@reduxjs/toolkit";
import { studentSlice } from "./studentSlice";
type childSelector<P,C> = (state:P) => C;
export const forwardReducer = <P,C>(childSlice:Slice<C>,childSelector:childSelector<P,C>) => {
const reducerDC = {} as any;//will fix types later
for (const key in childSlice.actions) {
if (childSlice.actions.hasOwnProperty(key)) {
const action = childSlice.actions[key];
reducerDC[action.type] = (state:P, action:any) => {