Skip to content

Instantly share code, notes, and snippets.

@devinivy
devinivy / stubQueryMethod.js
Last active September 29, 2020 10:31 — forked from wxactly/stubQueryMethod.js
Sails.js: Stub Waterline query method with Sinon.js
var util = require('util');
var _ = require('lodash');
var sinon = require('sinon');
/**
* Replaces a query method on the given model object with a stub. The query
* will still operate on a callback, and allow full access to waterline's
* deferred object. However, the query will not cause any I/O and instead
* will immediately resolve to the given result.
*
@devinivy
devinivy / hapi-mock-scheme.js
Created October 6, 2015 15:34
A mock auth scheme for testing
// Mock scheme for testing
server.auth.scheme('mock', function(server, options) {
return {
authenticate: function(request, reply) {
reply({credentials: options});
}
};
});
module.exports = function (graph, root) {
var traversal = graph.traverse();
var edges = [];
var stack = [root];
var current = null;
while (stack.length) {
traversal.hop(stack.pop());
@devinivy
devinivy / polymer-w-reflux.md
Last active January 27, 2016 19:59
Polymer with Reflux

Polymer with Reflux

Implementation

Ties together Polymer and Reflux

Is a demo of using Polymer with Reflux via funk

The Pieces

These are thoughts pre-funk!

@devinivy
devinivy / supertouch.sh
Created January 15, 2016 21:13
Create all necessary dirs while touching a file
# from http://unix.stackexchange.com/a/168582
supertouch() {
for p in "$@"; do
_dir="$(dirname -- "$p")"
[ -d "$_dir" ] || mkdir -p -- "$_dir"
touch -- "$p"
done
}
@devinivy
devinivy / server.js
Created January 20, 2016 03:34
Testing an initialized hapi server
var Hapi = require('hapi');
// Keep track of the server's init state
var internals = {
initialized: false
};
var server = new Hapi.Server();
server.connection();
@devinivy
devinivy / index.js
Last active May 5, 2016 12:40
Knex locked connections
'use strict';
const Knex = require('./knex');
const knex = Knex({
dialect: 'postgres',
connection: {
adapter: 'postgresql',
database: 'test',
user: 'postgres'
@devinivy
devinivy / test-npmignore.sh
Created June 13, 2016 13:28
List the files that .npmignore will pack-up
# from https://github.com/hapijs/contrib/issues/90#issuecomment-224889568
tar -tf $(npm pack) && rm *.tgz
@devinivy
devinivy / sam-redux.md
Last active June 29, 2016 11:41
SAM meets Redux
  • model is a redux store.
  • actions are thunks.
  • nap() via model.subscribe().
  • present() is model.dispatch().
  • acceptor logic is redux middleware.
  • state/learner is implemented with ReactRedux.connect() and selectors (i.e. reselect).
@devinivy
devinivy / app.conf
Created July 14, 2016 13:06
Nginx reverse-proxy config for many apps
include /etc/nginx/conf.d/real-scheme.block;
upstream <app> {
server 127.0.0.1:<port>;
keepalive 16;
}
server {
listen 80;
server_name <server>;