Skip to content

Instantly share code, notes, and snippets.

View crrobinson14's full-sized avatar

Chad Robinson crrobinson14

View GitHub Profile
@crrobinson14
crrobinson14 / Gruntfile.js
Last active October 12, 2021 06:49
How to make a REST API definition in YAML, compile it into a Swagger-compatible JSON file, expose it via Swagger-UI, then write a Mocha unit test against it to verify that a sample record validates against the JSON-Schema produced by the process. This is a great mix of tools and scripts for building RESTful APIs in Node.JS. You can build backwar…
'use strict';
var request = require('request');
module.exports = function (grunt) {
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
@crrobinson14
crrobinson14 / test-sequelize-failures.js
Last active August 29, 2015 14:13
Examples of ways to trigger SequelizeJS exceptions so you can more easily test the .catch() branches of query promise chains.
// This mechanism assumes you have an api.models hash of models - adjust to suit your actual location.
api.utils.recursiveDirectoryGlob(__dirname + '/../models', 'js').forEach(function(filename) {
var modelName = (filename.replace(/\\/g, '/').split('/')).pop().replace('.js', '');
console.log('ORM: Loading model ' + modelName);
models[modelName] = sequelize.import(filename);
});
// Pretend we've had a database failure when creating roles
Object.keys(api.models).map(function(modelName) {
ASAPP DevOps and Systems Engineering Challenge
==============================================
v0.1
Welcome to your challenge project!
You have two timeline options. If you live outside of NY and would have to fly in for your onsite, we strongly prefer that you take option 1. If coming in to the office is easy for you, then whichever you prefer is great.
Option 1: Code at home, half-day at ASAPP
@crrobinson14
crrobinson14 / asyncAction.js
Last active June 14, 2016 12:46
Wrap ActionHero methods in async() to simplify their internal await() handling.
exports.action = {
name: 'myAction',
description: 'Perform some work with multiple async steps.',
async: true,
run: function(api, data) {
var firstRecord = api.await(api.orm.getFirstRecord());
// We will async await this result here before proceeding. No callback nesting or promise chaining!
if (!firstRecord) {
throw new NotFoundError();
}
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export EVENT_NOKQUEUE=1
export GIT_MERGE_AUTOEDIT=no
export MACHINE_NATIVE_SSH=1
export HOMEBREW_GITHUB_API_TOKEN=GETYOUROWNFREAKINGTOKEN
export LANG=en_US.UTF-8
alias v="ls -l"
alias glg='git log --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --date=relative'
@crrobinson14
crrobinson14 / docker-compose.yml
Created April 12, 2016 15:40
Test Rancher config
nginx:
log_driver: ''
labels:
io.rancher.container.pull_image: always
tty: true
log_opt: {}
image: nginx:alpine
links:
- nr-db:mysql
stdin_open: true
var publicApi = {},
api;
publicApi.function1 = function() {
// If you call api.myInitializer1.function1() everything should be normal here, callee, whatever...
};
publicApi.function2 = function() {
};
// NOTE: Gist doesn't allow subdir names. This would be in migrations/
module.exports = {
description: 'Migration 00047: Sample migration file',
// Make the appropriate updates
up: function(orm, DataTypes, queryInterface) {
return orm.Promise.all([
queryInterface.addColumn('mytable', 'myField', { type: DataTypes.DATE }),
queryInterface.addColumn('mytable', 'myField2', { type: DataTypes.INTEGER, defaultValue: 0 })
]);
@crrobinson14
crrobinson14 / bootstrap.js
Last active July 12, 2016 14:56
ActionHero testing support files
// Set NODE_ENV to test so AH creates api.specHelper for us
process.env.NODE_ENV = 'test';
process.env.ACTIONHERO_CONFIG = 'config,local-config';
// Get ActionHero ready to go
var actionheroPrototype = require('actionhero').actionheroPrototype,
actionhero = new actionheroPrototype(),
running = false;
global.api = null;
var pendingNotifications = {},
publicApi = {},
api;
// Dummy function to avoid an Unhandled Rejection error if the user is offline. Prevents us
// from needing to .catch() the notification result in every spot where we call it. Also a
// useful debugging point, so we don't just null it out.
function userNotOnline() {
}