Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active November 1, 2024 20:38
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.
@perrygeo
perrygeo / base64_padding.md
Last active October 29, 2024 09:51
Avoiding TypeError: Incorrect padding with Python's base64 encoding

Avoiding padding errors with Python's base64 encoding

>>> import base64
>>> data = '{"u": "test"}'
>>> code = base64.b64encode(data)
>>> code
'eyJ1IjogInRlc3QifQ=='
@magnetikonline
magnetikonline / README.md
Last active October 31, 2024 17:00
Bash string manipulation cheatsheet.

Bash string manipulation cheatsheet

Assignment
Assign value to variable if variable is not already set, value is returned.

Combine with a : no-op to discard/ignore return value.
${variable="value"}
: ${variable="value"}
@joar
joar / gotcha.rst
Created April 5, 2013 21:42
Python pytest virtualenv gotcha

I encountered this issue:

(mediagoblin)➜  ~VIRTUAL_ENV git:(master) ✗ ./runtests.sh                                                                         belz
Using ./bin/py.test
+ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests
+ exec ./bin/py.test ./mediagoblin/tests --boxed
/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/oldinterpret.py:3: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
  from compiler import parse, ast, pycodegen