Skip to content

Instantly share code, notes, and snippets.

View jonschlinkert's full-sized avatar
🤔
Trying to stay in the right branch of the wave function.

Jon Schlinkert jonschlinkert

🤔
Trying to stay in the right branch of the wave function.
View GitHub Profile
@jonschlinkert
jonschlinkert / assemblefile.md
Last active February 8, 2024 08:26
How to create a project with Assemble v0.6.0

assemblefile.js

This is a fairly complete assemblefile

Shows how to:

  • load templates
  • use tasks with plugins
  • use middleware
  • register helpers
@jonschlinkert
jonschlinkert / Preview in Chrome.sublime-build
Created January 3, 2013 20:55
Preview in Chrome.sublime-build, build system for Sublime Text 2 to preview current .html file in chrome with ctrl+b
{
"working_dir": "${project_path:${folder}}",
"cmd": ["C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "$file"],
"selector": "source.html"
}
@jonschlinkert
jonschlinkert / async-engine.js
Last active February 8, 2024 08:26
PoC of an async template engine using native template literals and async-await. Response to https://twitter.com/doowb/status/1072688034485805058
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);
@jonschlinkert
jonschlinkert / zip.js
Last active February 8, 2024 08:26
versatile JavaScript "zip" function. Works with objects, arrays, and yep - even strings.
function zip(a, b) {
var arr = [];
for (var key in a) arr.push([a[key], b[key]]);
return arr;
}
console.log(zip('foo', 'bar'));
//=> [ [ 'f', 'b' ], [ 'o', 'a' ], [ 'o', 'r' ] ]
console.log(zip(['a', 'b', 'c'], ['x', 'y', 'z']));
@jonschlinkert
jonschlinkert / permutations-with-max-depth.js
Last active February 8, 2024 08:26
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.
/**
* 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) {
'use strict';
const download = require('download');
/**
* Download all ballots
*/
const dl = async (baseurl, dest) => {
const pending = [];
@jonschlinkert
jonschlinkert / hash.js
Created May 18, 2021 06:25
Attempt at creating a Ruby-ish Hash using JavaScript's Proxy.
'use strict';
const values = new Map();
const getValues = hash => {
const v = values.get(hash) || new Map();
values.set(hash, v);
return v;
};
@jonschlinkert
jonschlinkert / parse-regex.js
Last active February 8, 2024 08:24
I created this to see how hard it would be to provide syntax highlighting for regex in the terminal. Try it out and see for yourself!
'use strict';
const colors = require('ansi-colors');
const chars = {
backslash: '\\',
backtick: '`',
caret: '^',
colon: ':',
comma: ',',
@jonschlinkert
jonschlinkert / fixture.txt
Created February 11, 2018 02:56
This is a test fixture for the gists library, do not delete.
Do not delete.
module.exports = [
'014a',
'0x706272',
'13steinj',
'2bdb2',
'_3442',
'__crackers__',
'_selfishPersonReborn',
'a_redditor',
'Aceeri',