Skip to content

Instantly share code, notes, and snippets.

View alexsmith716's full-sized avatar

Alex Smith alexsmith716

  • NYC
  • New York, NY
View GitHub Profile
@alexsmith716
alexsmith716 / interactiveFormValidationEnabled.txt
Created August 23, 2017 13:55
Testing userAgent HTML5 constraints
// testing userAgent HTML5 constraints
// is userAgent Safari && webkitVersion 603 or higher
// https://webkit.org/blog/7099/html-interactive-form-validation/
<script>
var isSafari = (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)
var interactiveFormValidationEnabled = false
var appVersion = navigator.appVersion
var webkitVersion1 = appVersion.indexOf('AppleWebKit/') + 12
@alexsmith716
alexsmith716 / authentication.js
Last active August 23, 2017 13:15
Authentication modifications to 'getting-MEAN'
// my authentication modifications to book 'Getting MEAN'
// repository: https://github.com/simonholmes/getting-MEAN
// file: './app_api/controllers/authentication.js'
var passport = require('passport');
var mongoose = require('mongoose');
var User = mongoose.model('User');
var sendJSONresponse = function(res, status, content) {
@alexsmith716
alexsmith716 / passport.js
Last active August 22, 2017 17:14
Authentication modifications to 'getting-MEAN'
// my authentication modifications to book 'Getting MEAN'
// repository: https://github.com/simonholmes/getting-MEAN
// file: './app_api/config/passport.js'
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongoose = require('mongoose');
var User = mongoose.model('User');
@alexsmith716
alexsmith716 / users.js
Last active August 22, 2017 17:14
Authentication modifications to 'getting-MEAN'
// my authentication modifications to book 'Getting MEAN'
// repository: https://github.com/simonholmes/getting-MEAN
// file: './app_api/models/users.js'
var mongoose = require( 'mongoose' );
var crypto = require('crypto');
var jwt = require('jsonwebtoken');
var userSchema = new mongoose.Schema({
@alexsmith716
alexsmith716 / npmPermissionError.md
Last active August 22, 2017 19:22
Unexpected "npm command not found" error, but Node is installed

Possible fix for npm -global related errors on Mac OSX with Node installed through Homebrew

Unexpected "npm command not found" error received, but I did not uninstall npm and Node is installed and returning it's correct version


* update: since this post i have been using Yarn *

and it installed with ease

brew install yarn


@alexsmith716
alexsmith716 / newObjectErrorEnumerable.js
Last active June 29, 2017 17:26
Send Node.js Error object properties, including 'stack', in a JSON response
// Send Node.js Error object properties, including 'stack', in a JSON response
// A existing Error object is passed to below module and a new object with properties is returned
// To create a custom Error object first use 'customErrorObject.js' module below, then pass to below module
module.exports = function (errorObject) {
var newObjectErrorEnumerable = {}
Object.keys(errorObject).forEach(function (k) {
@alexsmith716
alexsmith716 / serverSideValidation.js
Last active June 25, 2017 02:00
A server-side data validation module I wrote. Pass User data and a template (basically your schema model) to script and receive an evaluated object in return. Client-side validation is important, server-side validation is critical. All User data entering your app must be evaluated/validated.
/*
req.body.template = {displayname: 'required',
email: 'required',
confirmEmail: 'required',
password: 'required',
confirmPassword: 'required',
firstname: 'required',
lastname: 'required',
city: 'required',
@alexsmith716
alexsmith716 / evaluateUserEmail.js
Last active June 23, 2017 19:09
A simple User email evaluator module I wrote. Tests on an expectedResponse.
var mongoose = require('mongoose')
var User = mongoose.model('User')
module.exports = function (req, res, cb) {
var expectedResponse = req.body.expectedResponse
!expectedResponse ? expectedResponse = req.body.template.expectedResponse : null
var email = req.body.email.trim()
@alexsmith716
alexsmith716 / controlJQueryEvents.js
Last active May 29, 2017 18:06
Better control of jQuery events. Control events on a cancelled Bootstrap Modal form.
// 'Cancel' button on a Bootstrap Modal form
// This simply cancels active input events when user cancels a form
// Note data-dismiss="modal" since this button is child of form element. It prevents form submission and hides Modal
// button(class="btn btn-default btn-md", data-dismiss="modal", id="newUserDataItemModalCancel") Cancel
// Turn Off Selected Events:
turnOffSpecificEvents: function () {
$('#newUserDataItem').off('change')
@alexsmith716
alexsmith716 / Guidelines.md
Created May 18, 2017 17:54
Microsoft's REST API Guidelines Resource