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 阅读全文
posted @ 2023-05-31 20:00 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-29 14:42 Zhentiw 阅读(32) 评论(0) 推荐(0) 编辑
摘要:Difference between yieldand return returnset doneto true /** * Example 1 */ function* loggerator() { console.log("running"); yield "paused"; console.l 阅读全文
posted @ 2023-05-25 17:39 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-24 17:53 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-24 15:11 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:`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 阅读全文
posted @ 2023-05-24 13:57 Zhentiw 阅读(69) 评论(0) 推荐(0) 编辑
摘要:Typescript: import fs from "fs"; const fileName = process.argv[2]; if (fileName) { fs.readFileSync(fileName) .toString() .split("\n") .map((num) => pa 阅读全文
posted @ 2023-05-24 13:52 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑
摘要:Typescript: function practice(nums: number[], index: number): number { return (nums[index] ?? index) * 5 } In Rust: fn practice(nums: Vec<usize>, inde 阅读全文
posted @ 2023-05-24 01:24 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:background.ts: // TODO: background script chrome.runtime.onInstalled.addListener(() => { console.log("onInstalled..."); }); chrome.webRequest.onBefore 阅读全文
posted @ 2023-05-22 14:39 Zhentiw 阅读(96) 评论(0) 推荐(0) 编辑
摘要:// Imagine NavBar is an external library! export const NavBar = (props: { title: string; links: string[]; children: React.ReactNode; }) => { return <d 阅读全文
posted @ 2023-05-22 14:11 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要:Using Omit import { ComponentProps } from 'react'; import { Equal, Expect } from '../helpers/type-utils'; export const Input = ( props: Omit<Component 阅读全文
posted @ 2023-05-22 13:58 Zhentiw 阅读(35) 评论(0) 推荐(0) 编辑
摘要:Relevant for components that accept other React components as props. export declare interface AppProps { children?: React.ReactNode; // best, accepts 阅读全文
posted @ 2023-05-22 13:24 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:fn multiply(num: Option<usize>) -> usize { return num.unwrap_or(0) * 5; } fn multiply1(num: Option<usize>) -> Option<usize> { match num { Some(num) => 阅读全文
posted @ 2023-05-18 20:32 Zhentiw 阅读(21) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-17 14:53 Zhentiw 阅读(21) 评论(0) 推荐(0) 编辑
摘要:Typescript import * as fs from "fs"; fs.readFileSync("project/lines", { encoding: "utf-8" }) .toString() .split("\n") .filter((_, i) => i % 2 0) .filt 阅读全文
posted @ 2023-05-16 14:34 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:String collect: automaticlly calling concat on string let foo: String = vec!["this", "is", "a", "test"] .into_iter() .collect(); println!("{:?}", foo) 阅读全文
posted @ 2023-05-15 15:01 Zhentiw 阅读(69) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-10 22:53 Zhentiw 阅读(16) 评论(0) 推荐(0) 编辑
摘要:Few intertesting things from Rust Option<T>: with Some, unwrap() function todo(): to skil compiler error for a while unreachable(): similar to Typescr 阅读全文
posted @ 2023-05-09 01:03 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:1. TSD: https://github.com/SamVerschueren/tsd import {expectType} from 'tsd'; import concat from '.'; expectType<string>(concat('foo', 'bar')); expect 阅读全文
posted @ 2023-05-07 16:08 Zhentiw 阅读(22) 评论(0) 推荐(0) 编辑
摘要:Blog: https://www.totaltypescript.com/react-component-props-type-helper Get any Prop type from html element: import { ComponentProps } from "react"; t 阅读全文
posted @ 2023-05-07 16:04 Zhentiw 阅读(65) 评论(0) 推荐(0) 编辑
摘要:import {Expect, Equal} from "../types/utils" import { expect, it } from 'vitest'; type PayloadsToDiscriminatedUnion<T extends Record<string, any>> = { 阅读全文
posted @ 2023-05-07 16:00 Zhentiw 阅读(21) 评论(0) 推荐(0) 编辑
摘要:interface EnemyAttacker { fireWeapon(): void; driveForward(): void; assignDriver(driverName: string): void; } // Target class EnemyTank implements Ene 阅读全文
posted @ 2023-05-05 01:59 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-04 14:09 Zhentiw 阅读(20) 评论(0) 推荐(0) 编辑
摘要:Blog: https://dev.to/marclipovsky/discovering-the-power-of-javascript-proxy-after-all-this-time-4627 Lazy loading: const lazyLoadHandler = { get: func 阅读全文
posted @ 2023-05-04 13:45 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Example code: interface Fruit { name: string; price: number; } export const wrapFruit = <TFruits extends Fruit[]>(fruits: TFruits) => { const getFruit 阅读全文
posted @ 2023-05-03 01:55 Zhentiw 阅读(40) 评论(0) 推荐(0) 编辑
摘要:With Temperature = 0, everytimes it generates same response, with high temperature, it add more randomness into the response. prompt = f""" You are a 阅读全文
posted @ 2023-05-02 15:14 Zhentiw 阅读(33) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-02 14:58 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑
摘要:reverse()mutates the original array, return the reference point to the original array. The toReversed() method of Array instances is the copying count 阅读全文
posted @ 2023-05-02 14:06 Zhentiw 阅读(20) 评论(0) 推荐(0) 编辑
摘要:sort(), mutates the original array, and return the reference to original array and sorted. The toSorted() method of Array instances is the copying ver 阅读全文
posted @ 2023-05-02 14:04 Zhentiw 阅读(32) 评论(0) 推荐(0) 编辑
摘要:Array.prototype.splice()mutates the original array. To avoid mutation, we use Array.prototype.slice(). new method Array.prototype.toSpliced() return a 阅读全文
posted @ 2023-05-02 14:01 Zhentiw 阅读(77) 评论(0) 推荐(0) 编辑
摘要: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' 阅读全文
posted @ 2023-05-02 13:55 Zhentiw 阅读(30) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-05-02 01:41 Zhentiw 阅读(31) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示