Skip to content

Instantly share code, notes, and snippets.


Eric Wooley ericwooley

View GitHub Profile
ericwooley / List.ts
Last active Apr 2, 2021
List entity, part 1
View List.ts
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
export class List {
id: number;
name: string;
ericwooley / Todoitem.ts
Created Apr 2, 2021
TodoItem.ts part 1
View Todoitem.ts
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
export class TodoItem {
id: number;
name: string;
ericwooley / extract.ts
Last active Mar 19, 2021
Extract explanation
View extract.ts
// states of h2o
type h2o = 'water'|'steam'|'ice'
// states of h2o that will pass through a filter
type filter = 'water'|'steam'
// Extract non solid forms of h2o
type nonSolidH2o = Extract<h2o, filter>
// these are fine, they are not solid
const water: nonSolidH2o = 'water'
ericwooley / eventEmitterPattern.tsx
Last active Mar 19, 2021
How to make eventemitter3 typesafe
View eventEmitterPattern.tsx
import EventEMitter3 from 'eventemitter3'
interface EmitterEvent<Type extends string> extends Object {
type: Type;
interface AEvent extends EmitterEvent<'a'>{
aOnly: true
ericwooley / integrationTest.js
Last active Aug 20, 2017
Integration test script
View integrationTest.js
* configuration
* the commands below should line up with your npm run scripts.
const initDbCommand = 'initIntegrationDB'
const startServerInIntegrationModeCommand = 'start:integration'
const apiPort = process.env.API_PORT || 3200
const jestCommand = 'jest:integration'
// After starting the server, it must console.log a string we can listen too,
ericwooley / api.integration.js
Last active Aug 20, 2017
jest test for integration
View api.integration.js
// see
const requestPromise = require('request-promise')
// in case you want to mess with where the integration test happens
const api = process.env.API_URL || 'http://localhost:3200'
* Test Setup Functions
* These functions make our actual tests much shorter and readable
ericwooley / package.json.js
Last active Aug 20, 2017
scripts for api snapshotting
View package.json.js
// package.json
// note that comments aren't typically allowed.
"scripts": {
// recreate the dev database
"initDB": "rm dev.sqlite3; knex migrate:latest; knex seed:run",
// recreate the integration database
"initIntegrationDB": "export DATABASE_FILE=integration.sqlite3; rm integration.sqlite3; knex migrate:latest; knex seed:run",
// start the service on port 3000
"start": "node index.js",
View 20170819134815_products.js
// migrations/20170819134815_products.js
// Initial migration which adds the products table
exports.up = function (knex, Promise) {
return knex.schema.createTable('products', function (t) {
t.decimal('price', 6, 2).notNull()
ericwooley / package.json
Created Aug 19, 2017
NPM docker example
View package.json
"name": "docker-db-example",
"scripts": {
"initDocker": "docker run --name snapshot-test-postgres -e POSTGRES_PASSWORD=developPassword -d postgres",
"destroyDocker": "docker stop snapshot-test-postgres; docker rm snapshot-test-postgres"
ericwooley / dev.js
Created Jul 7, 2017
Medium: Make output readable again. Controlling your IO streams in node. - 1
View dev.js
// silent because by default shelljs copies output to your main
// terminal output. async because shelljs blocks by default.
const {stdout, stderr} = shelljs.exec('ping', {silent: true, async: true})