05 2023 档案
摘要:For example you have two containers running Container A: need to talk to Container B Container B, running a node application export port 1337 From con
阅读全文
摘要:Three rules: There can only be one value owner There can be unlimited immutable borrows (reference) with no mutable references There can be only one m
阅读全文
摘要:Difference between yieldand return returnset doneto true /** * Example 1 */ function* loggerator() { console.log("running"); yield "paused"; console.l
阅读全文
摘要:On mobile device, when you open / close the keyboard, zoom in / out, it might affect the visual viewport view (the actual page content); to detect cha
阅读全文
摘要:React set the ref to null in runtime. It is a limitation now for react. import { useRef } from 'react'; export const Component = () => { const ref = u
阅读全文
摘要:`Option` and `Result` are two very central enums in Rust, and they are used for error handling and for representing the absence of a value. Here is a
阅读全文
摘要:Typescript: import fs from "fs"; const fileName = process.argv[2]; if (fileName) { fs.readFileSync(fileName) .toString() .split("\n") .map((num) => pa
阅读全文
摘要:Typescript: function practice(nums: number[], index: number): number { return (nums[index] ?? index) * 5 } In Rust: fn practice(nums: Vec<usize>, inde
阅读全文
摘要:background.ts: // TODO: background script chrome.runtime.onInstalled.addListener(() => { console.log("onInstalled..."); }); chrome.webRequest.onBefore
阅读全文
摘要:// Imagine NavBar is an external library! export const NavBar = (props: { title: string; links: string[]; children: React.ReactNode; }) => { return <d
阅读全文
摘要:Using Omit import { ComponentProps } from 'react'; import { Equal, Expect } from '../helpers/type-utils'; export const Input = ( props: Omit<Component
阅读全文
摘要:Relevant for components that accept other React components as props. export declare interface AppProps { children?: React.ReactNode; // best, accepts
阅读全文
摘要:fn multiply(num: Option<usize>) -> usize { return num.unwrap_or(0) * 5; } fn multiply1(num: Option<usize>) -> Option<usize> { match num { Some(num) =>
阅读全文
摘要:enum Color { Red, Green, Blue, Yellow, } impl Color { fn is_green(&self) -> bool { if let Color::Green = self { return true; } return false; } fn is_g
阅读全文
摘要:Typescript import * as fs from "fs"; fs.readFileSync("project/lines", { encoding: "utf-8" }) .toString() .split("\n") .filter((_, i) => i % 2 0) .filt
阅读全文
摘要:String collect: automaticlly calling concat on string let foo: String = vec!["this", "is", "a", "test"] .into_iter() .collect(); println!("{:?}", foo)
阅读全文
摘要:docker exec container-id sh -c "patch -p1 < your-file.diff" Replace container-id with the ID of the container you want to run the command in, and your
阅读全文
摘要:Few intertesting things from Rust Option<T>: with Some, unwrap() function todo(): to skil compiler error for a while unreachable(): similar to Typescr
阅读全文
摘要:1. TSD: https://github.com/SamVerschueren/tsd import {expectType} from 'tsd'; import concat from '.'; expectType<string>(concat('foo', 'bar')); expect
阅读全文
摘要:Blog: https://www.totaltypescript.com/react-component-props-type-helper Get any Prop type from html element: import { ComponentProps } from "react"; t
阅读全文
摘要:import {Expect, Equal} from "../types/utils" import { expect, it } from 'vitest'; type PayloadsToDiscriminatedUnion<T extends Record<string, any>> = {
阅读全文
摘要:interface EnemyAttacker { fireWeapon(): void; driveForward(): void; assignDriver(driverName: string): void; } // Target class EnemyTank implements Ene
阅读全文
摘要:With a long-running node server and a database, sometimes it's useful to ssh into the virtual machine to explore the file system, and look at the data
阅读全文
摘要:Blog: https://dev.to/marclipovsky/discovering-the-power-of-javascript-proxy-after-all-this-time-4627 Lazy loading: const lazyLoadHandler = { get: func
阅读全文
摘要:Example code: interface Fruit { name: string; price: number; } export const wrapFruit = <TFruits extends Fruit[]>(fruits: TFruits) => { const getFruit
阅读全文
摘要:With Temperature = 0, everytimes it generates same response, with high temperature, it add more randomness into the response. prompt = f""" You are a
阅读全文
摘要:Universal Translator Imagine you are in charge of IT at a large multinational e-commerce company. Users are messaging you with IT issues in all their
阅读全文
摘要:reverse()mutates the original array, return the reference point to the original array. The toReversed() method of Array instances is the copying count
阅读全文
摘要:sort(), mutates the original array, and return the reference to original array and sorted. The toSorted() method of Array instances is the copying ver
阅读全文
摘要:Array.prototype.splice()mutates the original array. To avoid mutation, we use Array.prototype.slice(). new method Array.prototype.toSpliced() return a
阅读全文
摘要:Prevously, when we want to upate an item inside a array: const items = [ {id: 1, name: 'a'}, {id: 2, name: 'b'}, {id: 3, name: 'c'}, {id: 4, name: 'd'
阅读全文
摘要:Sentiment (positive/negative) lamp_review = """ Needed a nice lamp for my bedroom, and this one had \ additional storage and not too high of a price p
阅读全文