Skip to content

Instantly share code, notes, and snippets.

View hartraft's full-sized avatar
🍻

hartraft

🍻
  • Belgium
View GitHub Profile
@hartraft
hartraft / rollup.config.js
Created October 4, 2017 15:17
rollup.config.js with typescript and node module , angular templateUrl / styleUrl resolution & SASS processing. Line 23-28 resolves the templateUrl / styleUrl in angular components
// rollup.config.js with typescript and node module , angular templateUrl / styleUrl resolution & SASS processing
import angular from 'rollup-plugin-angular';
import typescript from 'rollup-plugin-typescript';
import nodeResolve from 'rollup-plugin-node-resolve';
import sass from 'node-sass';
export default {
entry: 'dist/index.js',
dest: 'dist/bundles/amazing.umd.js',
sourceMap: false,
@hartraft
hartraft / attribute.directive.ts
Last active November 3, 2017 10:38
Minimal Angular 4+ Attribute Directive binding to @input property based on Angular docs https://angular.io/guide/attribute-directives
import { Directive, ElementRef, Renderer2, Input, OnInit } from '@angular/core';
@Directive({ selector: '[attrDirective]' })
export class AttributeDirective {
@Input('statusField') statusField: string;
constructor(private el: ElementRef, private renderer: Renderer2) { // use Renderer2 as Renderer is deprecated
this.renderer.addClass(el.nativeElement, 'label'); // add Bootstrap label classes. need to access the nativeElement
}
@hartraft
hartraft / componentundertest.component.spec.ts
Last active November 8, 2017 09:38
TS Spec template to cover standard testing cases. Uncomment sections that are needed. Can be inserted into WebStorm / IntelliJ as a file template
import {DebugElement} from '@angular/core';
import {async, ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
// import {RouterTestingModule} from '@angular/router/testing';
describe('ComponentUnderTest ', () => {
let comp: ComponentUnderTest;
let fixture: ComponentFixture<ComponentUnderTest>;
let de: DebugElement;
@hartraft
hartraft / test-route.component.ts
Created November 28, 2017 16:06
Angular 2+ subscribing to query and route params. From https://github.com/angular/angular/issues/13804 there is no need to unsubscribe the observables. https://angular.io/docs/ts/latest/guide/router.html#!#reuse
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import 'rxjs/add/observable/combineLatest';
import { Observable } from 'rxjs/Observable';
@Component( {
selector: 'test-route',
templateUrl: './test-route.component.html'
} )
@hartraft
hartraft / es6-alphabet-array.js
Created December 15, 2017 12:46
Short gist to retrieve the letters a...z of the alphabet
console.log( 'lowercase alphabet %s', String.fromCharCode( ...Array( 123 ).keys() ).slice( 97 ) );
console.log( 'uppercase alphabet %s',String.fromCharCode( ...Array( 91 ).keys() ).slice( 65 ) );
0xe84ca4c2bb68ecd98c16ffa3e109c6f227107729
0x1adaacf544619445388d99614a1a7cffd892cc7f
// from() – determine the result’s constructor via the receiver
// (in this case, MyArray)
let instanceOfMyArray = MyArray.from([1, 2, 3], x => x * x);
// map(): the result is always an instance of Array
let instanceOfArray = [1, 2, 3].map(x => x * x);
@hartraft
hartraft / settings.json
Created December 26, 2017 10:11
VS Code user settings
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.js.map": true,
"**/*.js": { "when": "$(basename).ts"}
}
@hartraft
hartraft / align.css
Created February 8, 2018 10:46
css to align word wrap correctly
ul li {
/*
* We want the bullets outside of the list,
* so the text is aligned. Now the actual bullet
* is outside of the list’s container
*/
list-style-position: outside;
/*
* Because the bullet is outside of the list’s