Skip to content

Instantly share code, notes, and snippets.

View ritch's full-sized avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
@ritch
ritch / job-queue-adapters.js
Last active December 26, 2015 22:39
How to implement adapter pattern inside a LoopBack connector
var adapters = {
redis: RedisJobQueue,
foo: FooJobQueue,
bar: BarJobQueue
};
function JobQueueConnector(settings) {
this.DataAccessObject = adapters[settings.type];
}
@ritch
ritch / example.js
Last active June 6, 2018 10:19
LoopBack example for accessing the current user.
/**
* Dependencies
*/
var request = require('request');
var loopback = require('loopback');
var app = loopback();
var memoryDataSource = loopback.memory();
var HEADER_NAME = 'x-access-token'; // subject to change
/**
* First `sn install node-markdown shelljs`
* Then `sn markdown-example.js`
*/
var md = require('node-markdown').Markdown
require('shelljs/global');
/**
* Output the sample file as html
@ritch
ritch / wishful.js
Created November 13, 2012 18:04
AwaitScript
// the way you want to do it
var files = [];
function recurse(dir) {
dir.forEach(function (f) {
if(stat(f).isFile()) {
files.push(f);
} else {
recurse(fs.readdir(dir));
}
@ritch
ritch / domain-example.js
Created October 4, 2012 14:38
How to do domains...
// based on an example by @mikeal
var http = require('http')
, domain = require('domain')
;
module.exports = function (handler) {
var server = http.createServer(function (req, resp) {
var d = domain.create()
@ritch
ritch / average.js
Created September 25, 2012 16:08
Automatic Property Examples
// /students collection
// grades automatic property
var student = this
, query = {
courseId: {
$in: student.courses
}
};
dpd.assignments.average('grade', query, function (avgGrade) {
@ritch
ritch / .DS_Store
Created August 28, 2012 07:09
Dpd Recursive Fail
fail
@ritch
ritch / origin.js
Created August 26, 2012 18:38
dpd custom resource for cross origin support
// this must be in your project's node_modules folder to be available from the dashboard
var Resource = require('deployd/lib/resource')
, util = require('util');
function CrossOrigin() {
Resource.apply(this, arguments);
// match all urls when routing
this.path = '/*';
}