Skip to content

Instantly share code, notes, and snippets.

View marshallswain's full-sized avatar
😄

Marshall Thompson marshallswain

😄
View GitHub Profile
@marshallswain
marshallswain / simple-mongoose-schema.js
Created July 8, 2017 03:58
Simple Mongoose Schema
// address-map-model.js - A mongoose model
//
// See http://mongoosejs.com/docs/models.html for more of what you can do here.
module.exports = function (app) {
const mongooseClient = app.get('mongooseClient')
const addressMap = new mongooseClient.Schema({
identifier: { type: String, required: true },
address: { type: String, required: true }
})
@marshallswain
marshallswain / address-map-data.json
Created July 8, 2017 04:05
Example address-map data
[
{"address": "1", "identifier": "xxx"},
{"address": "1", "identifier": "yyy"},
{"address": "1", "identifier": "zzz"},
]
@marshallswain
marshallswain / feathers-mongoose-upsert-2.js
Last active November 24, 2021 10:18
Another example of feathers-mongoose upserting
const data = { address: '2', identifier: 'some-other-identifier' }
const params = {
query: { address: '2' },
mongoose: { upsert: true }
}
app.service('address-meta').patch(null, data, params)
@marshallswain
marshallswain / hook.map-create-to-upsert.js
Last active June 16, 2022 18:29
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') {
@marshallswain
marshallswain / client.js
Created August 16, 2017 17:29
feathers-authentication Authenticate a socket client at connection time
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 / app.js
Last active May 18, 2021 17:08
Authenticate on feathers-socketio connection with header
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 / users.test.js
Created September 13, 2017 19:56
Simple user create test
describe('create', function () {
before(function () {
return utils.services.users.removeByEmail(app, '[email protected]')
})
it('allows user signup', function (done) {
const newUser = {
email: '[email protected]',
password: 'test'
}

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 / readme.md
Last active October 9, 2017 13:44
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.

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
@marshallswain
marshallswain / feathers-hooks.json
Last active October 17, 2017 18:08
VS Code Feathers Snippets
{
"Feathers Hook": {
"prefix": ";hook;",
"body": [
"const errors = require('feathers-errors')",
"",
"module.exports = function () {",
" return function $1 (context) {",
" $2",
" }",