Skip to content

Instantly share code, notes, and snippets.

View doublemarked's full-sized avatar

Heath Morrison doublemarked

View GitHub Profile
### Keybase proof
I hereby claim:
* I am doublemarked on github.
* I am doublemarked (https://keybase.io/doublemarked) on keybase.
* I have a public key ASDt-2MkG9cfX0ix9VfFNuHpSjQKFs6kSsivg7e8_2SJVAo
To claim this, I am signing this object:
@doublemarked
doublemarked / 01:unit-tests-example.js
Last active February 6, 2019 22:07
Testing Loopback Projects (a simplified extraction)
// File Location: test/unit/user/
const appRoot = require('app-root-path')
const bootstrap = appRoot.require('/test/bootstrap')
const expect = bootstrap.expect
describe('Example Unit Tests', function () {
const User = bootstrap.app.models.User
@doublemarked
doublemarked / !Fragmenting Loopback Models.md
Last active May 2, 2016 00:40
Boot script for fragmented loading of Loopback models

Fragmenting Loopback Models

Hey! I've bundled this approach into a component: https://github.com/doublemarked/loopback-component-model-fragments

This boot script will load module components on app initialization. Stick this file in server/boot. Components are looked for in the directory common/models/model-name. The script will load recursively any script from that directory, passing it the Model handle as a parameter (just like model.js loads). Conveniently, since this is occuring during the boot phase, those model scripts will execute at a later phase than model.js, meaning PersistedModel is already initialized and all peer model handles are already usable. Note - it's necessary for you to still maintain a model.js file for Loopback to load the model at all.

@doublemarked
doublemarked / 1:middleware.json
Last active December 15, 2017 02:06
Bunyan Loopback logging
{
"initial:before": {
"loopback#context": {
"params": { "enableHttpContext": true }
},
"loopback#token": {},
"loopback#favicon": {
"params": "$!../client/images/govright-favicon.ico"
},
"./middleware/logging": {},
@doublemarked
doublemarked / bootstrap.js
Last active November 23, 2015 16:37
Loopback unit testing bootstrapper
var chai = require('chai');
chai.use(require('chai-things'));
var expect = chai.expect;
var appRoot = require('app-root-path');
var factories = appRoot.require('/server/test/factories');
var app = appRoot.require('/server/server');
var contextUtils = appRoot.require('/common/utils/context');
@doublemarked
doublemarked / hasManyThroughProblems.js
Last active August 29, 2015 14:27
Demonstration of problems with hasManyThrough relations and the relation.findOne helper
// mocha hasManyThroughProblems.js
var app = require('loopback/test/fixtures/simple-integration-app/server/server.js');
var expect = require('chai').expect;
describe('relation check', function() {
before(function defineProductAndCategoryModels() {
var product = app.model(
'product',
@doublemarked
doublemarked / law-index.html
Last active August 29, 2015 14:22
ui-tree demonstration (from LegislationLab.org)
<div ng-controller="LawIndexController" class="law-index" scroll-to-active-child>
<h2>
<a href ui-sref="site.law.overview">{{law | i18n:'title'}}</a>
</h2>
<div ui-tree drag-enabled="false">
<ol ui-tree-nodes="" ng-model="law.nodes">
<li
ui-tree-node
data-collapsed="true"
ng-repeat="n in law.nodes"
[
{"US":"United States"},
{"CA":"Canada"},
{"AF":"Afghanistan"},
{"AL":"Albania"},
{"DZ":"Algeria"},
{"DS":"American Samoa"},
{"AD":"Andorra"},
{"AO":"Angola"},
{"AI":"Anguilla"},
@doublemarked
doublemarked / rake routes
Created September 26, 2012 11:09
Rails parameter naming discrepancy
Kombucha:delme$ rake routes
snack_eat GET /snacks/:snack_id/eat(.:format) snacks#eat
snacks GET /snacks(.:format) snacks#index
POST /snacks(.:format) snacks#create
new_snack GET /snacks/new(.:format) snacks#new
edit_snack GET /snacks/:id/edit(.:format) snacks#edit
snack GET /snacks/:id(.:format) snacks#show
PUT /snacks/:id(.:format) snacks#update
DELETE /snacks/:id(.:format) snacks#destroy