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 / 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 }));
@deebloo
deebloo / app-state.ts
Created June 11, 2016 17:10
Typescript and RXJS application state with history
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class AppStateService {
changes: Subject<any> = new Subject();
private state: any = {};
private history: any[] = [];
private historyPos: number = 0;
@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 / rxjs-worker-map.example.js
Last active August 19, 2016 17:24
A RxJs operator that runs in a new thread. https://github.com/deebloo/rxjs-worker
// https://github.com/deebloo/rxjs-worker
var observable = Observable.of([0, 1, 2, 3, 4]);
observable
.map(function (data) {
return data.concat([5, 6, 7, 8, 9]);
})
.workerMap(function (data) {
return data.concat([10,11,12,13,14]);;
})
@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';
import { createStore } from 'redux';
const add1 = () => {
type: 'ADD1',
payload: state => [{}, ...state]
}
const add2 = () => {
type: 'ADD2',
payload: state => add1().payload(add1().payload(state))
@deebloo
deebloo / compose.ts
Last active September 16, 2016 21:41
Compose function/decorator
// Our compose function that can be used as a decorator
// Decorators are just functions
const Compose = (mixins: any[]) => {
const protos = mixins.map(mixin => mixin.prototype)
const targetFunc = target => {
Object.assign(target.prototype, ...protos)
}
targetFunc.create = (base: any) =>{
@deebloo
deebloo / 0-sweet-modals.component.ts
Last active October 8, 2016 15:53
Simple Modals with Angular2
import { Component, Input } from '@angular/core';
@Component({
selector: 'sweet-modal',
styleUrls: ['sweet-modal.component.css']
templateUrl: 'sweet-modal.component.html'
})
export class LsModalComponent {
@Input() width: string = '400px';
@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'
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<div class="map-container" #mapContainer><div>
`,
styles: [`
.map-container {
height: 300px;