Skip to content

Instantly share code, notes, and snippets.

View Neo42's full-sized avatar
:shipit:

Johnny (Hao) Jiang Neo42

:shipit:
View GitHub Profile
@Neo42
Neo42 / config.bash
Created February 16, 2022 05:35
how to fix git connection issue
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 http://127.0.0.1:8001
git config --global https.proxy https://127.0.0.1:8001
@Neo42
Neo42 / April 18, 2022.md
Last active March 6, 2023 09:44
gistpad-scratch

Rust Jargon Explained

Scope

  • 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
Neo42 / readme.md
Last active March 8, 2022 10:18
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
Neo42 / readme.md
Last active January 20, 2022 08:07
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
@Neo42
Neo42 / __webpack_require__.js
Created January 19, 2022 16:15
__webpack_require__
/******/ 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 module.id needed
@Neo42
Neo42 / promise.js
Last active January 18, 2022 10:43
Simple promise implementation.
const states = {
PENDING: 'PENDING',
FULFILLED: 'FULFILLED',
REJECTED: 'REJECTED',
}
const isThenable = (thing) => thing && typeof thing.then === 'function'
class MyPromise {
_state = states.PENDING
@Neo42
Neo42 / command.js
Last active January 17, 2022 14:56
Design patterns in JavaScript
class OrderManager {
orders = new Set()
execute(command, ...args) {
return command.run(this.orders, ...args)
}
}
class Command {
constructor(steps) {
@Neo42
Neo42 / context-module-functions.js
Last active January 8, 2022 14:20
React Patterns: context module functions
// 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'
type AppleLiteral = 'Apple'
let appleName: AppleLiteral = 'Apple'
type LiteralIsStringType<Type> = Type extends string
? string
: Type extends number
? number
: Type extends boolean
? boolean
@Neo42
Neo42 / mapped-types-&-modifiers.ts
Last active January 8, 2022 06:47
Mapped types are the for...in loop for types.
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>