Skip to content

Instantly share code, notes, and snippets.

View phryneas's full-sized avatar
🫖
418 I'm a teapot.

Lenz Weber-Tronic phryneas

🫖
418 I'm a teapot.
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active April 24, 2024 02:07
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@kentcdodds
kentcdodds / README.md
Last active March 30, 2024 11:39
user-package-stats

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:

@ClickerMonkey
ClickerMonkey / types.ts
Last active February 6, 2024 07:21
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
import React from "react";
import { Link } from "react-router-dom";
export function createResource(getPromise) {
let cache = {};
let inflight = {};
let errors = {};
function load(key) {
inflight[key] = getPromise(key)
@davidwhitney
davidwhitney / LICENSE.txt
Last active October 7, 2019 21:14
A Tiny Typescript mocking... um... library? class? That doesn't annoy me, and doesn't cause Typescript linters to get confused or fill your code up with :anys. The license is MIT.
Copyright (c) 2019 David Whitney
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@acutmore
acutmore / README.md
Last active January 21, 2024 20:30
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
  [
    ["push", N_1],         // 1
    ["push", False],       // 2
 ["peek", _], // 3
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);
@donaldpipowitch
donaldpipowitch / README.md
Last active March 10, 2019 08:03
Use @ts-check for custom ESLint rules

This is a very basic example which shows how you can create a simple ESLint rule with @ts-check support. This example features the rule and a test. The rule checks, if you pass an absolute URL to a history.push function or not.

If you want to use this rule in your ESLint configuration without publishing the rule there is a caveat. AFAIK you can't simply include the path to your rule in your .eslintrc.js (correct me if I'm wrong). You need to pass the directory of this rule to the CLI as --rulesdir "./path/to/rules" and if you use VS Code with the ESLint extension you need to set "eslint.options": { "rulePaths": ["./path/to/rules"] }, in your settings.json as well. Only then you can add the rule to your config:

module.exports = {
  // ...yourCurrentConfig,
  rules: {
    // ...yourCurrentConfig.rules,
 'some-rule': 'error'
@ottidmes
ottidmes / default.nix
Last active May 23, 2021 18:41
VS Code Live Share extension
# Baseed on previous attempts of others: https://github.com/NixOS/nixpkgs/issues/41189
{ lib, vscode-utils, autoPatchelfHook, bash, file, makeWrapper, dotnet-sdk
, curl, gcc, icu, libkrb5, libsecret, libunwind, libX11, lttng-ust, openssl, utillinux, zlib
, enableDiagnosticsWorkaround ? false, gccStdenv
}:
with lib;
let
# https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/linux#install-prerequisites-manually
@zimbatm
zimbatm / README.md
Created March 29, 2017 09:32
Nixpkgs pinning example

Nixpkgs pinning example

This is an example of how to pin the version of nixpkgs in a package repo. The goal is to improve reproducibility, make sure all the developers use the same version of nixpkgs and also allow to share binary caches.

Usage

Put all these files in a nixpkgs folder and then in other derivations, instead of import <nixpkgs> {} use import ./path/to/nixpkgs {}

Keeping nixpkgs up to date