Skip to content

Instantly share code, notes, and snippets.

@mk-pmb
mk-pmb / univeil-chars.js
Last active October 4, 2016 23:33
List of characters I consider suspicious.
// nodejs -p 'require("univeil").rgx.nonprintGroups; // v0.1.8 +'
{ asciiControlChars_nonpr: /[\x00-\x1F\x7F]/g,
generalPunctuation_nonpr: /[\u2000-\u200F\u2028-\u202F\u205F-\u206F]/g,
latinSupplement_ctrl: /[\x80-\x9F]/g,
nbsp_nonpr: /\xA0/g,
privateUseArea_untrust: /[\uE000-\uF8FF]/g,
softHyphen_nonpr: /\xAD/g,
specials_nonpr: /[\uFFF9-\uFFFF]/g,
variationSelectors_nonpr: /[\uFE00-\uFE0F]/g,
/*jslint indent: 2, maxlen: 80, node: true */
/* -*- tab-width: 2 -*- */
'use strict';
var jsStringify = require('js-stringify'),
animals = { dog: '\uD83D\uDC15', cow: '\uD83D\uDC04' };
function charCodes(s) {
if (s.length === 1) { return '[' + s.charCodeAt(0).toString(16) + ']'; }
return s.replace(/[~-\uFFFF]/g, charCodes);
@mk-pmb
mk-pmb / dse-circ-6.1.0.js
Last active October 9, 2016 00:22
Node.js quiz! Can you guess the value?
'use strict';
var a = [], b = [a], eq = require('assert').deepStrictEqual;
function dse(x, y) {
var e;
try {
eq(x, y);
e = '===equal===';
} catch (err) {
/*jslint indent: 2, maxlen: 80, continue: false, unparam: false, node: true */
/* -*- tab-width: 2 -*- */
'use strict';
var async = require('async'), a, b, c, d, db;
db = {
get: function (num, hnd) { return hnd(null, num * 3); },
};
@mk-pmb
mk-pmb / test-amenities.js
Created November 10, 2016 13:05
An easy way to manage unit test amenities. Originally posted in https://github.com/stevemao/better-than-before/issues/6
const amenityDefs = {
dbConn: {
provide() { db.connect(login); },
dispose() { db.disconnect(); },
},
dummyTable: {
provide() { db.createTable('dummy', dummySchema); },
dispose() { db.dropTable('dummy'); },
},
dummyData: {
@mk-pmb
mk-pmb / getting-started.md
Created November 18, 2016 13:47 — forked from joepie91/getting-started.md
Getting started with Node.js

"How do I get started with Node?" is a commonly heard question in #Node.js. This gist is an attempt to compile some of the answers to that question. It's a perpetual work-in-progress.

And if this list didn't quite answer your questions, I'm available for tutoring and code review! A donation is also welcome :)

Setting expectations

Before you get started learning about JavaScript and Node.js, there's one very important article you need to read: Teach Yourself Programming in Ten Years.

Understand that it's going to take time to learn Node.js, just like it would take time to learn any other specialized topic - and that you're not going to learn effectively just by reading things, or following tutorials or courses. Get out there and build things! Experience is by far the most important part

@mk-pmb
mk-pmb / reserved_usernames.rb
Created November 28, 2016 18:35 — forked from caseyohara/reserved_usernames.rb
A list of reserved usernames to avoid vanity URL collision with resource paths
# A list of possible usernames to reserve to avoid
# vanity URL collision with resource paths
# It is a merged list of the recommendations from this Quora discussion:
# http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
# Country TLDs found here:
# http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains
# Languages found here:
@mk-pmb
mk-pmb / npm-debug.log
Created January 11, 2017 17:13
npm fails to deprecate generic-diff-context
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/usr/bin/npm',
1 verbose cli 'deprecate',
1 verbose cli '.',
1 verbose cli 'gdc.splitFinalLfPart duplicates the entire part even if it\'s huge' ]
2 info using npm@3.10.10
3 info using node@v6.9.3
4 silly mapToRegistry name null
5 verbose stack AssertionError: 'object' == 'string'
@mk-pmb
mk-pmb / npm@a08189f.log
Last active February 27, 2017 16:21
npm error log when trying to deprecate test-npm-synhl
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/mnt/…/nodejs/modules/npm/cli.js',
1 verbose cli 'deprecate',
1 verbose cli '.',
1 verbose cli 'string highlighting looks ok now' ]
2 info using npm@4.4.0
3 info using node@v6.10.0
4 silly mapToRegistry name null
5 verbose stack AssertionError: 'object' == 'string'
@mk-pmb
mk-pmb / 01_mbrs.js
Last active June 19, 2017 21:40
debug nodejs package nosync
'use strict';
var fs = require('fs'), assert = require('assert');
function enforceStdio(fd) {
if (fd !== 0) { throw new Error('Nope, use stdio, stdio rocks!'); }
}
function muchBetterRS(fd) {
if (muchBetterRS.useBackup) {
return muchBetterRS.backup.apply(fs, arguments);