Skip to content

Instantly share code, notes, and snippets.


Marshall Thompson marshallswain

View GitHub Profile
marshallswain / mb.js
Last active Oct 14, 2018
mb object property accessor, formatted
View mb.js
const mb = (...p) => o => p.reduce((a, c) => Object(a)[c], o)
marshallswain / auth.js
Created May 17, 2018
Next.js Feathers auth trick
View auth.js
jwtAuth({ token }) {
if (!isClient) {
app().set('accessToken', token);
return this.verifyToken(token)
.then(payload => this.loadUser(payload.userId));
return app()
.authenticate({ strategy: 'jwt', accessToken: token })
.then(response => this.verifyToken(response.accessToken))
marshallswain / states.js
Created Mar 18, 2018
US States & Abbreviations as JavaScript Array
View states.js
var usStates = [
{ name: 'ALABAMA', abbreviation: 'AL'},
{ name: 'ALASKA', abbreviation: 'AK'},
{ name: 'AMERICAN SAMOA', abbreviation: 'AS'},
{ name: 'ARIZONA', abbreviation: 'AZ'},
{ name: 'ARKANSAS', abbreviation: 'AR'},
{ name: 'CALIFORNIA', abbreviation: 'CA'},
{ name: 'COLORADO', abbreviation: 'CO'},
{ name: 'CONNECTICUT', abbreviation: 'CT'},
{ name: 'DELAWARE', abbreviation: 'DE'},
marshallswain / feathers-hooks.json
Last active Oct 17, 2017
VS Code Feathers Snippets
View feathers-hooks.json
"Feathers Hook": {
"prefix": ";hook;",
"body": [
"const errors = require('feathers-errors')",
"module.exports = function () {",
" return function $1 (context) {",
" $2",
" }",
marshallswain /
Last active Oct 9, 2017
Webpack configuration for CanJS

Using Webpack with CanJS

This is a good starting Webpack configuration, but will need to be adjusted to work well in production.


  1. Create webpack.config.js in the root of your project. (Refer to the Webpack CLI docs to learn how to customize this))
  2. Install dependencies: npm install webpack webpack-dev-server can-stache-loader svg-inline-loader style-loader less-loader less --save-dev

Cordova: Running an ios app in a specific ios emulator

You need two flags when specifying which target to emulate. Also, do not include the version number on the end.

Find out what emulator images are available. Again, take into account that the version number will not be included when specifying the target in the cordova call.


iPhone-5, 10.3
marshallswain / users.test.js
Created Sep 13, 2017
Simple user create test
View users.test.js
describe('create', function () {
before(function () {
return, '')
it('allows user signup', function (done) {
const newUser = {
email: '',
password: 'test'
marshallswain / app.js
Last active Jan 27, 2021
Authenticate on feathers-socketio connection with header
View app.js
const socketio = require('feathers-socketio')
const authOnSocketConnect = require('./authenticate-on-socket-connect')
// ... Setup your Feathers app code or use the generator then replace the socketio registration with this
// When you register the feathers-socketio plugin, use the utility
app.configure(socketio(function (io) {
// Get headers
io.on('connection', function (socket) {
authOnSocketConnect({ app, socket })
marshallswain / client.js
Created Aug 16, 2017
feathers-authentication Authenticate a socket client at connection time
View client.js
const feathers = require('feathers/client')
const io = require('')
const axios = require('axios')
const rest = require('feathers-rest/client')
const socketio = require('feathers-socketio/client')
const auth = require('feathers-authentication-client')
const hooks = require('feathers-hooks')
// TODO: make this port dynamic like the server tests
const host = 'http://localhost:3030'
marshallswain /
Last active Nov 25, 2018
A Feathers hook to remap service.create to do an upsert
module.exports = function (upsertQuery) {
if (typeof upsertQuery !== 'function') {
console.warn('No `upsertQuery` function was passed to the mapCreateToUpsert hook. Please set params.upsertQuery in the hook context to dynamically declare the function.')
return function mapCreateToUpsert (context) {
const { service, data, params } = context // const data = { address: '123', identifier: 'my-identifier' }
upsertQuery = params.upsertQuery || upsertQuery
if (typeof upsertQuery !== 'function') {