Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active November 17, 2024 22: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.
@hediet
hediet / main.md
Last active November 13, 2024 17:23
Proof that TypeScript's Type System is Turing Complete
type StringBool = "true"|"false";


interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };

type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@lavelle
lavelle / convert-date-components.js
Last active February 15, 2018 22:13
Lodash Art Gallery
// Author: Giles
const datetimeComponents = _(matchResults).tail().map(_.toNumber).value();
// Better than
var datetimeComponents = _.map(
matchResults.slice(1, 6), // skip the matched result
function(component) {
return parseInt(component, 10);
}
);
@Zulko
Zulko / 3D_piano_from_midi.py
Last active April 9, 2024 05:51
Turn a piano MIDI file into a basic 3D animated piano video.
"""
Turn a piano MIDI file into a basic 3D animated piano video.
See the result here:
I am leaving it as a script because it is not tested on enough MIDI files yet.
Zulko 2014
This script is released under a Public Domain (Creative Commons 0) licence.
@ingdir
ingdir / gist:0b211b9253c376f9cfa5
Last active December 3, 2023 11:47
BEM Cheatsheet

BEM Cheatsheet

BLOCK

Block encapsulates a standalone entity that is meaningful on its own.

While blocks can be nested and interact with each other, semantically they remain equal; there is no precedence or hierarchy.

Holistic entities without DOM representation (such as controllers or models) can be blocks as well.

@lavelle
lavelle / git-cheat.md
Last active December 19, 2015 10:59
All the useful Git commands I've found (mostly from StackOverflow), in one convenient reference.

Branch from an old commit

git branch branchname ref

where ref is either a sha (abcd123) or a pointer HEAD@{5}

Undo a commit

git reset HEAD~1
@leommoore
leommoore / node_file_paths.markdown
Last active August 19, 2024 13:02
Node - File Paths

#Node - File Paths

##File Paths Node has a path module which can be used to manipulate paths.

###Normalizing Paths Paths can be stored in different ways and it is neccessary to ensure that the path is standardized.

var path = require('path');
path.normalize('/foo/bar//baz/asdf/quux/..');
@Nurdok
Nurdok / python_conversion.md
Last active July 11, 2024 15:00
Python Conversion

Python Number Conversion Chart

From To Expression
@hijonathan
hijonathan / instructions.markdown
Created October 4, 2012 19:58
Steps to transfer Chrome Custom Search Engines to Alfred

Step 0: Quit Chrome

Step 1: Get a dump of your search engines

> pwd
/Users/jonathankim/Desktop

> sqlite3 ~/Library/Application\ Support/Google/Chrome/Default/Web\ Data
sqlite3> .output chrome_export.sql

sqlite3> .dump keywords