Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jsruvi on github.
  • I am ruvi (https://keybase.io/ruvi) on keybase.
  • I have a public key ASCAR5JoIuq3PoAWhWG6xXTD4My1WY3X_LIOGKzh1c5Cxgo

To claim this, I am signing this object:

@jsruvi
jsruvi / better-nodejs-require-paths.md
Created October 30, 2016 18:03 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

// Restify Server CheatSheet.
// More about the API: http://mcavage.me/node-restify/#server-api
// Install restify with npm install restify
// 1.1. Creating a Server.
// http://mcavage.me/node-restify/#Creating-a-Server
var restify = require('restify');
public.post('/custom', function*(next) {
var ctx = this
yield passport.authenticate('local', function*(err, user, info) {
if (err) throw err
if (user === false) {
ctx.status = 401
ctx.body = { success: false }
} else {
yield ctx.login(user)
ctx.body = { success: true }
@jsruvi
jsruvi / exception handling
Created September 17, 2016 20:34
exception handling
'use strict';
const passport = require('koa-passport');
const LocalStrategy = require('passport-local').Strategy;
const FacebookStrategy = require('passport-facebook').Strategy;
const BearerStrategy = require('passport-http-bearer').Strategy;
const StripeStrategy = require('passport-stripe').Strategy;
const query = require('./query');
const validatePw = require('./validatePassword');
const genHash = require('./genHash');
@jsruvi
jsruvi / client.js
Created July 18, 2016 18:04 — forked from crtr0/client.js
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});