Skip to content

Instantly share code, notes, and snippets.

View aztack's full-sized avatar
🎯
Focusing

Wang Weihua aztack

🎯
Focusing
View GitHub Profile
@aztack
aztack / useArrayCompare
Created April 15, 2024 07:12
useArrayCompare
function useArrayCompare<T>(value: T[]) {
const ref = useRef<T[]>(value);
if (value.length !== ref.current.length ||value.sort().join(',') !== ref.current.join(',')) {
ref.current = value;
}
return ref.current;
}
@aztack
aztack / find-get-commits-by-file-name.js
Last active March 10, 2024 07:01
Print git changes by file name
const { execSync } = require('child_process');
// Replace the array with the usernames of the developers whose commits you want to fetch
const developers = ['developer1', 'developer2', 'developer3'];
function getCommitsByDevelopers() {
const commits = [];
for (const developer of developers) {
const gitCommand = `git log --author="${developer}" --pretty=format:"%h"`;
const commitHashes = execSync(gitCommand).toString().trim().split('\n');
GOOS=windows GOARCH=amd64 go build
// jonschlinkert/is-object
type IsObjectObject<T> = T extends
| AnyArray
| AnyFunction
| boolean
| null
| number
| string
| symbol
| undefined
#!/bin/bash
ancestor_branch=${1:-"origin/develop-sdk"}
# Find the latest common ancestor commit
joint_commit=$(git merge-base HEAD $ancestor_branch)
echo $joint_commit
# Get the list of commit hashes from current HEAD to the joint commit
commit_hashes=$(git rev-list --ancestry-path ${joint_commit}..HEAD)
import { useState, useEffect } from 'react';
function useDebouncedValue<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
@aztack
aztack / gist:4ddcfb9b400e94eac7dbe7f243f85b96
Created October 16, 2023 06:59
Yeoman Generator Overwrite without Prompt
class extends Generator {
writing() {
// enable force overwrite
this.conflicter.force = true;
this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'),
{ appname: 'your_appname' }
);
import readline from 'node:readline';
function printProgress(text: string) {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, undefined);
process.stdout.write(text);
};
@aztack
aztack / probe.js
Created October 7, 2023 06:47
Test given url availability in browser wiht fetch HTTP HEAD and specific timeout
/**
* Test given url availability in browser wiht fetch HTTP HEAD and specific timeout
* @param url
*/
export function probe(url: string, opt?: RequestInit & { timeout: number }) {
const ctrl = new AbortController();
const timeout = (opt || {}).timeout || 5000;
const timer = setTimeout(() => ctrl.abort(), timeout);
return new Promise(resolve => {
const promise = fetch(url, { signal: ctrl.signal, method: 'HEAD', ...opt })
@aztack
aztack / gist:a774b7c82e94330f49a20e0a1523227f
Created August 28, 2023 03:20
ShowTabWithPrefix AppleScript
on ShowTabWitePrefix(targetDomain) tell application "Google Chrome" set windowList to every window repeat with aWindow in windowList set tabList to every tab of aWindow set tabCount to count of tabList set currentTabIndex to 0 set targetTabs to {} -- Collect all the tabs matching the targetDomain prefix repeat with i from 1 to tabCount set aTab to item i of tabList considering case set tabURL to URL of aTab if tabURL starts with targetDomain then set end of targetTabs to {index:i, tab:aTab} end if end considering end repeat -- If there are any matching tabs, activate the next one in the list if (count of targetTabs) > 0 then set currentIndex to 0 repeat with i from 1 to count of targetTabs if active tab index of aWindow is (index of item i of targetTabs) then set currentIndex to i exit repeat end if end repeat -- if the current tab is the last matching one, activate the first one, else activate the next one