Skip to content

Instantly share code, notes, and snippets.

@tswaters
tswaters / maze.js
Last active September 22, 2018 20:56
maze generation in terminal
'use strict'
const readline = require('readline')
const NORTH = 0b1000
const SOUTH = 0b0100
const EAST = 0b0010
const WEST = 0b0001
const ALL = 0b1111
@tswaters
tswaters / tag-npm-versions.sh
Created February 13, 2018 16:54
Add tags to git repo based on npm view output
#!/usr/bin/env bash
for version in $(npm view $1 --json | jq '.versions[]' -c -r); do
sha=$(npm view $1@$version --json | jq '.gitHead' -c -r)
echo Tagging $sha as v$version
git tag -a "v$version" $sha -m "Release v$version"
done
@tswaters
tswaters / instructions.md
Last active November 29, 2017 02:54
Using Seneca-Web with request$ and response$

Using Seneca-Web with request$ and response$

node web-host.js

In another terminal

node web-client.js
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\tyler\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'un',
1 verbose cli 'lodash' ]
2 info using npm@5.3.0
3 info using node@v8.2.1
4 verbose npm-session 183b62c0437ca1ee
5 silly install loadCurrentTree
6 silly install readLocalPackageData
@tswaters
tswaters / index.js
Last active April 6, 2017 20:42
translating a provided date to a given timezone with moment-timezone
var moment = require('moment-timezone')
console.log(midnightPst('2017-12-31T13:59:59.999Z')) // provided as 11:59 HAST
console.log(midnightPst('2018-01-01T07:59:59.999Z')) // provided as 11:59 PST
console.log(midnightPst('2018-01-01T04:59:59.999Z')) // provided as 11:59 EST
console.log(midnightPst('2018-12-31T23:59:59.999Z')) // provided as 11:59 UTC
// east of GMT doesn't work.
console.log(midnightPst('2018-01-01T08:59:59.999Z')) // provided as 11:59 JST
@tswaters
tswaters / browserify-virtual-file.md
Created September 5, 2016 02:05
Trying to mimic virtual files in browserify

Let's say you have a string that you want to include in browserify. This needs to be identified by a path so you can require it later, but a file does not exist at that path's location.

You can pass streams to browserify, and streams can include arbitrary strings... the key is ignoreMissing:true which will dutifully ignore any required files that aren't actually on the file system.

Now, for it to actually come through as something you can require, it needs to be exposed as an explicit string. While this works, it means you can only reference it by this name... see with-expose.js

The main problem of course is that mechanisms for directory loading won't work like they do in a normal commonjs fashion.

i.e., consider the following was used for ./requires:

@tswaters
tswaters / math-client.log
Created April 21, 2016 16:13
Seneca errors using math client/service
2016-04-21T16:07:40.563Z 6ti4fu88u7oq/1461254860543/16252/- INFO hello Seneca/2.0.0/6ti4fu88u7oq/1461254860543/16252/-
2016-04-21T16:07:40.581Z 6ti4fu88u7oq/1461254860543/16252/- DEBUG options { log: { map: [ { level: 'all', handler: { [Function: print] routestr: '{ level: \'fatal\' }' } } ] }, tag: '-', idlen: 12, timeout: 11111, default_plugins: { basic: true, cluster: true, 'mem-store': true, repl: true, transport: true, web: true }, debug: { fragile: false, undead: false, print: { options: false }, act_caller: false, short_logs: false, callpoint: false }, strict: { result: true, fixedargs: true, add: false, find: true, maxloop: 11 }, actcache: { active: true, size: 11111 }, trace: { act: false, stack: false, unknown: 'warn' }, stats: { size: 1024, interval: 60000, running: false }, deathdelay: 11111, admin: { local: false, prefix: '/admin' }, plugin: {}, internal: { close_s
@tswaters
tswaters / stubbing-classes.md
Last active April 15, 2024 10:50
stubbing classes?

Stubbing Classes and their Constructors in Native ES6

It's getting to that point. All the major evergreen browsers have (mostly) functional class keyword. But what does this mean for unit tests and the ability to stub constructors? In short, the answer is 'no'.

Many will tell you that es6 classes are just sugar coated es5 functions with prototypal inheritance setup. Mostly true - but there are two considerations that make testing more difficult:

  • super is a magical keyword that calls the same method on the parent class. in cases with methods, easy enough to stub those, sinon.stub(parent.prototype, 'whatever') -- for super itself, there is no way to stub out the constructor call... normally not a huge deal, but...

  • classes are not added to the global scope. where once you could call sinon.stub(global, 'SomeFunction'), sinon.stub(global, 'SomeClass') (or under window in the browser), this will throw an error.

function transformAttributes (stats) {
attrs = parseInt(attrs, 8);
var others = attrs & 7;
var user = attrs >> 3 & 7;
var owner = attrs >> 6 & 7;
return [
owner & 4 ? 'r' : '-',
owner & 2 ? 'w' : '-',
owner & 1 ? 'x' : '-',

setting up nodejs debugging on debian

$ npm insall -g node-inspector

$ node-inspector 
Node Inspector v0.12.2
Visit http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 to start debugging.