Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
drmikecrowe / app.js
Last active October 27, 2021 04:28
Sharing constants between node.js app and web app
//** In web app **//
var current = constants.STATE_WAITING;
var forms = require('forms');
var fields = forms. fields,
validators = forms.validators,
widgets = forms.widgets;
var _ = require('lodash');
var fs = require('fs');
function repl(str,arr) {
_.forOwn(arr,function(value,key) {
var search = '{'+key+'}';
@drmikecrowe
drmikecrowe / reindex-db.js
Last active July 25, 2016 07:22
Complex indices (and post-create index) of Waterline models
/**
* FILE: api/hooks/reindex-db.js
*
* Created by mcrowe on 1/28/15.
*
* Insures indices recreated if needed, and allows complex indicies to be specified in the model as well. Example:
*
module.exports = {
schema : true,
version : "1.3",
@drmikecrowe
drmikecrowe / README.md
Last active August 29, 2015 14:16
Reformat Gherkin test scripts to line up properly

Setup/Configuration

Here's how our tests are setup:

  • Tests are grouped in subdirectories
  • Each directory/filename is prefixed with a number between 100-999, typically incremented by 10. This allows us to insert new tests into the stream of sequential tests
  • Tests start at 100, but configuration setup tests start at 010.
  • Tests are tagged according to the directory, and directory/file

This is very easy to understand/use, especially when you get 1000s of steps/scenarios and complex tests in your setup.

@drmikecrowe
drmikecrowe / app.yml
Last active August 29, 2015 14:17 — forked from Zolmeister/app.yml
---
# file: roles/app/tasks/main.yml
- name: ensure logging directory exists
file: path=/var/log/acme state=directory
tags:
- install
- name: ensure config directory exists
file: path=/etc/acme/app state=directory
docker-yml() {
docker inspect -f $'
{{.Name}}
image: {{.Config.Image}}
entrypoint: {{json .Config.Entrypoint}}
environment: {{range .Config.Env}}
- {{.}}{{end}}
' $1
}
@drmikecrowe
drmikecrowe / setup.js
Created January 19, 2016 18:05
Set debug log level for MongoClient
var MongoClient = require('mongodb').MongoClient
, Logger = require('mongodb').Logger;
Logger.setLevel('debug');
@drmikecrowe
drmikecrowe / Account.js
Last active June 17, 2021 16:38
Auto-incrementing ID's in Loopback
module.exports = function (Account) {
Account.observe('before save', function addAccountId(ctx, next) {
if (!ctx.isNewInstance) {
debug('id is already set, returning', ctx.data);
return next();
}
app.dataSources.db.connector.collection("Sequences").findAndModify({name: 'Account'}, [['_id', 'asc']], {$inc: {value: 1}}, {new: true}, function (err, rec) {
if (err) {
console.err(err);
@drmikecrowe
drmikecrowe / DisableAllMethods.js
Last active September 5, 2019 06:58
Loopback mixin to disable or expose methods
// based on https://github.com/strongloop/loopback/issues/651#issuecomment-259540469
'use strict';
const
relationMethodPrefixes = [
'prototype.__findById__',
'prototype.__destroyById__',
'prototype.__updateById__',
'prototype.__exists__',
@drmikecrowe
drmikecrowe / Dockerfile
Created January 14, 2017 04:01
Working PHP Docker Compose System with PhantimJS testing
# Build using docker build -t php-drmikecrowe
FROM php:5.6-apache
MAINTAINER Emilien Kenler <[email protected]>
RUN apt-get update && apt-get install -y git libpq-dev libmcrypt-dev zlib1g-dev libicu-dev g++ graphviz && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_pgsql pdo_mysql mbstring mcrypt zip sockets intl bcmath mysqli
RUN curl -o /usr/local/bin/composer https://getcomposer.org/composer.phar && \