View babel-polyfill vs

The main difference is that polyfill works for all polyfills but must be installed as a production dependency. And you need to use import 'babel-polyfill'; to make it work. And it will pollute the global scope.

The transform-runtime provides many of the same features, but won't provide special functions like array.includes() or array.values(). So it's safer to use inside a library.

If you're building an app, you can use babel-polyfill. If you're building a library, make sure not to use babel-polyfill, and only the transform-runtime.

View boundIndex.js
// imagine you have an array like [E1,E2]
// normally an index into this array is just:
// 0 -> E1 (firstIndex)
// 1 -> E2 (lastIndex)
// now you want to be able to refer to positions in between the elements in positive and negative manner
// (this can be used for both insertion and also retrieval!)
// [ E1 E2 ]
// ^ ^ ^
// | | |
// 0 1 2
  1. Explicitly Linked Objects (Child points, parent pointers, next pointers, previous pointers... etc)
  2. Materialised Path or Dewey Encoding - Unix Filepaths
  3. Nested Sets or more general Nested Intervals
  4. Adjacency List or Closure Table (a closure table is just a secondary adjacency list)
  5. Matrix encodings (adjacency matrix and incidence matrix)
  6. Succinct encodings that take advantage of some sort of binary or mathematical pattern such that properties can be computed from the relative position or value. (like fenwick trees)
  7. Ondisk encodings (has to deal with slower random access, while with the advantage of block reads, so should be cache and seek friendly)

All encodings have different tradeoffs.

View Bidirectional Maps and their

Bidirectional maps has extra variants:

  1. Bimap (key to single value, value to single key)
  2. Multivalued Bimap (key to multiple values, value to single key)
  3. Multikeyed Bimap (key to single value, value to multiple keys)
  4. Multikeyed Multivalued Bimap (key to multiple values, value to multiple keys)

Note that making array keys or array values are totally orthogonal to this system. Any "claimed" multimap that uses array keys or array values has nothing to do with this idea.

Although you can definitely make the value an array, it just means that the array is considered the value, not the individual elements.

View DLinkedList.js
// @flow
class DLinkedList<T> {
_value : T;
_prev: DLinkedList<T>|void;
_next: DLinkedList<T>|void;
constructor (value: T, prev: DLinkedList<T>|void, next: DLinkedList<T>|void) {
this._value = value;
View permaProxy.js
// I just discovered this very powerful metaprogramming pattern.
// Suppose you have some internal object exists in a container.
// You want to return a reference to this internal object.
// But you know that once you return such a reference, that reference may
// become invalid, because the container may change its internal reference.
// At the same time we cannot just return the container, since we must
// return something that behaves (type-wise) like the internal object.
// To solve this problem, we create a proxy that looks and acts just like
// the internal object.
// However it maintains a persistent link that is mediated through the container.
import contextlib
import matplotlib.pyplot as plt
def figure(*args, **kwargs):
fig = plt.figure(*args, **kwargs)
yield fig
# use it like `with figure() as fig:`
View Matplotlib

Matplotlib Backends

Matplotlib is a plotting library. It relies on some backend to actually render the plots. The default backend is the agg backend. This backend only renders PNGs. On Jupyter notebooks the matplotlib backends are special as they are rendered to the browser. Generally you will not need to explicitly set the backend on a Jupyter notebook. This does introduce a discrepancy between code that runs in Jupyter and code that runs as a script natively in the Python interpreter. So you need to understand that the 2 environments are not the same


Found all these from nix-repl. Use builtins.fetchTarball for nixpkgs pinning!

View flow_optional_parameters.js
// undefined | string
function optionalF (optional?: string) {
console.log(typeof optional);
// undefined | null | string
function maybeF (maybe: ?string) {
console.log(typeof maybe);