Skip to content

Instantly share code, notes, and snippets.

@gund
gund / CLA Agreement.md
Last active April 10, 2017 07:21
CLA Agreement

SAP Individual Contributor License Agreement

Thank you for your interest in contributing to open source software projects (“Projects”) made available by SAP SE or its affiliates (“SAP”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to SAP in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact opensource@sap.com.

You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.

Copyright License. You hereby grant, and agree to grant, to SAP a non-exclusive, perpetual, irrevocable, worldwi

@gund
gund / ng-router-resolver.ts
Created June 15, 2017 13:01
Angular Router Static Resolver (draft)
import { NgModule } from '@angular/core';
import * as ts from 'typescript';
const startTime = Date.now();
main()
.then(() => Date.now())
.then(endTime => console.log(`Done in ${endTime - startTime}ms`))
.catch(e => {
console.error(e);
@gund
gund / index.md
Last active June 20, 2017 08:58
Generate routes manifest for @angular/service-worker

This is small script that can help generating routes manifest for @angular/service-worker. It is alternative way for ng-pwa-tools to generate manifest without ever running angular application on the server.

It requires you to have installed ng-pwa-tools and ng-router-resolver libraries.

It is a drop-in replacement for command ngu-sw-manifest.

NOTE: --out argument should point to existing manifest json file.

routes.js:

@gund
gund / rollup.config.js
Last active June 21, 2017 17:48
Rollup Angular configuration
// Precompile angular module before server-side rendering
import typescript from 'rollup-plugin-typescript2';
import angular from 'rollup-plugin-angular';
import nodeResolve from 'rollup-plugin-node-resolve';
import alias from 'rollup-plugin-alias';
import { GLOBAL, globalsRegex } from 'rollup-globals-regex';
export default {
entry: 'src/app/app.module.ts',
dest: 'dist-ngu/app.module.js',
@gund
gund / readme.md
Last active July 28, 2017 12:14
Run angular application in custom zone

This shows how you can customize zone behavior in which Angular App will run.

Can be useful for example if you want to intercept all events that angular dispatches to your handlers.

First, create a custom-zone.ts file:

import 'zone.js';

interface TaskInfo {
  delegate: ZoneDelegate;
@gund
gund / advanced-renderer.md
Last active August 12, 2017 19:24
Example of abstract advanced renderer for Angular to execute arbitrary function on different safe thread (ex. webworker)

Advanced Renderer

The idea here is to have an abstraction to safely run browser dependent code in non browser-native environment (like webworker or server-side) without breaking the app and not changing any application logic code.

execute(expression: string, args?: ExpressionArguments): Promise

import { Injectable, NgModule, PLATFORM_INITIALIZER, Provider } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {
@gund
gund / readme.md
Last active July 4, 2018 18:27
Webpack 2 beta circular dependencies trouble

So consider we have Logger class. And also we have a LoggerInContext class which extends Logger. And Logger has factory method to create new LoggerInContext instances.

// logger.ts

import { LoggerInContext } from './logger-in-context';

export class Logger {
@gund
gund / readme.md
Created October 5, 2018 16:58
TS spread bug
// EXPECTED
new Set(...document.body.classList)
> {"l", "o", "g", "e", "d", …}

// ACTUAL
new (Set.bind.apply(Set, [void 0].concat(document.body.classList)))();
> {"logged-in", "env-production", "emoji-size-boost"}

// FIX
@gund
gund / setup-for-jest.ts
Last active January 7, 2019 22:29
Angular Testing Helpers for auto-generating host component
import { setOutputsMock } from './testing-helpers';
declare module './testing-helpers' {
interface MockedOutput extends jest.Mock {}
}
setOutputsMock(() => jest.fn());
@gund
gund / no-branching.ts
Created January 21, 2019 09:47
Example how you can convert data without branching
// function with branching
function giveAppleOrOrange(condition) {
if (condition) {
return 'apple';
} else {
return 'orange';
}
}
// function without branching