Skip to content

Instantly share code, notes, and snippets.

View rjbultitude's full-sized avatar

Rich rjbultitude

View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active May 27, 2024 21:19
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.
@pavanpodila
pavanpodila / metadata-loader.js
Created October 7, 2019 04:31
A webpack-loader that reads Component metadata and generates a *.component.json file
const parser = require('@babel/parser');
const traverse = require('@babel/traverse').default;
const generator = require('@babel/generator').default;
module.exports = function(source) {
// Parse to get the AST
const ast = parser.parse(source, {
sourceType: 'module',
plugins: [
'jsx',
[
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active May 22, 2024 08:34
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@paceaux
paceaux / conjunctions.english.js
Created October 5, 2018 21:49
English conjunctions
/*
* Conjunctions
* https://www.english-grammar-revolution.com/list-of-conjunctions.html
*/
module.exports = [
{
conjunction: ['and'],
type: 'coordinating',
},
@chrisguttandin
chrisguttandin / post.md
Created May 31, 2017 16:27
What else can we do with the Web Audio API?

What else can we do with the Web Audio API?

Of course the Web Audio API is meant for synthesizing and processing audio data. It is tailored for that use case. But at least in our digital world audio data is just a series of numbers, which are typically somewhere between +1 and -1. So why can't we use the Web Audio API for general computations?

Almost a year ago I had the pleasure to give a talk at the Web Audio Conference in Atlanta. The conference featured a lot of great talks, which I really appreciated as an attendee. However, as a speaker it was tough to reduce my own talk until it was short enough to fit into the schedule. I had the feeling that I had to rush through my slides. Since then I planned to write down my findings in a more detailed way, but I never got around to it. Luckily I was asked to repeat my talk at our local Web Audio Meetup here in

@patrickkunka
patrickkunka / factories-1.js
Last active March 6, 2021 21:27
Factory Function Patterns
/**
* Factory #1: Constructor Instantiation
*
* This example shows basic abstraction of constructor/class
* instantation. Additional error checking, validation of arguments
* could be added inside the factory, or just delegated to the constructor.
*/
import Implementation from './Implementation';
@Spikus
Spikus / event-delegate.js
Last active November 1, 2017 13:49
ZoneEventDelegate
class EventDelegate {
constructor() {
this.events = {};
window.eventDelegate = this;
}
addEvent(newEvent, eventSelector, handle) {
this.createEvent(newEvent);
@perry-mitchell
perry-mitchell / .babelrc
Created December 6, 2016 19:01
Webpack2 + inject-loader2.0.1 (blog post)
{
"env": {
"testing": {
"presets": [
"es2015"
]
}
},
"presets": [
["es2015", { "modules": false }]
@Restuta
Restuta / framework-sizes.md
Last active March 7, 2024 00:01
Sizes of JS frameworks, just minified + minified and gzipped, (React, Angular 2, Vue, Ember)

Below is the list of modern JS frameworks and almost frameworks – React, Vue, Angular, Ember and others.

All files were downloaded from https://cdnjs.com and named accordingly. Output from ls command is stripped out (irrelevant stuff)

As-is (minified)

$ ls -lhS
566K Jan 4 22:03 angular2.min.js
@Restuta
Restuta / the-bind-problem.jsx
Last active March 16, 2024 00:22
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));