Skip to content

Instantly share code, notes, and snippets.

View rhythnic's full-sized avatar

Nick Baroni rhythnic

View GitHub Profile
@rhythnic
rhythnic / us-states.json
Last active August 11, 2021 06:31
Name, abbreviation, and numeric code for all 50 US states and some territories.
[
{
"id": "01",
"name": "Alabama",
"abbr": "AL"
},
{
"id": "02",
"name": "Alaska",
"abbr": "AK"
// ***********************************************************************
// Validator Lib
// ***********************************************************************
const { Success, Failure } = require('folktale/validation')
const fieldPath = (...args) => args.join('.')
const optional = args => ([
(path, prop) => {
let assertions = args.map(x => x(path, prop))
@rhythnic
rhythnic / request-response-over-pubsub.js
Last active October 12, 2019 12:16
Request/Response on top of pubsub
// *****************************************************************
// Extend pubsub with request-response pattern
// Pubsub instance should conform to this interface:
// https://github.com/apollographql/graphql-subscriptions/blob/master/src/pubsub-engine.ts
// *****************************************************************
// *****************************************************************
// API
// request(topic, args)
// respond(topic, ({ args, pass, request }) => {})
@rhythnic
rhythnic / rc-server.js
Created May 30, 2019 18:45
Remote Control Server - Send and listen for HTTP requests via HTTP.
const express = require('express')
const R = require('ramda')
const uuid = require('uuid')
const request = require('request')
// *******************************************************
// Models
// *******************************************************
// RequestSummary
// {
@rhythnic
rhythnic / serve-spa.js
Created May 20, 2019 17:25
Singe Page App Express Utility
// Serve a single page application (web-client)
const path = require('path')
const Express = require('express')
module.exports = function serveSpa ({ app, omit, public }) {
if (!omit) omit = () => false
app
.use(Express.static(public))
.get('*', (req, res, next) => {
if (req.accepts('html') && !omit(req)) {
@rhythnic
rhythnic / selenium-fp.js
Last active December 17, 2018 21:52
Helpers for composing Selenium tests into functional pipelines.
// Usage with Jest
//
// const loginForm = [
// {
// selector: '#login_username',
// property: 'username'
// },
// {
// selector: '#login_password',
// property: 'password'
@rhythnic
rhythnic / S3Directory.js
Last active September 28, 2018 20:28
Implementation of Directory class for s3
const { Directory } = require('./Directory')
const AWS = require('aws-sdk')
const { PassThrough } = require('stream')
const s3 = new AWS.S3({ apiVersion: '2006-03-01' })
module.exports = class S3Directory extends Directory {
constructor (opts) {
super(opts)
this.Bucket = opts.Bucket
@rhythnic
rhythnic / Directory.js
Last active September 28, 2018 20:29
Classes for keeping directories in sync.
const { join } = require('path')
const fs = require('fs')
const pump = require('pump')
class Directory {
constructor ({ dir = '' }) {
this.dir = dir
this.init()
}
init () {}
@rhythnic
rhythnic / selenium-helpers.js
Last active September 21, 2018 20:30
Helper functions for selenium-webdriver in Node.
const { Builder, until } = require('selenium-webdriver')
async function setupSeleniumDriver (config) {
let driver = await new Builder().forBrowser(config.BROWSER)
if (config.HUB_HOST) {
driver = driver.usingServer(`http://${config.HUB_HOST}:${config.HUB_PORT}/wd/hub`)
}
driver = driver.build()
await driver.manage().window().setPosition(0, 0)
await driver.manage().window().setSize(1280, 1024)
@rhythnic
rhythnic / fetcher.js
Last active October 12, 2019 12:12
Small wrapper around window.fetch
// Small wrapper to enhance the fetch API and handle errors
// Requires Promise, fetch, and Object.assign polyfills
function checkFetchResponse (response) {
if (response.ok) return response
return response.text().then(function (text) {
const error = new Error(text || response.statusText)
error.status = response.status
error.statusText = response.statusText
throw error