Skip to content

Instantly share code, notes, and snippets.

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)
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')
'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]
@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))
// 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
Created July 2, 2016 00:52
requirebin sketch
const pull = require('pull-stream')
const Notify = require('pull-notify')
const notify = Notify()
pull(notify.listen(), pull.drain(console.log))
notify('hello', 'world')
notify.end()
@toddself
toddself / index.js
Last active June 30, 2016 00:09
requirebin sketch
const choo = require('choo')
// app 1
const app1 = choo()
app1.model({
state: {
data: 'app1',
},
reducers: {
1 1/2 cups cake flour
1/4 sugar
1/2 tsp salt
1/2 tsp baking soda
1/2 tsp baking powder
3/4 whole milk
3/4 whole milk yogurt
2 egg whites
4 tbls butter, melted
shot of vanilla extract
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var history = require('sheet-router/history');
var sheetRouter = require('sheet-router');
var document = require('global/document');
var href = require('sheet-router/href');
var hash = require('sheet-router/hash');
var hashMatch = require('hash-match');
var sendAction = require('send-action');
var mutate = require('xtend/mutable');
var assert = require('assert');
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]
Object.defineProperty(base, `_${key}`, {writable: true, value: prop})
if (typeof prop === 'function') {