Skip to content

Instantly share code, notes, and snippets.

View wesleytodd's full-sized avatar

Wes Todd wesleytodd

View GitHub Profile
@wesleytodd
wesleytodd / framework.js
Last active September 18, 2020 15:55
Just noodling on the future Node.js and http
'use strict'
// Notice no certs, one thing I have thought
// for a long time is that frameworks should
// directly have support for spinning up with
// a cert if none was provided.
require('h3xt')()
.get('/', (req) => {
// Access the associated session
// req.session
'use strict'
const SUBS = Symbol('subs')
const DONE = Symbol('done')
module.exports = class Channel {
constructor () {
this[SUBS] = []
}
subscribe (evt) {
@wesleytodd
wesleytodd / openapi.js
Created December 7, 2018 21:29
Proposal for an open api package for express
'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 June 25, 2018 21:18
A simple state container and express middlware wrapper (redux like)
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 February 6, 2018 01:19
Error handling with `async`/`await`
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);
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 January 10, 2019 19:09
Record a raspberry pi camera to an hls stream
#!/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 December 30, 2016 19:52
DAT project idea

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
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 August 25, 2016 14:24
Thoughts on module level debugging
var module = require('module');
var logger = require('my-logger');

process.on('debug-log', function (log) {
  logger.debug(log);
});