Skip to content

Instantly share code, notes, and snippets.

View rhythnic's full-sized avatar

Nick Baroni rhythnic

View GitHub Profile
@rhythnic
rhythnic / vuex-reusable-functions.js
Last active October 21, 2022 07:41
Reusable Vuex Functions
// *******************************************************************
// ATTENTION
// This gist is now an npm module
// The API of some functions is altered slightly.
// All future work will happen in the repo.
//
// https://gitlab.com/rhythnic/vuex-intern
// *******************************************************************
// *******************************************************************
@rhythnic
rhythnic / vuelidate-messages.js
Last active June 4, 2020 08:52
Display Vuelidate Validation (Error) Messages
const isFn = x => typeof x === 'function'
const plural = (words, count) => {
words = words.split('|').map(x => x.trim())
return count > 1 ? words[2].replace('{n}', count) : words[count]
}
// Given a Vuelidate validations object, find the validator keys
export function extractValidatorKeys (validations, validators = []) {
const keys = Object.keys(validations)
@rhythnic
rhythnic / animated-text-factory.js
Created September 6, 2018 19:02
Factory for creating custom elements for text-animation.
// ***************************************
// AnimatedTextFactory
// Factory gives you a custom element that accepts a text property.
// Each character of the text is wrapped in an element and appended as a child.
// You can achieve cool effects by combining css animation with props
// set on the child nodes.
//
// Usage
// <template>
// <text-stagger-animation-delay text="The ants go marching one by one.">
@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
@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 / 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 / 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 / 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 / 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 / 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
// {