Skip to content

Instantly share code, notes, and snippets.

@born2net
born2net / ngrx8_with_immer.ts
Created July 10, 2019 14:55
ngrx 8+ with immer and support for on() within reducer
import {createReducer} from '@ngrx/store';
import {on} from "@ngrx/store";
import produce, {Draft} from "immer";
export const initialUserState: IUserState = {
knownUsers: [user1, user2],
selectedUser: null,
scenes: null
};
@lllyin
lllyin / mini-store.ts
Last active September 10, 2020 16:02
mini-store
import { parseJSON } from 'utils/tools/parseJSON';
import { IOPtions, ISubscribe } from './Types';
/**
* mini store
* 微型数据管理的仓库库
*
* 必要的说明:
* - 1. 订阅 subscribe: 只有先订阅后,set或update才能触发订阅函数,未订阅前的set和update是不会触发订阅函数的。
*
@mario-subo
mario-subo / localStorage.ts
Last active July 5, 2022 16:26
simple JS local storage utility
export const setLocalStorage = (key: string, value: any) => {
if (typeof key !== "string") {
throw new Error(`Error in localStorage: key ${key} must be of type string but is ${typeof key}`);
}
const typeOfValue = typeof value;
console.log(`localStorage: about to save value of type ${typeOfValue} for key ${key}`);
let valueToStore;
switch (typeOfValue) {
case "string":
@ThomasBurleson
ThomasBurleson / git-flat-commit-history.md
Last active February 23, 2020 16:04
Git - Benefits of Flat Commit History

Flawed Commit Strategy

Developers often want to condense their git log output. However without a proper git commit strategy (and conventions), those condensed outputs are still flawed.

For details on condensed git log outputs, see Improve your Git Log Output

Consider a git lg output for a typical project:

image

@imbudhiraja
imbudhiraja / convert-keys-to-camel-case
Last active February 24, 2023 14:38
Converting Object Keys from Snake Case, Kebab Case to Camel Case with JavaScript
const mongoose = require('mongoose');
const toCamel = (string) => string.replace(/([-_][a-z])/gi, ($1) => $1
.toUpperCase()
.replace('-', '')
.replace('_', ''));
const isObject = (args) => args === Object(args) && !Array.isArray(args) && typeof args !== 'function';
const keysToCamel = (args) => {
@holmberd
holmberd / js-nestGroupsBy.md
Last active November 28, 2024 16:16
Dynamically create nested level groups by properties in Javascript

Dynamically create nested level groups by properties in Javascript

Code

/**
 * Creates nested groups by object properties.
 * `properties` array nest from highest(index = 0) to lowest level.
 *
 * @param {String[]} properties
 * @returns {Object}
@jdnichollsc
jdnichollsc / ABC.md
Last active December 7, 2024 17:45
The Job Interview Guide

The Job Interview Guide 💼

And English is a Work in Progress ⌛

@ThomasBurleson
ThomasBurleson / cars.facade.spec.ts
Last active February 23, 2025 02:51
Testing NgRx Facades with async/await.
import { NgModule } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { readFirst } from '@nrwl/nx/testing';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule, Store } from '@ngrx/store';
import { NxModule } from '@nrwl/nx';
/**
@w8r
w8r / event_emitter.js
Created July 18, 2018 13:54
Event emitter
var isArray = Array.isArray;
class EventTarget {
/**
* @param {string} name
* @param {function} cb
* @return {EventTarget}
*/
@yusufades
yusufades / svg-rounded-rect-path.js
Last active March 20, 2020 13:23
Generate svg path for rounded rectangle with constant radius. Working example/calculator available here https://jsfiddle.net/theya222/b5jLydqh/
/***
* Generates the svg path data for a rounded rectangle
* Rounded corners are approximated by Cubic bezier curve with control point at an end point and the other at the corner
* @license MIT License
* Copyright (c) 2018 Yusuf Ades
* @param {Object} dimension - Dimensions of rectangle.
* @param {number} width - Width.
* @param {number} height - Height.
* @param {number} [r=0] - Corner Radius. Keep this smaller than half of width or height.
* @param {number} [x=0] - Offset from top left corner in x axis. default 0.