Skip to content

Instantly share code, notes, and snippets.

View pglazkov's full-sized avatar

Pavlo Glazkov pglazkov

View GitHub Profile
@pglazkov
pglazkov / firestore-collection-count-cloud-function.js
Created March 25, 2018 18:32
Firestore cloud function that maintains a document field that contains number of items in a collection
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const db = admin.firestore();
exports.updateMyCollectionCount = functions.firestore
.document(`users/{userId}/my-collection/{itemId}`)
.onWrite(event => {
const isUpdate = event.data.exists && event.data.previous.exists;
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { SharedData } from '../shared-data';
@Component({
selector: 'app-main',
template: `
<button (click)="loadData()">Load data</button>
<div *ngIf="sharedData.value | async; let data">
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AsyncSubject } from 'rxjs/AsyncSubject';
export interface DataValue {
items: string[];
}
@Injectable()
export class SharedData {
import { Component } from '@angular/core';
import { SharedData } from '../shared-data';
@Component({
selector: 'app-sidebar',
template: `
Item count: <span>{{ getItemCount() | async }}</span>
`
})
export class SidebarComponent {
import {
ApplicationRef, Componenimport {
ApplicationRef, ComponentFactoryResolver, ComponentRef,
Injectable, Injector, Type, ViewContainerRef
} from '@angular/core';
import {
ComponentType,
Portal,
ComponentPortal,
import { Component } from '@angular/core';
import { ComponentFactoryService } from './component-factory.service';
import { DynamicComponent } from './dynamic.component';
@Component({
selector: 'app-home',
template: '<div #host></div>'
})
export class HomeComponent {
@ViewChild('host', {read: ViewContainerRef})
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component'
import { DynamicComponent } from './dynamic.component';
import { ComponentFactoryService } from './component-factory.service';
@NgModule({
declarations: [
AppComponent,
import {
ApplicationRef, ComponentFactoryResolver, ComponentRef,
EmbeddedViewRef, Injectable, Injector, Type, ViewContainerRef
} from '@angular/core';
@Injectable()
export class ComponentFactoryService {
constructor(
private cfr: ComponentFactoryResolver,
@pglazkov
pglazkov / webpack.config.js
Created October 17, 2017 12:50
Webpack.config.js for multiple applications
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const apps = [
{
name: 'app1',
baseUrl: '/app1'
},
{
name: 'app2',
@pglazkov
pglazkov / AsyncRetry.cs
Last active October 11, 2018 09:23
Asynchronous Retry Helper
public static class AsyncRetry
{
public static async Task DoAsync(Func<Task> action,
AsyncRetryPolicy policy = null,
CancellationToken? cancellationToken = null)
{
await DoAsync(async () =>
{
await action();
return true;