Skip to content

Instantly share code, notes, and snippets.

Wes Todd wesleytodd

View GitHub Profile
View channel.js
'use strict'
const SUBS = Symbol('subs')
const DONE = Symbol('done')
module.exports = class Channel {
constructor () {
this[SUBS] = []
}
subscribe (evt) {
@wesleytodd
wesleytodd / openapi.js
Created Dec 7, 2018
Proposal for an open api package for express
View openapi.js
'use strict'
const app = require('express')()
const openapi = require('@express/openapi')
const oapi = openapi('/api/swagger.json', {
info: {
title: 'Test swagger',
description: 'testing the express swagger api',
version: '0.0.1'
},
@wesleytodd
wesleytodd / middleware.js
Last active Jun 25, 2018
A simple state container and express middlware wrapper (redux like)
View middleware.js
const React = require('react')
const ReactDOM = require('react-dom')
const createStore = require('./state-container')
module.exports = storeMiddleware
function storeMiddleware (reducer, initialState, Component) {
let _c = Component
if (_c && !_c.hasOwnProperty('$$typeof')) {
_c = React.createFactory(Component)
}
@wesleytodd
wesleytodd / error-tuple.js
Last active Feb 6, 2018
Error handling with `async`/`await`
View error-tuple.js
const operations = {
op1: () => Promise.resolve([null, 'foo']),
op2: (res) => Promise.resolve([new Error(`Ugh, an error: ${res}`)]),
op3: (res) => Promise.resolve([null, 'op3 ' + res])
};
module.exports = async function operation () {
let [err1, res1] = await operations.op1();
if (err1) {
console.error('error 1', err1);
View refcompat.js
var oldRefs = parseInt(React.version.split('.')[0], 10) < 14;
function refCompatibilitySet (refName) {
if (oldRefs) {
return refName;
}
return function (ref) {
this['__ref' + refName] = ref;
};
}
@wesleytodd
wesleytodd / camera.sh
Last active Jan 10, 2019
Record a raspberry pi camera to an hls stream
View camera.sh
#!/bin/bash
# record from the camera at 30fps and 24kbps
raspivid -o - -t 0 -fps 30 -b 24000000 -ih -n -pts | \
# pipe to ffmpeg, create a silent audio stream and segment to 10s hls segments
ffmpeg -y -re -f lavfi -i anullsrc=r=11515:cl=mono -thread_queue_size 512 -probesize 10000000 -f h264 -i - \
-acodec aac -strict experimental -c:v copy -f ssegment -segment_time 10 -segment_format mpegts \
-segment_list "seg/test.m3u8" -segment_list_size 720 -segment_list_flags live -segment_list_type m3u8 "seg/%08d.ts"
@wesleytodd
wesleytodd / readme.md
Created Dec 30, 2016
DAT project idea
View readme.md

So here is my plan for a "own your data" version of a security cam system:

  1. Write a little app which interacts with my razpi camera, publish it over dat
  2. Setup multiple razpi's to watch for changes on the dat, and pull updates/restart
  3. When it runs it will create a dat to dump the images/video in
  4. (Second)? app which you can point at any archives from the (first)? app (maybe just one app with all of this?)
  5. This app will monitor for motion, notify you, and provide a web ui for accessing the feeds
  6. The feeds will be streamable video over dat to the browser
View comment.md

In response to https://github.com/expressjs/express/issues/3161#issuecomment-269687403


I want to apologize in advance for my unsolicited comment/advice here ;)

I would help, but there is no way I am downloading a zip of someones code posted like this, and I would caution anyone else I know from doing the same. I would reccomend posting the relavent code as a github comment in the future. For example, in this case:

My direcroties look like:

View map.js
var map = require('lodash.map');
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log('Lodash: ' + time(lodashMap, 1000));
console.log('Native: ' + time(nativeMap, 1000));
console.log('Loop: ' + time(loop, 1000));
function lodashMap () {
return map(data, function (i) {
return i + 1;
@wesleytodd
wesleytodd / a-solution.md
Created Aug 25, 2016
Thoughts on module level debugging
View a-solution.md
var module = require('module');
var logger = require('my-logger');

process.on('debug-log', function (log) {
  logger.debug(log);
});
You can’t perform that action at this time.