Skip to content

Instantly share code, notes, and snippets.

@40thieves
40thieves / with-util.js
Created July 3, 2019 09:40
Comparing webpack polyfilling
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;

Effective Learning Strategies

Here are some strategies for learning that scientists and psychologists have found to be effective.

Active Learning vs Passive Learning

Try to do more active learning than passive learning as it is more effective.

Passive Active
// node_modules/5to6-codemod/transforms/amd.js
/**
* amd - Replace define([]) calls with es6 import/exports
*/
var util = require('../utils/main');
export default function transform(file, api, options) {
var j = api.jscodeshift;
let viewport = document.body.getBoundingClientRect()
let maxWidth = viewport.width
let maxHeight = viewport.height
let outer = document.createElement('div')
outer.style = "position: absolute; top: 0; left: 0; right: 0;"
for (let i = 0; i <= 40; i++) {
outer.append(makeImg())
}
module.exports = function (file, api, options) {
const useDouble = options.useDouble || false;
const noSemi = options.noSemi || false;
const useRequire = options.useRequire || false;
const j = api.jscodeshift;
const isContainsLodashImport =
file.source.match(/(const|let|var)\s+_\s+=\s+require\(["']lodash["']\)/g) ||
file.source.match(/import\s+_\s+from\s+["']lodash["']/g);
@40thieves
40thieves / prevent-jsx-array-length-and-operator-without-comparison-eslint-rule.js
Created July 8, 2020 13:47
Custom ESLint rule to catch a footgun in JSX when using && operator with array length comparison
/*
* Catches this footgun:
*
* {myArray.length && (
* <div>Foo</div>
* )}
*
* which renders "0" if myArray is empty
*
* It should instead be:
@40thieves
40thieves / index.html
Last active August 25, 2020 08:55
Demo of async script loading
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Script loading</title>
</head>
<body>
Hello world
@40thieves
40thieves / machine.js
Last active January 5, 2021 17:54
Generated by XState Viz: https://xstate.js.org/viz
const chatMachine = Machine({
id: "chat",
initial: "idle",
context: {
messages: []
},
states: {
idle: {
on: {
fetch: "fetching",
@40thieves
40thieves / machine.js
Created January 5, 2021 17:59
Generated by XState Viz: https://xstate.js.org/viz
const chatMachine = Machine({
id: "chat",
initial: "idle",
context: {
messages: []
},
states: {
idle: {
on: {
fetch: "fetching",
@40thieves
40thieves / machine.js
Last active January 6, 2021 09:35
Generated by XState Viz: https://xstate.js.org/viz
const chatMachine = Machine({
id: "chat",
type: "parallel",
context: {
messages: []
},
states: {
http: {
initial: "idle",
states: {