Skip to content

Instantly share code, notes, and snippets.

View jschwarty's full-sized avatar

Justin Schwartzenberger jschwarty

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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();