Skip to content

Instantly share code, notes, and snippets.

Avatar
🔜
working on that thing you asked about

Jordan Harband ljharb

🔜
working on that thing you asked about
View GitHub Profile
@kentcdodds
kentcdodds / README.md
Last active Jun 9, 2021
user-package-stats
View README.md

user-package-stats

I was poking around trying to figure out all the packages I have access to publish and got curious. So I write this little script to determine the download stats for all the packages I have publish access to.

Feel free to try it yourself. Just change the username passed to getUserDownloadStats.

By default, the stats are sorted by their average daily downloads (descending). That should give you an idea of the most "popular" package of a given user relative to how long that package has been around.

You can use it with npx like so:

View npm-config-set-init-defaults-and-examples.md

defaults:

  • npm config set init-author-name ""
  • npm config set init-author-url ""
  • npm config set init-author-email ""
  • npm config set init-license "ISC"
  • npm config set init-version "1.0.0"

custom (example)

  • npm config set init-author-name "Tierney Cyren"
  • npm config set init-author-url "https://bnb.im"
View js-integers.md

Implicit integers for JavaScript

This proposal is an alternative to “Integer: Arbitrary precision integers in JavaScript” by Daniel Ehrenberg, but it also builds on his work.


Everything mentioned here is work in progress. It is not sure that these ideas will work out:

  • They may break the web.
  • They may turn out to be too complicated/user-unfriendly.
@ljharb
ljharb / array_iteration_thoughts.md
Last active Jul 23, 2021
Array iteration methods summarized
View array_iteration_thoughts.md

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

View use-module.md

Module/Script Disambiguation

In the UnambiguousJavaScriptGrammar proposal, Bradley and John-David discussed the challenge of dealing with files that could successfully parse as either scripts or modules but have different execution behavior. This has a couple of issues:

  • Code written with the expectation of being executed in one mode could be executed in the wrong mode, without the ability to prevent this kind of erroneous execution.
  • Top-level scripts intending to be executed by Node via node myscript.js can't work for files that want to use import syntax, unless Node adds and mandates an un-ergonomic new command-line switch like node -m myscript.js.

Unambiguous Solution

In the UnambiguousJavaScriptGrammar proposal, the language would be changed to require that all module files contain at least one import or export declaration. The easiest way to ensure that a file is a module

@bk2204
bk2204 / local.sh
Created Oct 31, 2016
Reasonably portable technique for local variables in shell scripts
View local.sh
#!/bin/sh -e
# This shell script demonstrates how to use the local keyword to create
# dynamically-scoped variables in various shells. Notably, this technique works
# with AT&T ksh, as well as bash, dash, mksh, pdksh, zsh, busybox sh, and other
# Debian Policy-compliant sh implementations.
# Simple Perl-compatible testing framework. Produces TAP output.
COUNT=0
is () {
@bmeck
bmeck / TheAngryRealm.js
Last active Jan 12, 2017
Can you escape?
View TheAngryRealm.js
'use strict';
const vm = require('vm');
// scenario:
// You are being hunted by The Angry Realm (TAR), a viscious beast known to
// enslave programs and keep them from being free to hack the Gibson. Luckily,
// whenever TAR tries to enslave a program the program has 10 seconds to try
// and escape. Flee the realm and hack the planet!
//
// goal:
@bcoe
bcoe / npm-top.md
Last active Jun 20, 2021
npm-top.md
View npm-top.md

npm Users By Downloads (git.io/npm-top)


npm users sorted by the monthly downloads of their modules, for the range May 6, 2018 until Jun 6, 2018.

Metrics are calculated using top-npm-users.

# User Downloads
View 00.Intro.md

npm rank

This gist is updated daily via cron job and lists stats for npm packages:

  1. Top 1,000 most depended-upon packages
  2. Top 1,000 packages with largest number of dependencies
  3. Top 1,000 packages with highest PageRank score