Skip to content

Instantly share code, notes, and snippets.

@royhowie
royhowie / a.js
Last active August 29, 2015 14:24
to use queryBuilder or to not use queryBuilder…
import { PromoCode } from '../../models/models'
const AVAILABLE = { available : true }
/*
HELPER FUNCTIONS
**/
function isExpired () {
return { 'expires.date' : { $lt : new Date() } }
}
@royhowie
royhowie / example1.js
Created June 28, 2015 21:18
new es6 import syntax
// example1.js
import something from 'myModule'
console.log(something)
// this yields (note how `c` is not here):
/*
{
a : true,
b : 42,
d : 'some property only available from default'
}
@royhowie
royhowie / changePassword.js
Created June 21, 2015 06:48
directly return promise or…? (which is better?)
userSchema.methods.changePassword = function (password) {
// option 1
return new Promise((resolve, reject) => {
let evaluatePassword = passwordStrength(password)
if (evaluatePassword.state) {
return this.generateHash(password).then((hash) => {
this.password = hash
return this
})
} else {
@royhowie
royhowie / roy.js
Last active August 29, 2015 14:23
what does it do?
(($,_) =>
_._[_.___(_.__._)](_.___(_.__.__))
)(_$ = {
_ : (__) =>__.map(_=>
[_,_,_].map(($,_)=>($=+!![],$<<$<<$)-(--_<<+!![])+$)[
($=(!0+[])[3]),(!0+[])[1]+$+([][[]]+[])[2]+([][[]]+[])[0]+([]+{})[5]+$
]((_,__)=>_*__)-_)
}, {
_ : this,
__ : {
@royhowie
royhowie / new-params.js
Last active August 29, 2015 14:23
How moving to ES6 and promises changed my params.js file in node (my :param middleware for routes)
import { courseQueries, oneOnOneQueries, userQueries } from '../lib/queries'
import ERRORS from '../lib/errors'
function passAlongCode (propertyName) {
return function (req, res, next, code) {
req[propertyName] = code
return next()
}
}
@royhowie
royhowie / new-passport.js
Last active August 29, 2015 14:23
why promises are great
import User from '../models/user'
import { userQueries } from './queries'
let LocalStrategy = require('passport-local').Strategy
export default function (passport) {
passport.serializeUser(serializeUser)
passport.deserializeUser(deserializeUser)
passport.use('register', getStrategy(register))
passport.use('login', getStrategy(login))
@royhowie
royhowie / accounts.js
Last active August 29, 2015 14:22
how to use a closure
module.exports = {
localLogin: function (passport) {
return passport.authenticate("login", {
successRedirect: "/order/admin",
failureRedirect : "/order/admin/login",
failureFlash : true
})
}
}
@royhowie
royhowie / accounts.js
Last active August 29, 2015 14:22
Why Function.prototype.bind is useful (but mostly how I set up my node.js projects)
module.exports = {
// lots of other files are also exported
localLogin: function (passport, req, res, next) {
passport.authenticate("login", {
successRedirect: "/order/admin",
failureRedirect : "/order/admin/login",
failureFlash : true
})(req, res, next);
},
localSignup: function (passport, req, res, next) {
@royhowie
royhowie / callbacks.js
Last active August 29, 2015 14:22
how to use callbacks according to NPM style guides
// in your library.js file
module.exports = {
getFibonacciNumber: function (n, done) {
if (n < 0) {
return done("Can only calculate fibonacci numbers for an integer n > -1 !");
} else {
var a = 0
, b = 1
, i = 0
, holder
import UIKit
class LoginViewController: UIViewController {
let domain = "http://plebvote.com:1337"
let URI = "/order/login"
@IBOutlet weak var usernameTxt: UITextField!
@IBOutlet weak var passwordTxt: UITextField!