Skip to content

Instantly share code, notes, and snippets.

@grncdr
grncdr / custom-error.js
Last active August 29, 2015 14:05
Custom JS errors
var inherits = require('inherits');
inherits(CustomError, Error);
function CustomError () {
this.constructor.super_.apply(this, arguments);
this.name = this.constructor.name;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
@grncdr
grncdr / deferred-proxy.js
Last active August 29, 2015 14:05
Promise-based generic deferred proxy
/**
* Create a proxy object with the given prototype that caches all method calls to be applied to a target later.
*
* Example of proxying an asynchronously obtained Result object
*
* function Client (transport) {
* this._transport = transport;
* }
*
* Client.prototype.query = function (query) {
@grncdr
grncdr / why-wont-you-die.js
Created October 4, 2014 16:17
Sometimes it's hard to know who's keeping your process alive
var timeouts = [];
var intervals = [];
var sockets = [];
var setTimeout_ = setTimeout;
var clearTimeout_ = clearTimeout;
var setInterval_ = setInterval;
var clearInterval_ = clearInterval;
var Socket = require('net').Socket;
var emit = Socket.prototype.emit;
@grncdr
grncdr / formatter.js
Created November 7, 2014 22:58
Prototype of formatter for tcomb errors
'use strict';
var xtend = require('xtend');
var op = require('object-path');
var isMeta = /^meta\./;
module.exports = function formatErrors (errors, options) {
options = options || {};
var byPath = options.paths || {};
var byType = options.types || {};
@grncdr
grncdr / hook.js
Last active August 29, 2015 14:08
Collect untranslated fields in a contentful entry and forward them elsewhere.
var hyperquest = require('hyperquest');
module.exports = checkForUntranslatedFields;
module.exports.schema = {
access_token: 'string',
translation_url: 'string',
space_id: 'string',
entry_id: 'string'
};
@grncdr
grncdr / mergeHooks.js
Last active August 29, 2015 14:09 — forked from Marak/mergeHooks.js
Merge multiple Hooks into a single Hook
var http = require('http');
module['exports'] = function recieveHttp (hook) {
var hook2 = hook.open('http://hook.io/Marak/echo?foo=bar');
var hook3 = hook.open('http://hook.io/Marak/echo');
var hooks = 2;
function complete() {
@grncdr
grncdr / contentful2gengo.js
Last active August 29, 2015 14:09
Turn Contentful webhooks into Gengo jobs
var Bluebird = require('bluebird');
var createContentfulClient = require('contentful-management').createClient;
var createGengoClient = require('gengo');
var collectStream = Bluebird.promisify(require('collect-stream'));
var keys = Object.keys;
module.exports = checkForUntranslatedFields;
module.exports.schema = {
cmaAccessToken: {
@grncdr
grncdr / echoHttpRequest.js
Created November 9, 2014 15:14 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
require('bluebird');
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
@grncdr
grncdr / -
Created February 28, 2015 19:35
## THIS FILE IS MANAGED BY CHEF !
## ALL CHANGES WILL BE LOST !
storage: /var/lib/sinopia
users:
admin:
password: d033e22ae348aeb5660fc2140aec35850c4da997
stephen:
password: 50f549c3f7508d8a442df7979dabe656e28bea24
@grncdr
grncdr / protected-ipfs-api.md
Last active August 29, 2015 14:22
Ideas about using IPFS from browsers

@ehd and myself have been playing around with a concept that is sort of like an ipfs-backed-in-browser-code-editor-and-live-coding-environment.* For this to work properly the browser clearly needs access to IPFS. Luckily there is a nice API! Unfortunately, it defaults to disallowing CORS.

I'm aware of API_ORIGIN and ipfs/kubo#1215, but that approach requires the user to understand a lot of stuff: environment variables, IPFS, CORS, and other 4-letter-initialisms to make it work. This is way too high of a barrier for anybody but the most committed tech-savvy user. It also subtly encourages allowing too broad of access (e.g. allow origin of *), which is pretty sketchy in my opinion.

I'd like to propose that the IPFS API offer a more holistic approach to this problem, and will even dust off my pre-1.0 golang skills to implement it if people agree...

* I'll leave it up to him to present the proper German compound word 😉

Proposal: "Protected" API