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 / 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 / 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()
@jonschlinkert
jonschlinkert / longest.js
Created June 13, 2018 14:49
Get the length of the longest item in an array of strings.
const longest = arr => arr.reduce((len, v) => Math.max(v.length, len), 0);

(This is an excerpt from a much longer paper I'm writing about code quality and maintaining FOSS projects.)

FOSS dependency scoring

In an effort to improve the quality of search results on sites like https://npmjs.com, there has been more and more discussion about factoring in the ranking/scoring of dependencies to influence search results. The general idea is that a library should be ranked not only on its own merits, but dependencies should weigh into the score as well.

I’m not sure what my opinion is on this yet. I was initially in favor of this, and still might be, but this document is a summary of some things that crossed my mind about the topic.

Should dependencies weigh into the search score for a library?

In an effort to improve the quality of search results on sites like https://npmjs.com, there has been more and more discussion about factoring in the ranking/scoring of dependencies to influence search results. The general idea is that a library should be ranked not only on its own merits, but dependencies should weigh into the score as well.

I’m not sure what my opinion is on this yet. I was initially in favor of this, and still might be, but this document is a summary of some things that crossed my mind about the topic.

Should dependencies weigh into the search score for a library?

  1. Some very popular libraries on npm are very poorly written, but solve problems that are sufficiently complex that few alternatives exist. From a scoring standpoint, this alone wouldn't matter because the law of averages would even it out. However...
  2. It's possible for developers to write high quality, stable code on top of lesser quality libraries.
  3. The better quality the code, and more knowledgable the maintainer
@jonschlinkert
jonschlinkert / strategic-control-point-index.md
Last active February 3, 2018 05:59
This is inspired by the book "The Profit Zone". It's been something like 20 years since I read that book, but I've used this index to guide many of the business and investment decisions I've made since that time.

Strategic control point index

Businesses with high strategic control have more sustainable profitability, stronger competitive advantage, and higher valuations. Many business hit multiple strategic control points, and it's possible for businesses to combine multiple control points, even low control, to achieve a much greater level of strategic control in aggregate.

High strategic control:

  • 10 — Monopoly, patent, own the standard
  • 9 — Control of value chain
  • 8 — Control of supply, string of superdominant positions
  • 7 — Control of distribution, owning the customer relationship, owning customer information flow

Code project conversion funnel

A page-rank-like approach to scoring code libraries for quality and dependability. This is a quick-pass attempt at translating metrics we have readily available in the code community into a conversion funnel that might be familiar to marketers.

Conversion funnel equivalent Metric Description
awareness github stars Equivalent of "likes", but only slightly better than visits (it's possible to have many stars per one visitor). This metric only proves awareness, no causal relationship to actual interest, "real" popularity, code quality, trust, intent to use, or advancement in the conversion funnel.
interest dependents Dependants are a sign of awareness and commitment from the authors that chose to depend on the library, but no correlation to actual usage, commitment from upstream implementors and users to use the dependent, and is just as likely to represent herd mentality or a reaction to recent awareness as it is to be a p

Cheatsheet

Move cursor

command description
ctrl+a Move cursor to the start of the line
ctrl+e Move cursor to the end of the line
or ctrl+b Move cursor back one character
▶ or ctrl+f Move cursor forward one character
@jonschlinkert
jonschlinkert / open-iterm-from-finder.md
Last active May 24, 2022 01:33
Add an icon to your finder toolbar to open iTerm in the current folder.

Open iTerm from finder

The code and instructions in this gist are from http://peterdowns.com/posts/open-iterm-finder-service.html. I've had to do this a few times and wanted to distill it the basics.

  1. Open Automator
  2. Create an Application
  3. Choose Actions > Utilities > Run Applescript
  4. Paste the contents of open_in_iterm.app into the window.
  5. Save the script somewhere convenient
  6. Find the script, then drag the script onto the Finder window while holding the command key (or in Yosemite, the command + option keys)