Skip to content

Instantly share code, notes, and snippets.

Avatar
😜

Eric Wooley ericwooley

😜
View GitHub Profile
View gist:a0e8fe9dcd2e4f8fdecf
Verifying that +ericwooley is my blockchain ID. https://onename.com/ericwooley
@ericwooley
ericwooley / webworker.js
Created Oct 11, 2016
Web worker from local function
View webworker.js
function testFunction () {
console.log('webworker success')
}
var worker = new Worker(URL.createObjectURL(new Blob(['(' + testFunction.toString() + ')()'], {type: 'application/javascript'})))
@ericwooley
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 www.google.com', {silent: true, async: true})
@ericwooley
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
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",
@ericwooley
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,
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.increments('id').unsigned().primary()
t.string('name').notNull()
t.text('description').nullable()
t.decimal('price', 6, 2).notNull()
})
@ericwooley
ericwooley / api.integration.js
Last active Aug 20, 2017
jest test for integration
View api.integration.js
// 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 / 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
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
}