Skip to content

Instantly share code, notes, and snippets.

Marshall Thompson marshallswain

Block or report user

Report or block marshallswain

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@marshallswain
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
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
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
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
marshallswain / readme.md
Last active Oct 9, 2017
Webpack configuration for CanJS
View readme.md

Using Webpack with CanJS

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

Instructions

  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
View 20170603-Cordova-Running-an-ios-app-in-a-specifi.md

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.

./platforms/ios/cordova/lib/list-emulator-images

iPhone-5, 10.3
@marshallswain
marshallswain / users.test.js
Created Sep 13, 2017
Simple user create test
View users.test.js
describe('create', function () {
before(function () {
return utils.services.users.removeByEmail(app, 'test@test.com')
})
it('allows user signup', function (done) {
const newUser = {
email: 'test@test.com',
password: 'test'
}
@marshallswain
marshallswain / app.js
Last active Jul 29, 2019
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 Socket.io headers
io.on('connection', function (socket) {
authOnSocketConnect({ app, socket })
@marshallswain
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('socket.io-client')
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
marshallswain / hook.map-create-to-upsert.js
Last active Nov 25, 2018
A Feathers hook to remap service.create to do an upsert
View hook.map-create-to-upsert.js
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') {
You can’t perform that action at this time.