Skip to content

Instantly share code, notes, and snippets.

View wbprice's full-sized avatar

Blaine Price wbprice

View GitHub Profile
'use strict';
const rn = require('random-number');
const program = require('commander');
const promptly = require('promptly');
program
.version('0.0.1')
.option('-d, --digit <n>', parseInt)
.parse(process.argv);
@wbprice
wbprice / table-extend.lua
Created December 20, 2017 21:02 — forked from cha55son/table-extend.lua
Simple function that will recursively extend lua tables.
function extend(table1, table2)
for k,v in pairs(table2) do
if (type(table1[k]) == 'table' and type(v) == 'table') then
extend(table1[k], v)
else
table1[k] = v
end
end
end
@wbprice
wbprice / azure-function-face-api-troubleshoot.md
Last active October 26, 2017 19:11
Azure Function Face API Troubleshooting

Hello! I'm trying to write an Azure Function using Serverless that makes requests to the Emotion API. I have a client that posts a Blob to an Azure function like so:

// client.js
return fetch(emotionUrl, { // Where emotionUrl is an endpoint for an Azure function app
    method: 'post',
    headers: {
        'Content-Type': 'application/octet-stream'
    },
    body: state.image // a blob from canvas.toBlob
@wbprice
wbprice / npm3-npm4.md
Created April 26, 2017 20:02
npm3-npm4

Upgrade from npm3 to npm4

npm4 is the first semver release since npm3. While npm3 introduced a number of breaking changes, upgrading to npm4 has a smaller impact on a given developer's day-to-day usage.

Breaking Changes

The below list is a list of breaking changes most likely to affect internal users:

 - `npm scripts` no longer prepends the path of the node executable used to run npm before running scripts. A `--scripts-prepend-node-path` option has been added to configure this behavior.
server.route({
method: 'POST',
path: settings.errorRoute,
handler: function handleRoute(request, reply) {
// We're only interested in handling application/json payloads.
if (request.mime !== 'application/json') {
return reply(boom.unsupportedMediaType());
}
return joi.validate(request && request.payload, internals.schema.payload, function(err) {
@wbprice
wbprice / broketv.md
Last active March 11, 2017 06:40
Broke TV

TV is broke

Make

Samsung

Model Number

HL50A650C1FXZA

Version

PK01

@wbprice
wbprice / wreck-timeout.js
Created December 9, 2016 15:50
timing out a request early if a connection isn't created soon enough
'use strict';
const Wreck = require('wreck');
const Boom = require('boom');
const connectionTimeout = 10;
const req = Wreck.request('GET', 'http://google.com/', {});
const connectionTimer = setTimeout(() => {
req.emit('error', Boom.gatewayTimeout('The other server took too long to respond'));
@wbprice
wbprice / class-instance-private-state.js
Last active November 23, 2016 18:47
Maintaining a private state in a class instance.
'use strict'
const assert = require('assert');
const _defaults = new WeakMap();
class Menu {
constructor(defaults = {}) {
_defaults.set(this, defaults);
}
@wbprice
wbprice / sqlJSONtoJSmodule.js
Last active November 7, 2016 17:16
Convert JSON dump from Postgres into a JS module
'use strict'
const fs = require('fs')
const path = require('path')
const file = process.argv[2]
/*
@name sqlJSONtoJSmodule
@usage
@wbprice
wbprice / get_struct_member_from_pointer.c
Created November 1, 2016 15:11
C - Accessing data from a struct, given an address in memory.
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
struct Person {
char *name;
int age;
int height;
int weight;
};