Skip to content

Instantly share code, notes, and snippets.

View hastebrot's full-sized avatar

Benjamin Gudehus hastebrot

  • Freiheit.com
  • Hamburg, Germany
  • 16:37 (UTC +02:00)
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active April 19, 2024 10:56
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.
@rstacruz
rstacruz / README.md
Last active April 8, 2024 04:56
Setting up Jest with ESM

Setting up Jest with ESM

Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.

Method A: Native Node.js support

Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.

Install cross-env:

@dakom
dakom / ECS notes.md
Last active April 15, 2024 11:26
ECS with sparse array notes (EnTT style)

Intro

The below is a breakdown / bird's eye view of how a sparse-array backed ECS like EnTT or Shipyard works.

Please see the thanks and references at the bottom - without their help I would not have been able to share this breakdown with you... everything here is really just notes and rephrasing of what they've written already :)

Also, these notes do not cover archetype systems (like unity) nor adaptations of archetypes (like in Flecs). Though there's a couple comparative footnotes at the end.

Here we go!

@tbutts
tbutts / tmux-migrate-options.py
Last active February 29, 2024 08:11
For tmux configs: Merge deprecated/removed -fg, -bg, and -attr options into the -style option
#!/usr/bin/env python
# vim: set fileencoding=utf-8
#
# USAGE:
# Back up your tmux old config, run the script and redirect stdout to your conf
# file. Example:
#
# $ cp ~/.tmux.conf ~/.tmux.conf.orig
# $ python ./tmux-migrate-options.py ~/.tmux.conf.orig > ~/.tmux.conf
#
@tmeasday
tmeasday / component.examples.md
Last active November 28, 2019 14:03
Storybook example file format

Simple API: export Component (for docs) and examples ("renderables")

import React from 'react';

import Component from 'somewhere';

export default Component;

export const variant1 = () => <Component variant="1" />;
var immer = require("immer")
var produce = immer.produce;
var patches=[];
var state0 = {a:1};
var state1 = produce(state0, function(draft){draft.b=9;}, function(p){patches.push(...p)});
var state2 = produce(state1, function(draft){draft.a=3;}, function(p){patches.push(...p)});
var state3 = produce(state2, function(draft){draft.b=99;}, function(p){patches.push(...p)});
var state4 = produce(state3, function(draft){draft.a=5;}, function(p){patches.push(...p)});
@TheNeuralBit
TheNeuralBit / README.md
Last active November 27, 2022 06:04
Scrabble Arrow

Scrabble Data in an Arrow file

538's data on 45 years of Scrabble games turned into an Arrow file

Usage:

$ python scrabble.py https://media.githubusercontent.com/media/fivethirtyeight/data/master/scrabble-games/scrabble_games.csv scrabble.arrow

Functions are data-flow time machines

Today data-flow diagrams are something every CS student and programmer has seen. It is a nice way of visualizing the general flow of data through an application. But it is rarely more than that. A few reasons for this might be an inconvenience in displaying details. They tend to get big!

Another problem is the rather limited language which is incapable of describing some fundamental ideas of CS like lambda functions. Would you know how to draw a lambda function in a data-flow diagram? If you ever heard of string diagrams, you might be able to do so, but most programmers wouldn't recognize them.

I myself adore data-flow diagrams and I'm fascinated by what you can do with them even in an functional setting. That's why I want to show you, how you can build lambda functions in a data-flow diagram in a functional way and what this has to do with time machines. But first lets start with some simple examples to get used to functional data-flow diagrams. Here we have a rat

@lukashaertel
lukashaertel / AnotherFunneler.kt
Created August 31, 2017 14:52
Generated code of one of the funnelers.
package eu.metatools.kfunnels.tests
import eu.metatools.kfunnels.*
/**
* Funnels and unfunnels Another.
*/
object AnotherFunneler : GeneratedFunneler<Another> {
override val module = eu.metatools.kfunnels.tests.TestsModule
@kevinpschaaf
kevinpschaaf / 0. Custom Elements + Redux toolbox & examples.md
Last active July 21, 2020 06:48
Custom Elements + Redux toolbox & examples

An approach to binding Redux to custom elements

The code here captures some of the patterns I used in the "real estate" demo app discussed in my talk End to End Apps with Polymer from Polymer Summit 2017.

There are many ways to connect Redux to custom elements, and this demonstrates just one pattern. The most important aspects are to try and lazily-load as much of the otherwise global state management logic along with the components that need them (as shown via the lazyReducerEnhancer and addReducers calls in the connected components), and to consider the tradeoffs you make in terms of coupling components to the store.

The pattern shown here of creating a stateless component and then a subclass that connects it to the store addresses a potential desire to reuse app-level stateless components between more than one application context, so the subclass provides a degree of decoupling from the concrete store, at the expense of more boilerplate. If app com