Skip to content

Instantly share code, notes, and snippets.

View nirkaufman's full-sized avatar
🎯
Focusing

Nir Kaufman nirkaufman

🎯
Focusing
View GitHub Profile
const nums = [1,2,3,4,5];
// your own
const reduce = (arr, fn, initValue) => {
let result = initValue;
arr.forEach( item => result = fn(result, item) );
return result;
}
console.log(reduce(nums, (total, item) => total + item , 0))
import {Component} from '@angular/core';
import {FormControl} from "@angular/forms";
@Component({
selector: 'app-root',
template: `
<h1>Angular Playground</h1>
<input type="password"
[formControl]="inputControl"
nkStrongPassword
import {
AfterViewInit,
Component,
ComponentFactoryResolver,
ComponentRef,
Injector,
ViewChild,
ViewContainerRef,
ViewRef
} from '@angular/core';
function copyStyles(sourceDoc, targetDoc) {
Array.from(sourceDoc.styleSheets).forEach(styleSheet => {
if (styleSheet.cssRules) {
const newStyleEl = sourceDoc.createElement('style');
Array.from(styleSheet.cssRules).forEach(cssRule => {
newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText));
});
targetDoc.head.appendChild(newStyleEl);
import {AfterViewInit, Component, OnInit, TemplateRef, ViewChild, ViewContainerRef,} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div class="container">
<h1 class="display-1">Angular<span class="text-muted">MasterClass</span></h1>
<ng-container #container></ng-container>
<ng-container *ngIf="condition as value">{{ value }}</ng-container>
import {AfterViewInit, Component, OnInit, TemplateRef, ViewChild, ViewContainerRef,} from '@angular/core';
import {Card, CardTypes} from "./cards/card.types";
@Component({
selector: 'app-root',
template: `
<div class="container">
<h1 class="display-1">Angular<span class="text-muted">MasterClass</span></h1>
<!-- will render the built-in templates -->
import {AfterViewInit, Component, QueryList, ViewChildren} from '@angular/core';
import {NgComponentOutlet} from "@angular/common";
// Something to loop over
@Component({
template: `<p>Component Type A</p>`
})
class ComponentA {}
@Component({
import {BehaviorSubject, Observable} from "rxjs";
import {Inject, Injectable, InjectionToken} from "@angular/core";
export interface Action {
type: string;
}
export interface ActionHandler {
handleAction(currentState: any, action: Action): any;
}
const website = `nir.life`
const btn = document.createElement('button');
function map(transformFn) {
return function(inputValueProvider) {
return createObservable(
function (onValue, onError, onComplete) {
inputValueProvider.subscribe(
(value) => onValue(transformFn(value)),
let hooks = [];
let idx = 0;
export function useState(initialState) {
let state = hooks[idx] || initialState;
let _idx = idx;
function setState(newState) {
hooks[_idx] = newState;
render();