Skip to content

Instantly share code, notes, and snippets.

// params:
// * data:object
// * [key:string]?:string - a key/value pair. both must be strings.
function reduceHash (data) {
return Object.keys(data).reduce((acc, k) => {
acc.push.apply(acc, [k, data[k]])
return acc
}, [])
}
@toddself
toddself / index.js
Last active August 31, 2016 16:22
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
const axios = require('axios')
axios.post('http://localhost:3000/login', {email: 'dev@scripto', pass: 'devpassword!'}).then((res) => {
const authToken = res.data.sessionId
const userUUID = res.data.key.split(':')[1]
const userURI = 'http://localhost:3000/user/'+userUUID
axios({method: 'get', headers: {'x-showrunner-auth': authToken}, url: userURI }).then((res) => console.log(res.data)).catch((err) => console.log(err))
}).catch((err) => console.log(err))
'use strict'
const EventEmitter = require('events')
function ComputedModel (props) {
const base = Object.create(new EventEmitter())
const keys = Object.keys(props)
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i]
const prop = props[key]
var http = require('http')
http.createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
})
res.write('retry: 10000\n')
res.write('event: connecttime\n')
var source = new EventSource('stream')
source.addEventListener('message', function (event) {
console.log('new message', event.data)
}, false)
// this is our custom event
source.addEventListener('connecttime', function (event) {
console.log('Connection was last established at: ' + event.data)
}, false)