Skip to content

Instantly share code, notes, and snippets.

View binki's full-sized avatar

Nathan Phillip Brink binki

View GitHub Profile
@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({
@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 / 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 / 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 / Program.cs
Created October 13, 2017 17:08
disposing IEnumerator not allowed
using System.Collections;
class Program
{
static void Main(string[] args)
{
IEnumerable enumerable = new[]
{
"a",
"b",
gcc -Wall -o cForLoop cForLoop.c

Consider this block-level code:

var test = true;

Consider the test variable. It does not worry about clothes or food. Yet it holds such beautiful truth.

@binki
binki / output.txt
Created October 23, 2017 15:48
mongo error when passing connection URL to connect()
sam ~ # mongo --nodb ~/.mongo-do-auth.js ~/s2.js
MongoDB shell version: 2.6.12
loading file: /root/.mongo-do-auth.js
2017-10-23T15:47:53.636+0000 Error: Invalid port number "asdf123@localhost" in connection string "mongodb://root:asdf123@localhost/admin" at src/mongo/shell/mongo.js:135
failed to load: /root/.mongo-do-auth.js
interface IParent
{
void DoParentThings();
}
interface IChild : IParent
{
void DoChildThings();
}
class Child : object, IChild
{
using System;
class Program
{
static void Main()
{
var b = new Base();
b.DoSomething();
// The answer is 42!