Skip to content

Instantly share code, notes, and snippets.

View ericwooley's full-sized avatar
😜

Eric Wooley ericwooley

😜
View GitHub Profile
@ericwooley
ericwooley / List.ts
Last active April 2, 2021 17:17
List entity, part 1
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class List {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
@ericwooley
ericwooley / Todoitem.ts
Created April 2, 2021 16:51
TodoItem.ts part 1
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class TodoItem {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@ericwooley
ericwooley / extract.ts
Last active March 19, 2021 00:52
Extract explanation
// 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
ericwooley / eventEmitterPattern.tsx
Last active March 19, 2021 07:25
How to make eventemitter3 typesafe
import EventEMitter3 from 'eventemitter3'
interface EmitterEvent<Type extends string> extends Object {
type: Type;
}
interface AEvent extends EmitterEvent<'a'>{
aOnly: true
}
@ericwooley
ericwooley / integrationTest.js
Last active August 20, 2017 20:52
Integration test script
/***************************
* 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
ericwooley / api.integration.js
Last active August 20, 2017 21:18
jest test for integration
// see https://github.com/request/request-promise
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
ericwooley / package.json.js
Last active August 20, 2017 20:33
scripts for api snapshotting
// 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",
@ericwooley
ericwooley / 20170819134815_products.js
Last active August 20, 2017 21:17
snapshot migrations
// migrations/20170819134815_products.js
// Initial migration which adds the products table
exports.up = function (knex, Promise) {
return knex.schema.createTable('products', function (t) {
t.increments('id').unsigned().primary()
t.string('name').notNull()
t.text('description').nullable()
t.decimal('price', 6, 2).notNull()
})
@ericwooley
ericwooley / package.json
Created August 19, 2017 20:42
NPM docker example
{
"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
ericwooley / dev.js
Created July 7, 2017 18:00
Medium: Make output readable again. Controlling your IO streams in node. - 1
// silent because by default shelljs copies output to your main
// terminal output. async because shelljs blocks by default.
const {stdout, stderr} = shelljs.exec('ping www.google.com', {silent: true, async: true})