Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active June 1, 2024 19:35
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.

Your First Block

To make things simple, we're going to make a semi-structured way to display a mailing address.

We're going to start with a file tree that looks like this:

address-block
  ├ blocks
  | ├ address.jsx
@officeofjane
officeofjane / .block
Last active May 13, 2021 19:34
US grid maps
license: mit
@d11wtq
d11wtq / docker-ssh-forward.bash
Created January 29, 2014 23:32
How to SSH agent forward into a docker container
docker run -rm -t -i -v $(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK ubuntu /bin/bash
@ircmaxell
ircmaxell / gist:4121166
Created November 20, 2012 21:12
Predictable Sequence Generator
<?php
class PseudoRandomGenerator {
protected $state = null;
public function __construct($seed) {
$this->state = $seed;
}
public function next($max) {
$bits = (int) floor(log($max, 2) + 1);
$bytes = (int) max(ceil($bits / 8), 1);
@ircmaxell
ircmaxell / dumpToJSON.php
Created April 8, 2012 04:51
PHP JSON dump
<?php
function dumpToJson($var, $encode = true, array $recursionCache = array()) {
$tmp = serialize($var);
if (isset($recursionCache[$tmp])) {
return 'recursion';
}
$recursionCache[$tmp] = true;
$result = array();
$result['type'] = gettype($var);
@ramnathv
ramnathv / gh-pages.md
Created March 28, 2012 15:37
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" &gt; index.html