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 / markdown-cheatsheet.md
Last active April 11, 2024 04:45
A better markdown cheatsheet.
{
// Editor
// Controls whether the editor shows CodeLens.
"diffEditor.codeLens": false,
// When enabled, the diff editor ignores changes in leading or trailing whitespace.
"diffEditor.ignoreTrimWhitespace": true,
// Timeout in milliseconds after which diff computation is cancelled. Use 0 for no timeout.
@jonschlinkert
jonschlinkert / examples.md
Last active March 4, 2024 04:40
Three files: examples.md, yaml-cheatsheet.md and yaml-cheatsheet.yml

adapted from this blog

# YAML
name: Jon
# YAML
object:
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);
(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' });
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 February 8, 2024 08:26
Minimal code to create a benchmarks with terminal styling to show real-time progress while benchmarks are running.
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()

Unary operators

(and the oddities of number evaluation in JavaScript)

Type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. [--wikipedia][wikipedia]


Unary operators, or "typeof +'foo' === huh?"

@jonschlinkert
jonschlinkert / open.js
Created June 25, 2019 20:31
Simple, cross-platform way to open the browser upon starting an app.
const cp = require('child_process');
const Koa = require('koa');
const app = new Koa();
const cmds = { linux: 'xdg-open', win32: 'start chrome', darwin: 'open' };
const open = cmds[process.platform];
const PORT = 3000;
// response
app.use(ctx => {
ctx.body = 'Hello Koa';
const replace = async (input, regex, replacer) => {
// we need to remove the 'g' flag, if defined, so that all replacements can be made
let flags = (regex.flags || '').replace('g', '');
let re = new RegExp(regex.source || regex, flags);
let index = 0;
let match;
while ((match = re.exec(input.slice(index)))) {
let value = await replacer(...match);
index += match.index;