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 / 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 / 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 / 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));
}
/**
* 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 / 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
@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 / bacn.js
Last active December 27, 2015 04:48
BACN + LoopBack Example
// ... imagine backbone boilerplate here... pointing to localhost:3000
var Product = Backbone.Model.extend({
url: '/products'
});
/* would be nice if I could just include this here...
Product.validatesLengthOf('name', {
min: 3,
@ritch
ritch / RestaurantsController.js
Created November 16, 2013 00:52
Connecting Angular to MySQL through LoopBack
app.controller('RestaurantsController',
function RestaurantsController(Restaurant) {
$scope.restaurants = Restaurant.query(filterAndSortRestaurants);
});