Skip to content

Instantly share code, notes, and snippets.

View jschwarty's full-sized avatar

Justin Schwartzenberger jschwarty

View GitHub Profile
@jschwarty
jschwarty / conversion.pipe.spec.ts
Created July 28, 2016 16:51
Issues with testing parameter guard logic when using TypeScript
import { describe, it, expect, beforeEach } from '@angular/core/testing';
import { InvalidPipeArgumentException } from '@angular/common/src/pipes/invalid_pipe_argument_exception';
import { ConversionPipe } from './conversion.pipe';
describe('ConversionPipe', () => {
let pipe: ConversionPipe;
beforeEach(() => {
pipe = new ConversionPipe();
@jschwarty
jschwarty / index.ts
Last active October 17, 2017 10:48
GraphQL Express server with desire to mock data for schema
const graphqlHTTP = require('express-graphql');
const express = require('express');
import { schema } from './schema/schema';
// Can I use something from graphql-tools with my schema...
// import { <something-here> } from 'graphql-tools';
// ...and then feed it to my express() server below?
const port = 3000;
@jschwarty
jschwarty / docker-compose.yml
Created September 14, 2016 17:50
Docker compose for mongodb and seed containers
version: '2'
services:
mongodb:
image: mongo:3.2.6
ports:
- "27017:27017"
mongo-seed:
image: mongo:3.2.6
@jschwarty
jschwarty / queue.ts
Created November 9, 2016 01:17
A queue implemented in RxJS that will stream while subscribed and back up while no observers.
class Queue extends Subject<any> {
private items;
add(item) {
if(this.observers.length > 0) {
this.next(item);
} else {
this.items.push(item);
}
}
@jschwarty
jschwarty / destructuring.js
Last active January 4, 2017 22:31
JavaScript object destructuring in function signature
function justDoIt(color, { size, model }) {
console.log(`Laced up the size ${size} ${model} kicks (${color})`);
}
let shoe = {
size: 9.5,
model: 'Air Jordan Retro 4'
};
justDoIt('black', shoe);
@jschwarty
jschwarty / buildInitials.ts
Last active March 30, 2017 22:41
Function to create initials from a list of strings.
export function buildInitials(...fields: string[]) {
return fields.reduce((acc, val) => {
acc += val.length > 0 ? val[0] : '';
return acc.toUpperCase();
}, '');
}
@jschwarty
jschwarty / index.ts
Last active November 11, 2017 01:10
Blog Post (Nrwl) - nx modularize code 1
// Only exported types will be able to be imported elsewhere
export { BackendProviderModule } from './src/backend-provider.module';
export { BackendService } from './src/backend.service';
// leave out the private stuff, like that Helpers class
@jschwarty
jschwarty / imports.ts
Created November 11, 2017 01:12
Blog Post (Nrwl) - nx modularize 2
// Add this one to an AppModule imports
import { BackendProviderModule } from '@myproject/backend-provider';
// Use this one in the AppComponent for constructor injection
import { BackendService } from '@myproject/backend-provider';
@jschwarty
jschwarty / getFullTreeParams.ts
Created March 9, 2018 19:24
Recursive function for getting route params from the Angular router snapshot
import { ActivatedRoute } from '@angular/router';
export function getFullTreeParams(route: ActivatedRoute, params = {}) {
if (route) {
params = {...params, ...route.snapshot.params};
}
return route.parent
? this.getFullTreeParams(route.parent, params)
: params;
}
import { ActivatedRouteSnapshot } from '@angular/router';
export function getFullTreeParams(route: ActivatedRouteSnapshot, params = {}) {
if (route) {
params = {...params, ...route.params};
}
return route.firstChild
? this.getFullTreeParams(route.firstChild, params)
: params;
}