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 / 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 / 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 / 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'
});
var myWorker = createWorker(function (e) {
self.postMessage(e.data.toUpperCase());
});
myWorker.onMessage = function (e) {
console.log(e.data); // HELLO FROM AN INLINE WORKER!
}
myWorker.postMessage('hello from an inline worker!')
// New workers is created for a link to an external js file
var myWorker = new Worker('web-worker.js');
// function to fire when a message is sent from the worker.
myWorker.onmessage = function (e) {
console.log(e.data); // HELLO WORLD
}
// send a message to the worker
myWorker.postMessage('hello world');
@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);
}
@deebloo
deebloo / worker.js
Created May 29, 2016 21:53
utility function for working with inline web workers
function $worker() {
var workers = [];
// PUBLIC_API
return {
create: create,
runAll: runAll,
terminateAll: terminateAll,
list: list
}
@deebloo
deebloo / angular-cli-build.js
Created May 29, 2016 21:35
angular-cli-build if you want more control over your files
/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
const vendorNpmFiles = [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
@deebloo
deebloo / moment.pipe.ts
Created May 13, 2016 17:55
Easily create a better Angular2 data pipe with Momentjs
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'moment'
})
export class MomentPipe implements PipeTransform {
transform(date, format) {
return moment(date).format(format);
}