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 / 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);
}
@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 / 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
}
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 / 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 / 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]);;
})
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';