Skip to content

Instantly share code, notes, and snippets.

View ljharb's full-sized avatar
🔜
working on that thing you asked about

Jordan Harband ljharb

🔜
working on that thing you asked about
View GitHub Profile
@krohrbaugh
krohrbaugh / query_limit.rb
Created June 3, 2015 21:37
RSpec Query Limit matcher
# Allows for assertions regarding number of queries executed.
#
# Usage:
# it "eager loads `#manager` association" do
# expect do
# employee = Employee.with_manager.find(employee_id)
# employee.manager
# end.to satisfy_query_limit(1)
# end
RSpec::Matchers.define :satisfy_query_limit do |expected|
@anvaka
anvaka / 00.Intro.md
Last active October 12, 2025 18:21
npm rank

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
@bcoe
bcoe / npm-top.md
Last active July 28, 2025 08:15
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
@michaelficarra
michaelficarra / append-template-tag.js
Created May 30, 2016 14:29
chainable template tag for joining a bunch of strings over many lines
function append(separator) {
return typeof separator === "string" ? appender(separator, "") : appender("", "").apply(this, arguments);
}
function appender(separator, s) {
return function tag(literalParts, ...computedParts) {
s += literalParts[0];
for (let i = 1; i < literalParts.length; ++i) {
s += computedParts[i - 1] + literalParts[i];
}
@dead-claudia
dead-claudia / composition-proposal.md
Last active June 2, 2017 17:36
Function Composition Strawman
@bmeck
bmeck / TheAngryRealm.js
Last active January 12, 2017 22:56
Can you escape?
'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:
@bk2204
bk2204 / local.sh
Created October 31, 2016 23:45
Reasonably portable technique for local variables in shell scripts
#!/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 () {

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

@ljharb
ljharb / array_iteration_thoughts.md
Last active October 2, 2025 14:17
Array iteration methods summarized

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

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.