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
@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:

@shikelong
shikelong / convert-file-name.rb
Created November 17, 2021 01:25
【Ruby】 Convert file name (a b.svg ==> a-b.svg)
puts "start convert file names to hyphen style...."
def traverse_dir(fileType)
folder_path = File.absolute_path("./") + "/"
scheme = folder_path + "*.#{fileType}"
puts "find #{Dir.glob(scheme).length} #{fileType} files, start convert...."
puts '-' * 50
Dir.glob(scheme).each do |f|
filename = File.basename(f, File.extname(f))
File.rename(f, folder_path + filename.downcase.tr(' ', '-') + File.extname(f))