Skip to content

Instantly share code, notes, and snippets.

View jzellis's full-sized avatar

Joshua Ellis jzellis

  • London, UK
  • 01:05 (UTC +01:00)
View GitHub Profile
@jzellis
jzellis / userSchema.js
Last active January 24, 2024 06:50
Boilerplate for simple Mongoose user schema
/*
I find myself recreating user models for Mongoose every time I start a new project, so I thought I'd create a generic schema for a user model that can be added to or modified as need be.
This is loosely based on the Meteor user model (using a "profile" sub-object for the user's personal information). It also includes an optional geolocation point for the user, and Mongoose timestamps, as well as a pre("save") function to bcrypt the user password and a comparePassword() function.
Just save this file wherever you store your models and do something like const Users = include('./models/userSchema.js') and you can just use it as a standard Mongoose user model.
The username/email address definitions were copied from this tutorial: https://thinkster.io/tutorials/node-json-api/creating-the-user-model
@jzellis
jzellis / arrayMorph.js
Last active August 18, 2016 22:44
Given an array of numeric arrays and a decimal value between 0 and max, returns a "morph" of the arrays at a point on the continuum of the arrays at that point. Used to emulate the waveform knob on a Moog synthesizer.
// These are just examples.
var arrays = [
[0.64, 0.02, 0.1, 0, 0.9, 0, 0.09, 0, 0.07, 0, 0.06, 0, 0.05, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0.81, 0, -0.09, 0, 0.03, 0, -0.02, 0, 0.01, 0, -0.01, 0, 0, 0],
[-0.32, -0.16, -0.11, -0.08, -0.06, -0.05, -0.05, -0.04, -0.04, -0.03, -0.03, -0.02, -0.02]
];
var arrayMorph = function(value, max, arrays) {
current = [];