Skip to content

Instantly share code, notes, and snippets.

View shikelong's full-sized avatar
🏠
Working from home

shikelong shikelong

🏠
Working from home
View GitHub Profile
//Help me to write a javascript function that download my investment data from a website.
// What the function need to do is parse the HTML of the page and extract the investment data.
// The description of the DOM structure:
// the title row's select is .PositionList_listTitle, then the col name defined under the span in the class ListItemView_commonBox, need to ignore .ListItemView_detailExtra
// the data row's select is ListItemView, but it is just a wrapper. the value of each cols is in .ListItemView_commonBox, but .ListItemView_commonBox may not
// the direct child of the row, it may exists some nest structure.
// If you find the .ListItemView_commonBox, then you can find the text in the span, but sometimes there are some nested spans.
// let's me give you some example:
@shikelong
shikelong / snippets.json
Created March 15, 2024 05:38
🖍️ My RayCast Configurations
[
{
"name": "Personal Email",
"text": "[email protected]",
"keyword": "@@"
},
{
"name": "Home Address",
"text": "221B Baker St., London"
},
@shikelong
shikelong / .zshrc
Last active April 11, 2024 01:26
🐳 My MacOS Development Env Setup
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH

一、理解函数式编程

1. 有一个Web服务,为你提供了如下的数据结构:

难度:★

var data = [
  {
    name: "Jamestown",
    population: 2047,
    temperatures: [-34, 67, 101, 87]

},

@shikelong
shikelong / eventloop.js
Created March 14, 2022 14:32
Event Loop Test Codes
console.group('output 🌿')
queueMicrotask(() => {
console.log('queueMicrotask')
});
requestAnimationFrame(() => {
console.log('requestAnimationFrame')
})
@shikelong
shikelong / tappable.ts
Last active January 28, 2022 06:57
Tapable sample
import {
SyncHook,
SyncBailHook,
SyncWaterfallHook,
SyncLoopHook,
AsyncParallelHook,
AsyncParallelBailHook,
AsyncSeriesHook,
AsyncSeriesBailHook,
AsyncSeriesWaterfallHook,
@shikelong
shikelong / proxy_traps.js
Created January 10, 2022 09:12
ES6 Proxy Playground
function consoleSplit(description = '') {
console.log('-'.repeat(25) + description + '-'.repeat(25));
}
consoleSplit('Get, Set, Has, DeleteProperty')
const p1 = {
name: 'rio',
age: 20,
}
@shikelong
shikelong / attachDimensionStyleForImage.ts
Created December 7, 2021 03:05
Attach dimension style for img (get height/width value from height/width properties)
/**
* html-to-rtf-browser not recognize height/style property of img tag
* so, need add height/size to style property to avoid image lose rtf picture size.
*/
function attachDimensionStyleForImage(htmlString: string): string {
try {
const domParser = new DOMParser();
const doc = domParser.parseFromString(htmlString, "text/html");
const images = doc.getElementsByTagName("img");
for (let i = 0; i < images.length; i++) {
@shikelong
shikelong / useBlockRouteChange.ts
Created December 3, 2021 03:57
react-router Block Route Change
import { useEffect } from "react";
import { useHistory } from "react-router-dom";
export const defaultLevelMessage =
"未保存のデータがあります。ページを離れてもよろしいですか。";
function useBlockRouteChange(
shouldBlock: boolean,
message = defaultLevelMessage,
onLevel?: () => void
@shikelong
shikelong / async-await-forEach-alternatives.md
Created November 18, 2021 11:42 — forked from joeytwiddle/async-await-forEach-alternatives.md
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do: