Skip to content

Instantly share code, notes, and snippets.

@fiznool
fiznool / fz.restsource.js
Created April 17, 2014 14:27
Patch for angularjs $resource to send POST or PUT depending on ID field
// This patches the $resource.$save function
// to make a PUT when an ID is present.
// Inspired by http://kirkbushell.me/angular-js-using-ng-resource-in-a-more-restful-manner/
'use strict';
angular.module( 'fz.restsource', [ 'ngResource' ] )
.factory('$restsource', function($resource) {
var idField = '_id';
@fiznool
fiznool / app.js
Last active August 29, 2015 14:01 — forked from silas/app.js
var express = require('express'),
app = express();
app.configure(function() {
app.use(express.bodyParser());
app.use(app.router);
});
app.get('/', function(req, res) {
res.send(500);
@fiznool
fiznool / convert-json-to-js.js
Created September 9, 2014 11:19
Converts a directory of JSON files to JS ones.
'use strict';
var util = require('util'),
fs = require('fs');
var path = './server/services/defs';
var dirs = fs.readdirSync(path);
dirs.forEach(function(dir) {
var servicePath = path + '/' + dir;
@fiznool
fiznool / q-extra.decorator.js
Created September 25, 2014 10:48
Add extra functions to the $q Angular service.
'use strict';
angular.module('q-extra', [])
.config(['$provide', function($provide) {
$provide.decorator('$q', ['$delegate', function($delegate) {
if(angular.isUndefined($delegate.resolve)) {
$delegate.resolve = function($q) {
return function(val){
var dfd = $q.defer();
dfd.resolve(val);
@fiznool
fiznool / hashid.js
Created November 16, 2014 09:45
Short 'hash' ID generator.
'use strict';
/**
* The default alphabet is 25 numbers and lowercase letters.
* Any numbers that look like letters and vice versa are removed:
* 1 l, 0 o.
* Also the following letters are not present, to prevent any
* expletives: cfhistu
*/
var ALPHABET =
@fiznool
fiznool / index.js
Created December 18, 2014 08:19
request basic auth
var request = require('request');
// The `auth` object will take precedence
// over the `Authorization` header
var options = {
url: 'http://requestb.in/1jt9nmk1',
method: 'GET',
headers: {
Authorization: 'Basic 1234'
},
@fiznool
fiznool / index.js
Last active October 5, 2017 16:19
Testing some date parsers
// Testing out some date parsing libraries.
'use strict';
var chrono = require('chrono-node');
require('datejs');
require('sugar');
var stringsToParse = [
'today',
@fiznool
fiznool / date-duration.js
Created February 5, 2015 10:27
Date Duration
Date.prototype.duration = function(granularity) {
if(!granularity) {
granularity = 's';
}
var units = [{
enabled: /^[wdhms]$/.test(granularity),
singular: 'week',
plural: 'weeks',
inMillis: 7 * 24 * 60 * 60 * 1000
#!/bin/bash
if [ "$GIT_SSH_KEY" != "" ]; then
echo "Cleaning up SSH config" >&1
echo "" >&1
# Now that npm has finished running,
# we shouldn't need the ssh key/config anymore.
# Remove the files that we created.
rm -f ~/.ssh/config
rm -f ~/.ssh/deploy_key

As discussed on gitter, the plan is to implement the error handling as a two-stage process.

  1. Add an additionalCodes property to the error object passed in as the third argument to the api handler. This will specify the additional error responses that should be setup by API Gateway, and the associated regexes.
  2. Create a new claudia-api-errors module, which will allow developers to throw a predefined set of Error objects, which will correspond to response codes.

Only 1. needs to be implemented to allow multiple error responses, 2. is more of a nice-to-have.

Background

API Gateway allows you to parse the error message returned from a lambda function, and apply a response code according to a regex that you configure. Here's a good primer on how this works.