Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Hao Neo42

🎯
Focusing
View GitHub Profile
@Neo42
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 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 Apr 20, 2022
gistpad-scratch
View April 18, 2022.md

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 Mar 8, 2022
how webpack works inside
View readme.md

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 Jan 20, 2022
When to use code splitting (dynamic import) in webpack?
View readme.md
  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 module.id needed
@Neo42
Neo42 / promise.js
Last active Jan 18, 2022
Simple promise implementation.
View promise.js
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 Jan 17, 2022
Design patterns in JavaScript
View command.js
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 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
Neo42 / mapped-types-&-modifiers.ts
Last active Jan 8, 2022
Mapped types are the for...in 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>