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 / 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: ',',
'use strict';
const download = require('download');
/**
* Download all ballots
*/
const dl = async (baseurl, dest) => {
const pending = [];
@jonschlinkert
jonschlinkert / first-amendment.md
Last active November 16, 2021 17:36
Free speech is not without exceptions.

What Does Free Speech Mean?

Among other cherished values, the First Amendment protects freedom of speech. The U.S. Supreme Court often has struggled to determine what exactly constitutes protected speech. The following are examples of speech, both direct (words) and symbolic (actions), that the Court has decided are either entitled to First Amendment protections, or not.

Freedom of speech includes the right:

  • Not to speak (specifically, the right not to salute the flag). West Virginia Board of Education v. Barnette, 319 U.S. 624 (1943).
  • Of students to wear black armbands to school to protest a war (“Students do not shed their constitutional rights at the schoolhouse gate.”). Tinker v. Des Moines, 393 U.S. 503 (1969).
  • To use certain offensive words and phrases to convey political messages. Cohen v. California, 403 U.S. 15 (1971).
  • To contribute money (under certain circumstances) to political campaigns. Buckley v. Valeo, 424 U.S. 1 (1976).
@harveyconnor
harveyconnor / a-mongodb-replica-set-docker-compose-readme.md
Last active April 20, 2024 15:54
MongoDB Replica Set / docker-compose / mongoose transaction with persistent volume

This will guide you through setting up a replica set in a docker environment using.

  • Docker Compose
  • MongoDB Replica Sets
  • Mongoose
  • Mongoose Transactions

Thanks to https://gist.github.com/asoorm for helping with their docker-compose file!

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 / 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"]} ]}'