Skip to content

Instantly share code, notes, and snippets.

var api = foo
api.foo = 1
api.bar = 2
export default api
Object.assign(foo, someThings)
export default foo
array.forEach(item => {
bar[item.key] = item.value
@mhart
mhart / activityStore.js
Created April 7, 2017 16:05
One way to manage React global state with EventEmitters
const EventEmitter = require('events')
class ActivityStore extends EventEmitter {
constructor() {
this.state = 'stopped' // Whether you need this or not...?
}
start() {
this.state = 'started'
this.emit('started', this.state)
}
<!doctype html>
<html lang="en">
<!-- Example HTML file for AWS Proxy Resource tutorial at: https://aws.amazon.com/blogs/compute/authorizing-access-through-a-proxy-resource-to-amazon-api-gateway-and-aws-lambda-using-amazon-cognito-user-pools/ -->
<!-- Fill out your UserPoolId, ClientId and apiGatewayEndpoint in JS further below -->
<!-- Then serve locally with a static file server, such as `python -m SimpleHTTPServer` and open http://localhost:8000 -->
<head>
<meta charset="utf-8">
@mhart
mhart / .block
Last active September 30, 2016 00:33 — forked from mbostock/.block
Blocks
license: gpl-3.0
@mhart
mhart / splitStream.js
Last active September 12, 2016 00:29
Split stream for Node.js >= 4.x
var stream = require('stream')
module.exports = split
function split(delim, emitTrailingIfEmpty) {
delim = delim || new Buffer('\n')
var trailing, delimLen = delim.length
return new stream.Transform({
readableObjectMode: true,
transform: function(chunk, enc, cb) {
var AWS = require('aws-sdk')
var dynamo = new AWS.DynamoDB({endpoint: 'http://localhost:4567'})
var params = {
AttributeDefinitions: [ // required
{
AttributeName: 'test_id', // required
AttributeType: 'N' // required
}, {
@mhart
mhart / gist:e182beaecab4c9224b1d
Created September 8, 2015 19:16
Trying to install native modules in Node.js v4.0.0-rc.5
/ # npm install hiredis
npm WARN engine [email protected]: wanted: {"node":">= 0.8.0"} (current: {"node":"4.0.0-pre","npm":"2.14.2"})
> [email protected] install /node_modules/hiredis
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack at install (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:66:16)
gyp ERR! stack at Object.self.commands.(anonymous function) [as install] (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:66:37)
@mhart
mhart / csp.js
Last active March 15, 2017 23:10 — forked from amasad/csp.js
var spawn = require('child_process').spawn;
var csp = require('js-csp');
class Math {
constructor(readyCallback) {
this._readyCallback = readyCallback;
this._worker = spawn('6to5-node', ['worker.js']);
this._worker.stderr.pipe(process.stderr);
this._reqChan = csp.chan();
@mhart
mhart / awslambda
Last active April 14, 2019 15:38
node_modules/awslambda
#!/usr/bin/env node
var path = require('path')
var fs = require('fs')
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
require(lib + '/awslambda.js').start_runtime();
var util = require('util')
var Readable = require('stream').Readable
var request = require('request')
var async = require('async')
function PagingFetchStream(opts) {
Readable.call(this, {objectMode: true})
opts = opts || {}
this.getIdsUrl = opts.getIdsUrl