Skip to content

Instantly share code, notes, and snippets.

/**
* I have recently started to embrace TDD or BDD or whatever we are calling it today. I was
* hoping for some feedback on my how I am structuring my tests. Currently I am writing
* functional tests for my API routes. One thing I dislike is that I have included a global
* data object in each file and beforeEach test generating json web tokens for auth purposes.
* I could probably move that actual logic to some test helper but I still have to store
* this global (for the page) object. Just trying to some feedback. Any advice, even
* unrelated to this, is gladly appreciated.
*/
'use strict';
var _ = require('lodash'),
Promise = require('bluebird'),
models = require('../database'),
pipeline = require('../utils/pipeline'),
utils = require('./utils'),
errors = require('../errors');
var listing = {
@aray12
aray12 / promise-with-arrows.js
Last active October 22, 2015 17:50
Promise.join with arrow function
/**
* This does not work on node v4.2.0
*
* Reason has been determined. The first example of arrow functions is a function
* definition, not a function call. The second is a function call that passes the
* return value to Promise.join
*/
'use strict';
const Promise = require('bluebird');
# /etc/rc.d/rc.local
HOMEDIR = /home/ec2-user
GITREPO = git@github.com:org/project.git
GITDIR = $HOMEDIR/project
cd $HOMEDIR
# Clone the latest version
git clone $GITREPO
const someArray = [4,3,3,2,5,6,63,1,43,34,46,46,2,35,35,64,75];
function sum(list) {
let count = 1;
function add(x,y) {
const sum = x + y;
if(++count > list.length - 1) {
return sum;
const someArray = [4,3,3,2,5,6,63,1,43,34,46,46,2,35,35,64,75];
function reduction(list, callback) {
if (typeof callback !== 'function') {
throw new Error('callback not function');
}
let count = 1;
function reducting(current) {
if (++count > list.length - 1) {
@aray12
aray12 / App.js
Last active January 20, 2016 18:07
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import NavBar from './Navbar';
import Login from './Login';
export default class App extends Component {
constructor(props, context) {
super(props, context);
#!/usr/bin/env bash
# This kills all connections to a database a resets it based
# on a backup file. The first argument passed should be the
# name of the database. The second should be the complete
# filepath for the backup. The backup should have already been
# compressed using the gzip utility. If you are working on a
# remote database set the environment variables recognized by
# psql
#
@aray12
aray12 / codedeploy-github.sh
Created January 22, 2017 23:56
Deploy using github as the source of your revision
#!/usr/bin/env bash
APPLICATION_NAME="YOUR_APP_NAME"
DEPLOYMENT_GROUP="YOUR_DEPLOY_GROUP_NAME"
REGION="us-west-2"
REPOSITORY="your/github-repo"
# Install jq if not already installed
# We use jq to parse the json return by the AWS API's
# If you don't know about jq, it is dope. Learn more here: https://stedolan.github.io/jq/
@aray12
aray12 / queryMiddleware.js
Created January 24, 2017 02:59
With redux-api-middelware takes a property called query and appends a query string to the endpoint
import qs from 'querystring';
import { CALL_API } from 'redux-api-middleware';
export default function queryMiddleware() {
return next => action => {
if (action.hasOwnProperty(CALL_API) && action[CALL_API].hasOwnProperty('query')) {
const request = action[CALL_API];
request.endpoint = [
request.endpoint.replace(/\?*/, ''),
qs.stringify(request.query),