Skip to content

Instantly share code, notes, and snippets.

View deebloo's full-sized avatar
👋
Hello!

Danny Blue deebloo

👋
Hello!
View GitHub Profile
@deebloo
deebloo / ts-custom-elements.ts
Last active November 4, 2016 12:19
Typescript declarations and decorators for custom elements
export interface CustomElementConfig {
tagName: string;
options?: {
extends: string;
};
}
/**
* @CustomElement({
* tagName: 'my-element'
@deebloo
deebloo / spa-server.js
Created June 7, 2016 12:27
A small sample server for SPA apps with compression.
var fallback = require('express-history-api-fallback');
var express = require('express');
var compress = require('compression');
var app = express();
var root = __dirname + '/dist';
app.use(compress());
app.use(express.static(root));
app.use(fallback('index.html', { root: root }));
var myWorker = $worker().create(function () {
self.postMessage('Hello World');
});
myWorker.run().then(function (e) {
console.log(e.data); // 'Hello World'
});
@deebloo
deebloo / sertice.ts
Last active April 27, 2017 07:05
Angular2 Service Pattern for configurability and reusability
// Standard Service Class
export class MyService {
constructor(private config) { }
}
// factory for creating new instances of the service
function createMyService(config = {}) {
return new MyService(config);
}
@deebloo
deebloo / web-component-class-example.js
Last active December 28, 2017 05:29
Its extremely easy to create vanilla custom elements with classes and template strings.
'use strict';
class NameCard extends HTMLElement {
set name(val) {
this._name = val;
this.render();
}
get name() {
return this._name;
@deebloo
deebloo / inline-worker-example.js
Last active January 19, 2018 13:15
Small function for inline workers
function createWorker(fn) {
var blob = new Blob(['self.onmessage = ', fn.toString()], { type: 'text/javascript' });
var url = URL.createObjectURL(blob);
return new Worker(url);
}
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<div class="map-container" #mapContainer><div>
`,
styles: [`
.map-container {
height: 300px;
@deebloo
deebloo / app.component.spec.ts
Last active February 10, 2018 18:36
Angular2 Webpack basic setup with UNIT TESTS!
// src/app.components.ts
import {AppComponent} from './app.component';
import {Injector} from '@angular/core';
import {expect, it, describe, beforeEach, beforeEachProviders, inject} from '@angular/core/testing';
describe('Component: AppComponent should be created', function () {
let fooComponent: FooComponent;
beforeEachProviders(() => [
import { BehaviorSubject, of } from 'rxjs';
import { distinctUntilChanged, concatMap, map, take } from 'rxjs/operators';
export class StateDef<T> extends BehaviorSubject<T> {
setState(setter: (state: T) => T) {
this.pipe(take(1)).subscribe(state => {
super.next(setter(state));
});
}
@deebloo
deebloo / test-http.service.spec.ts
Last active December 3, 2018 09:01
How to mock http requests with angular2's http module
// import core testing libs
import {
beforeEach,
addProviders,
it,
describe,
expect,
inject
} from '@angular/core/testing';