Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
jonschlinkert / permutations-with-max-depth.js
Last active Apr 14, 2019
Generate all permutations of an array. Alternative to the many variants of heap's algorithm I keep finding on the interweb. Every single algorithm I found produced incorrect results. This one is correct.
View permutations-with-max-depth.js
/**
* This variant takes a max depth as the second argument.
*/
const permutations = (value, max = value.length) => {
let depth = Math.min(max, value.length);
let results = [];
const permute = (queue = []) => {
if (queue.length === depth) {
View guide-to-contributing-to-enquirer.md

Guide to Contributing to Enquirer

Welcome!

Thanks for choosing to contribute to Enquirer! We're so happy that you're contributing to open source projects, and we're even happier that one of those projects is ours!

Teamwork

There is no faster, more effective way to improve a product than from the feedback from the first experience of a new user -- Jon Schlinkert

@jonschlinkert
jonschlinkert / async-engine.js
Last active Dec 15, 2018
PoC of an async template engine using native template literals and async-await. Response to https://twitter.com/doowb/status/1072688034485805058
View async-engine.js
const compile = (input, helpers, thisArg) => {
return async data => {
let ctx = { ...thisArg, ...data };
let keys = [];
let vals = [];
if (helpers) {
for (let key of Object.keys(helpers)) {
if (ctx[key] === void 0) {
ctx[key] = (...args) => helpers[key].call(ctx, ...args);
View monokai-extended.itermcolors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.13333329558372498</real>
View countdown.js
const countdown = (msgFn, fn, count = 3, interval = 500) => {
let timer = setInterval(() => {
process.stdout.write('\u001b[?25l');
process.stdout.write('\u001b[2K\r');
process.stdout.write(msgFn(count));
if (count-- === 0) {
process.stdout.write('\u001b[?25h');
process.stdout.write('\u001b[2K\r');
clearInterval(timer);
fn();
@jonschlinkert
jonschlinkert / benchmarks-starter.js
Last active Aug 19, 2018
Minimal code to create a benchmarks with terminal styling to show real-time progress while benchmarks are running.
View benchmarks-starter.js
const { Suite } = require('benchmark');
const argv = require('minimist')(process.argv.slice(2));
const cycle = (e, newline) => {
process.stdout.write('\u001b[G');
process.stdout.write(` ${e.target}` + (newline ? '\n' : ''));
};
function bench(name) {
const suite = new Suite()
@jonschlinkert
jonschlinkert / longest.js
Created Jun 13, 2018
Get the length of the longest item in an array of strings.
View longest.js
const longest = arr => arr.reduce((len, v) => Math.max(v.length, len), 0);
View assemble-next.js
(async function() {
const handlebars = require('handlebars');
const engine = require('./examples/support/engine');
const Assemble = require('./');
const app = new Assemble();
app.engine('hbs', engine(handlebars));
const pages = app.create('pages');
const layouts = app.create('layouts', { kind: 'layout' });
View collection-loader.js
const fs = require('fs');
const path = require('path');
const Collection = require('../lib/collection');
const collection = new Collection();
collection.use(loader());
const filter = file => file.extname === '.txt';
const contents = file => fs.readFileSync(file.path);
View public-reddit-usernames.js
module.exports = [
'014a',
'0x706272',
'13steinj',
'2bdb2',
'_3442',
'__crackers__',
'_selfishPersonReborn',
'a_redditor',
'Aceeri',
You can’t perform that action at this time.