Skip to content

Instantly share code, notes, and snippets.

View ritch's full-sized avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
# setup an office supply store
# deny everything by default
$ slc lb acl --deny --model product --everyone
# allow customers to browse the products
$ slc lb acl --allow --model product --everyone --read
# only allow the store owners to modify or delete them
$ slc lb acl --allow --model product --owner --all
@ritch
ritch / example.js
Last active August 29, 2015 13:56
Micro Processes
var MicroProcess = require('../lib/micro-process');
var loopback = require('loopback');
var app = loopback();
app.use(function(req, res, next) {
var p = new MicroProcess([req.method, req.url].join(' '));
p.run(next);
p.on('error', function(err) {
console.error(err);
@ritch
ritch / example.sh
Last active August 29, 2015 13:59
From 0 to MongoDB in 30 seconds...
# Run the following steps in your terminal...
# make sure you have node and mongo installed
npm install strong-cli
# create a loopback project
slc lb project mongo-example
cd mongo-example
# create a loopback model
@ritch
ritch / faq.md
Last active August 29, 2015 14:00
FAQ for LoopBack replication

Will it be possible to use continuous replication, so the client immediately triggers a replication when local data changes. And the server uses a push mechanism?

Yes... here is a basic example that relies on a socket.io style EventEmitter.

// psuedo-server.js
MyModel.on('changed', function(obj) {
  socket.emit('changed');
});
@ritch
ritch / zonify-loopback.md
Created May 12, 2014 18:18
How might we zonify loopback?

Here is a basic (truncated) callstack for a REST request to loopback.

  • GET /users
  • loopback.rest()
    • loopback.token()
    • Model.checkAccess()
    • sharedMethod.invoke(argsFromHttpCtx)
      • User.find()
        • connector.find()
          • driver.find()
@ritch
ritch / post.md
Last active August 29, 2015 14:01

Lessons Learned from Stateful Modules

Background

We forked the jugglingdb module to create loopback's orm. Jugglingdb allows you to define models and the relations between them. One of the fundemental mechanisms that it uses to do this is the type registry.

You can see this implemented in the original jugglingdb project

exports.Schema = Schema;
@ritch
ritch / comparison.js
Last active August 29, 2015 14:04
Vanilla Express / Express + co comparison
// my existing express app
app.use(myMiddleware);
function myMiddleware(req, res, next) {
doSomething(next); // does something async + takes a callback
}
app.get('/', function(req, res, next) {
getHomePageData(function(err, data) {
@ritch
ritch / controller.js
Last active August 29, 2015 14:24
Idea to simplify the definition of angular modules
/**
* @module myServiceModule
* @controller MyController
* @inject $scope notify
*/
$scope.callNotify = function(msg) {
notify(msg);
};
@ritch
ritch / rfc.md
Created July 30, 2015 19:03
Next Generation of Model and Boot Scripts

Model and Boot Scripts

Currently, model scripts and the way they are loaded are a bit naive.

Take a look at this example:

// models/my-model.js
module.exports = function(MyModel) {
  MyModel.findFooBars = function(filter, cb) {
@ritch
ritch / loopback-3-with-mixins.md
Last active August 29, 2015 14:27
LoopBack 3 with Mixins as First Class Citizens

LoopBack 3

Core + Boot + Connector refactor

0. setup

  • all components loaded into registry
  • all mixins loaded into registry
  • registry mixins applied
  • create models, apply model configs, etc
  • create data sources