Skip to content

Instantly share code, notes, and snippets.

View binki's full-sized avatar

Nathan Phillip Brink binki

View GitHub Profile
@binki
binki / output.txt
Created September 23, 2017 21:30
to skip a named subdir
$ ./skipDir.sh
/a/b/c is permitted
/e/f/blah is banned
@binki
binki / output.txt
Created August 22, 2017 04:53
validators ignore undefined (as documented)
ohnob@DESKTOP-A4G2C0J MSYS ~/repos/mongoose-validators-hard-to-use
$ node --version
v6.11.1
ohnob@DESKTOP-A4G2C0J MSYS ~/repos/mongoose-validators-hard-to-use
$ npm list mongoose
[email protected] C:\Users\ohnob\repos\mongoose-validators-hard-to-use
`-- [email protected] extraneous
npm ERR! extraneous: [email protected] C:\Users\ohnob\repos\mongoose-validators-hard-to-use\node_modules\mongoose
@binki
binki / index.js
Created August 22, 2017 04:48
impossible to require null or disallow undefined
const assert = require('assert');
const mongoose = require('mongoose');
const ThingSchema = new mongoose.Schema({
// https://stackoverflow.com/a/44336895/429091, doesn’t support
// subdocuments.
undefinedDisallowed: {
type: String,
required: function () {
return this.undefinedDisallowed === undefined;
@binki
binki / index.test.js
Created August 11, 2017 02:51
Mongoose way to get array to default to null
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test-mongoose-default-null');
describe('mongoose', function () {
for (const {id, buildSchema, } of [
{
id: 'FooNull',
buildSchema: () => new mongoose.Schema({
const fs = require('fs');
module.exports = function writeFileSafely(tempPath, destPath, contents, callback) {
fs.open(tempPath, 'w', function (err, fd) {
if (err) {
callback(err);
} else {
fs.createWriteStream(null, {
fd: fd,
autoClose: false,
}).on('error', function (err) {
@binki
binki / shell-transcript.txt
Created July 24, 2017 14:28
“a” is an invalid decimal value
ohnobinki@gibby ~ $ echo '<x>&#a;</x>' | xmllint -
-:1: parser error : CharRef: invalid decimal value
<x>&#a;</x>
^
-:1: parser error : xmlParseCharRef: invalid xmlChar value 0
<x>&#a;</x>
^
@binki
binki / gist:78301b60663b0aba627cde22e67a477b
Last active July 19, 2017 21:18
Demonstration of &#xd;
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> LoadAssembly("System.Xml.Linq");
csharp> using System.Xml.Linq;
csharp> (int)XElement.Parse("<x xml:space=\"preserve\">&#xd;</x>").Value[0]
13
csharp> (int)XElement.Parse("<x xml:space=\"preserve\">&#13;</x>").Value[0]
13
@binki
binki / index.js
Last active July 12, 2017 18:10
Subtle behavior change in primitive-enum with Enum.defaultArrayTransform
#!/usr/bin/env node
if (process.env.different === '1') {
require('./mod2');
}
const mod1 = require('./mod1');
const mod2 = require('./mod2');
console.log(mod1.enum1+'');
console.log(mod2.enum2+'');
@binki
binki / httpd-scgi-autolaunch.md
Created May 27, 2017 16:45
Convention for launching SCGI applications and managing lifetimes

Status

Incomplete. I just posted to save my progress, probably completely wrong still…

Introduction

CGI (Common Gateway Interface) has been around for a long time and is considered a standard for server-side dynamic content generation. CGI provides a mapping from URI to a script stored on a filesystem and a protocol for activating the script, sending the client’s request, and returning the script’s response to the client. CGI communicates headers and request information to the script by setting well known environment variables and executes it to activate it. This results in different types of overhead: concurrent requests require multiple processes and each request requires a fork(), exec(), and quite likely a script interpreter which may need to consume many resources before being able to respond to the request.

SCGI: A Simple Common Gateway Interface alternative
Neil Schemenauer <[email protected]>
2008-06-23
1. Introduction
The SCGI protocol is a replacement for the Common Gateway Interface
(CGI) protocol. It is a standard for applications to interface with
HTTP servers. It is similar to FastCGI but is designed to be easier
to implement.