Skip to content

Instantly share code, notes, and snippets.

View maxime1992's full-sized avatar

Maxime maxime1992

View GitHub Profile
import { EntityAdapter, EntityState } from '@ngrx/entity';
import { ActionReducer } from '@ngrx/store';
import { CommandReducer, ReducerCommand } from 'ngrx-command-reducer';
import { BaseAction, StaticAction } from './base.actions';
type PayloadActionFunction<S, P> = (p: P, s: S) => S;
type PayloadlessActionFunction<S> = (s: S) => S;
export type EntityFunction<S, P> = PayloadActionFunction<S, P> | PayloadlessActionFunction<S>;
export class EntityCommandReducer<Entity, State extends EntityState<Entity>, Action extends BaseAction> {
@Injectable()
export class NgrxStoreService {
ondestroy$: Observable<void> = new Subject<void>();
constructor(protected store: Store<State>, protected changeDetector: ChangeDetectorRef) { }
select<R>(mapFunc: (state: State) => R): Observable<R> {
return this.store.select(mapFunc).pipe(
takeUntil(this.ondestroy$),
@matheus-santos
matheus-santos / cheat_sheet_socketio
Last active May 1, 2019 19:23
SocketIO cheat sheet to emit messages through sockets
// SocketIO cheat sheet
// SocketIO is a library that makes websockets communications easier.
// Page: http://socket.io/
// ref: http://stackoverflow.com/a/10099325
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
#!/bin/bash
# Error handling
function OwnError()
{
echo -e "[ `date` ] $(tput setaf 1)$@$(tput sgr0)"
exit $2
}
# Repository for rethinkdb
@michaelbromley
michaelbromley / create-mock.ts
Last active December 6, 2019 11:36
Automatic component mocking in Angular
import {Component, EventEmitter, Type} from '@angular/core';
type MetadataName = 'Input' | 'Output';
interface PropDecoratorFactory {
ngMetadataName: MetadataName;
bindingPropertyName: string | undefined;
}
interface PropMetadata { [key: string]: PropDecoratorFactory[]; }
@messified
messified / vscode_reduce_cpu_usage.md
Created October 30, 2019 18:15
VSCode Reduce CPU Usage

VSCode Reduce CPU Usage

Update your settings.json with the code below, then restart vscode:

{
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
 "**/.hg": true,

@ngrx/store v3

Problems:

  • Users want to compose reducer tree across modules
  • Idea of a single reducer function makes it difficult for the library to dynamically augment the shape of the state tree
  • Turning control over to the library to build the root reducer limits the use of meta-reducers
  • Feature modules may inadvertently collide with the state of the root module
  • Library authors may want to leverage @ngrx/store in their projects and provide an easy way
@ruandre
ruandre / AiFitToArtboard.jsx
Last active July 19, 2022 12:16
Adobe Illustrator script to resize objects proportionally to fit inside the artboard.
/***************************
NOT MAINTAINED! from ~2014
****************************/
// cs4+ script for resizing objects proportionally to fit inside artboard
// based on: https://forums.adobe.com/message/4164590
// usage: create a new document with desired artboard size, paste object, select it, run this script
// bugs: centering does not work after changing artboard size
var activeDoc = app.activeDocument

[Know about it][Understanding][Clear understanding]

NOVICE

CONCEPTS

  • xxx Immutable Data
  • xxx Second-Order Functions
  • xxx Constructing & Destructuring
  • xxx Function Composition
  • xxx First-Class Functions & Lambdas
@connor
connor / .jshintrc.js
Created January 11, 2012 22:20
jshintrc example
// NOTE: I added the .js extension to this gist so it would have syntax highlighting. This file should have NO file extension
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.