Skip to content

Instantly share code, notes, and snippets.


Hao Neo42

View GitHub Profile
Neo42 / config.bash
Created Feb 16, 2022
how to fix git connection issue
View config.bash
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --local --unset http.proxy
git config --local --unset https.proxy
git config --global http.proxy
git config --global https.proxy
Neo42 / April 18,
Last active Apr 20, 2022
View April 18,

Rust Jargon Explained


  • Definition: Region of the program where a variable is valid.
  • A variable becomes valid when it comes into scope.
  • A variable remains valid until it goes out of scope.
  • Variable bindings are constrained to live within a block of code where it was created.
  • Blocks of code are enclosed by curly braces: {}
Neo42 /
Last active Mar 8, 2022
how webpack works inside

How code splitting works in webpack?

  1. get the chunkIds and moreModules
  2. for each chunkId, if the chunk is previously cached, use that cached version
  3. load all the modules in moreModules
  4. run __webpack_require__.e when needed
    1. find the head, create the script tag
    2. send a JSONP request, get the code
    3. append the script to the head
Neo42 /
Last active Jan 20, 2022
When to use code splitting (dynamic import) in webpack?
  1. Heavy library but not needed initially (threejs)
  2. Temporal components (that come and go or are conditionally loaded): tooltips, model, notification, dialog, page scrolling
  3. Routes
View __webpack_require__.js
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId]
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports
/******/ // Create a new module (and put it into the cache)
/******/ var module = (__webpack_module_cache__[moduleId] = {
/******/ // no needed
Neo42 / promise.js
Last active Jan 18, 2022
Simple promise implementation.
View promise.js
const states = {
const isThenable = (thing) => thing && typeof thing.then === 'function'
class MyPromise {
_state = states.PENDING
Neo42 / command.js
Last active Jan 17, 2022
Design patterns in JavaScript
View command.js
class OrderManager {
orders = new Set()
execute(command, ...args) {
return, ...args)
class Command {
constructor(steps) {
Neo42 / context-module-functions.js
Last active Jan 8, 2022
React Patterns: context module functions
View context-module-functions.js
// Context Module Functions
import * as React from 'react'
import {dequal} from 'dequal'
import * as userClient from '../user-client'
import {useAuth} from '../auth-context'
const UserContext = React.createContext()
UserContext.displayName = 'UserContext'
View conditional-types.ts
type AppleLiteral = 'Apple'
let appleName: AppleLiteral = 'Apple'
type LiteralIsStringType<Type> = Type extends string
? string
: Type extends number
? number
: Type extends boolean
? boolean
Neo42 / mapped-types-&-modifiers.ts
Last active Jan 8, 2022
Mapped types are the loop for types.
View mapped-types-&-modifiers.ts
interface Fruit {
readonly name?: string
readonly color?: string
readonly sweetness?: number
type Properties<Type> = keyof Type
type Values<Type> = Type[Properties<Type>]
type FruitProperties = Properties<Fruit>