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 / 0.md
Last active April 3, 2020 13:41
message-parts

Text Chats as Data

Most of the time when we are thinking about sending a chat message as text we just think of sending a string. This work fine in most cases but causes issues when we think about formatting or when needing to define special actions like links. This is a proposal for a potential way of treating messages differently.

Let’s say that you wanted to send this block of text as a message.

“Hello World, this is the BEST! Follow me here.”

How would you interpret the bold text? We could break up the string into distinct tokens that represent a small part of the message.

@deebloo
deebloo / if-animation.directive.ts
Last active December 21, 2018 14:17
custom directive that creates and destroys elements with an enter and exit animation
import { Directive, TemplateRef, ViewContainerRef, Input, Renderer2 } from '@angular/core';
import { timer } from 'rxjs';
@Directive({
selector: '[ifAnimation]'
})
export class IfAnimationDirective {
@Input() lsIfAnimationDelay: number;
@Input() set lsIfAnimation(display: boolean) {
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));
});
}
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 / 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 / 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 / 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) =>{
import { createStore } from 'redux';
const add1 = () => {
type: 'ADD1',
payload: state => [{}, ...state]
}
const add2 = () => {
type: 'ADD2',
payload: state => add1().payload(add1().payload(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';
@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]);;
})