Skip to content

Instantly share code, notes, and snippets.

View bajtos's full-sized avatar

Miroslav Bajtoš bajtos

View GitHub Profile
@bajtos
bajtos / notice.md
Last active August 29, 2015 14:06
LoopBack workshop
@bajtos
bajtos / Instructions.md
Created September 9, 2014 16:27
Add a custom remote method to a full-stack LoopBack AngularJS applications

This is an extra exercise for the workshop Building a full-stack application with LoopBack and AngularJS.

Add a custom model method

Let's write a method Whiskey.prototype.ratingStats that will provide a breakdown of rating data for a given whiskey. This method should be defined in common/models/whiskey.js. Below is a template, it's up to the reader to implement the statistical computation.

@bajtos
bajtos / Instructions.md
Created September 9, 2014 16:28
Switch the full-stack LoopBack AngularJS applications to MySQL database
@bajtos
bajtos / strawman.md
Created September 14, 2014 07:39
LoopBack Components - a strawman proposal

LoopBack Components - a strawman proposal

Component definition

Metadata

Component metadata is stored in package.json under loopback-component property.

@bajtos
bajtos / bug-326-juggler.js
Last active August 29, 2015 14:07
Auto-generated id property with a custom getter function
var jdb = require('./');
var ModelBuilder = jdb.ModelBuilder;
var DataSource = jdb.DataSource;
var Memory = require('./lib/connectors/memory');
var assert = require('assert');
var ID = 'custom-generated-id';
var memory = new DataSource({connector: Memory});
var modelBuilder = memory.modelBuilder;
@bajtos
bajtos / example.js
Last active August 29, 2015 14:08
express and phases
function createLoopBackApp() {
var app = express();
// add loopback stuff
app.phase('routes').use(function(req, res, next) {
if (app._router) {
app._router.handle(res, res, next);
} else {
next();
}
@bajtos
bajtos / 0-desc.md
Last active January 13, 2016 00:08
LoopBack Realtime

Imagine a chat server persisting the messages, a simplified Slack chat. The domain is designed in the object-orientated style. In order to get realtime updates, we need to transport events emitted on the model constructor ("static" events) and on a model instance ("instance" events).

While it may not be immediately clear, the example is covering few other important LoopBack concepts too:

  • authorization (loopback.token in REST)
  • current context (loopback.context in REST)

What is not covered:

  • file uploads and downloads
@bajtos
bajtos / testing-framework.md
Last active August 29, 2015 14:10
Unit-test framework requirements
  • API to group test cases into test suites, e.g. describe and it

  • setup/teardown hooks (before, beforeEach, after, afterEach)

  • Support for promises: test case returns a promise, the test runner waits until the promise is resolved

  • Output formatters: junit/xunit for CI, spec-like for humans (a list of failed tests is printed again at the end)

  • Run all tests in a single file, run a single test case, run a single test suite.

@bajtos
bajtos / 1-source benchmark-fs-promised-stat.js
Last active August 29, 2015 14:11
Benchmark of fs.stat with promises
// Call fs.stat over and over again really fast.
// Then see how many times it got called.
// Yes, this is a silly benchmark. Most benchmarks are silly.
var path = require('path');
var common = require('../common.js');
var fs = require('fs');
var FILES = [
require.resolve('../../lib/assert.js'),
@bajtos
bajtos / hooks-status.md
Last active April 18, 2016 09:53
LoopBack Hooks