Skip to content

Instantly share code, notes, and snippets.

View Marak's full-sized avatar

Marak

View GitHub Profile
@Marak
Marak / proxy.js
Created July 14, 2015 04:12
hook.io microservice for proxying http requests
module['exports'] = function proxyHook (hook) {
hook.res.end('proxied');
};
@Marak
Marak / test.js
Last active August 29, 2015 14:24
testGist
module['exports'] = function echoHttp (hook) {
hook.debug("test messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@Marak
Marak / coinHook.js
Last active August 29, 2015 14:23
hook.io microservice for getting crypto-coin price data from coinmarketcap.com
module['exports'] = function getCoin (hook) {
var request = require('request');
var url = 'http://coinmarketcap-nexuist.rhcloud.com/api/' + hook.params.coin;
request(url, { json: true }, function (err, response, body) {
if (hook.params.currency !== 'all') {
// if a specific currency is selected, filter the results
return hook.res.end(body['price'][hook.params.currency]);
} else {
// else, send all coin data back
hook.res.end(JSON.stringify(body));
@Marak
Marak / markdownHook.js
Last active August 29, 2015 14:23
hook.io microservice for rendering markdown to HTML
module['exports'] = function markdownHook (hook) {
var marked = require('marked');
// TODO: expose parser options through schema
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
@Marak
Marak / geoipHook.js
Last active August 29, 2015 14:23
hook.io microservice for geoip
module['exports'] = function geoipHook (hook) {
var geoip = require('geoip-lite');
var ip = hook.params.ip;
if (typeof ip === "undefined" || ip.length === 0) {
ip = hook.req.headers['x-forwarded-for'];
}
console.log('attempting to lookup ' + ip);
var geo = geoip.lookup(ip);
if (geo === null) {
return hook.res.end(JSON.stringify({ message: "invalid ip " + ip.toString(), error: true }, true, 2));
@Marak
Marak / spellcheckHook.js
Last active August 29, 2015 14:23
hook.io microservice for spellchecking
module['exports'] = function echoHttp (hook) {
var path = require('path');
var SpellCheck = require('spellcheck'),
base = __dirname + "../../../../modules/builds/hunspell/en_US/";
base = path.resolve(base);
base = base + "/";
spell = new SpellCheck(base + 'en_US.aff', base + 'en_US.dic');
// If the hook is not currently streaming, req has already been fully buffered
@Marak
Marak / colorsHook.js
Last active August 29, 2015 14:23
hook.io microservice for adding colors to text
var _colors = ["random", "red", "green", "blue", "yellow", "cyan", "rainbow", "zalgo"];
module['exports'] = function colorsHook (hook) {
var colors = require('colors'),
color = hook.params.color;
var text = hook.params.text || "";
// if random color is selected, return a random color
@Marak
Marak / view.js
Last active August 29, 2015 14:21
hook.io microservice for using the view module
module['exports'] = function view (hook) {
var view = require('view');
var marak = 'https://raw.githubusercontent.com/Marak/marak.com/master/view';
var url = hook.req.headers['x-forwarded-url'];
view.create( { remote: marak } , function (err, v) {
if (err) {
return hook.res.end(err.message);
}
v.remote(url, function (err, result) {
if (err) {
@Marak
Marak / staticHook.js
Created May 19, 2015 19:31
hook.io microservice for serving static files from remote sources
module['exports'] = function staticHook (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
hook.debug(hook.req.method);
@Marak
Marak / faker.js
Last active August 29, 2015 14:20
hook.io microservice wrapper for faker
module['exports'] = function faker (hook) {
var faker = require('faker');
var params = hook.params;
var parts = params.property.split('.');
faker.locale = hook.params.locale;
var result = faker[parts[0]][parts[1]]();
hook.res.end(JSON.stringify(result, true, 2));