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 / Makefile
Created July 6, 2019 11:30 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
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;
@jonschlinkert
jonschlinkert / try-open.js
Last active June 25, 2019 20:47
Simple way to open a file or directory in a text editor or file manager, whichever is resolved first.
const cmds = { linux: 'xdg-open', win32: 'start', darwin: 'open' };
const open = cmds[process.platform];
const tryOpen = (dirname, editors = ['sublime', 'code', open]) => {
try {
cp.execSync([editors[0], dirname].join(' '));
console.log('Opening in ' + editors[0]);
} catch (err) {
if (editors.length === 0) {
throw new Error('Cannot find an editor to open');
@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';
@jonschlinkert
jonschlinkert / patchy-patch-patch.md
Created June 19, 2019 17:37
The very brief guide to getting rid of NPM's annoying "vulnerability" messages for packages that have been patched.

How to get the latest patch

This little guide describes what to do when:

  1. You see a vulnerability warning for a package, and
  2. The package has already been fixed, and a patch version has been released.

TLDR;

  1. Delete all lock files
@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) {

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 / repos.sh
Last active March 4, 2021 19:16
Clone all repos for the given user/org. Just replace <USERNAME> and run this in the command line.
curl -s https://api.github.com/users/<USERNAME>/repos?per_page=100 | ruby -rjson -e 'JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["clone_url"]} ]}'
@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);
<?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>