Skip to content

Instantly share code, notes, and snippets.

View fangbinwei's full-sized avatar
🎯
Focusing

Binwei Fang fangbinwei

🎯
Focusing
View GitHub Profile
@fangbinwei
fangbinwei / api.js
Created April 12, 2021 03:41
axios cancel request vue-router
import axios from 'axios'
/** @type {import('axios').CancelTokenSource) | null } */
export let cancelTokenSource = null
export function setCancelTokenSource (source) {
cancelTokenSource = source
}
axios.interceptors.request.use(function (config) {
// Do something before request is sent
config.cancelToken = cancelTokenSource ? cancelTokenSource.token : null
@fangbinwei
fangbinwei / main.js
Created October 25, 2020 08:06
test registry
// yarn add request
const request = {
get (uri, opts) {
// lazy require
const request = require('util').promisify(require('request'))
const reqOpts = {
method: 'GET',
timeout: 30000,
resolveWithFullResponse: true,
json: true,
@fangbinwei
fangbinwei / test.ts
Last active July 25, 2020 12:58
typescript type from values in array
export const extraKeys = [
'app',
'title',
'package',
'deeplink',
'url',
'logo',
'image',
'type'
] as const
@fangbinwei
fangbinwei / 📊 Weekly development breakdown
Last active December 25, 2024 16:02
📊 Weekly development breakdown
TypeScript 10 hrs 49 mins ████████████████▊░░░░ 80.3%
JavaScript 1 hr 16 mins █▉░░░░░░░░░░░░░░░░░░░ 9.4%
Less 37 mins ▉░░░░░░░░░░░░░░░░░░░░ 4.6%
JSON 31 mins ▊░░░░░░░░░░░░░░░░░░░░ 3.9%
CSS 7 mins ▏░░░░░░░░░░░░░░░░░░░░ 1.0%
@fangbinwei
fangbinwei / main.js
Last active May 18, 2020 03:51
get clipboard image on windows
const execa = require('execa')
const path = require('path')
const fs = require('fs')
async function main() {
const scriptPath = path.join(__dirname, 'pc.ps1');
const imagePath = path.resolve(__dirname, 'clipboard.png')
try {
@fangbinwei
fangbinwei / gitRecord.js
Created March 17, 2020 09:03
record latest git info to file
const fs = require('fs')
const path = require('path')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const mkdirp = require('mkdirp')
const outputPath = 'dist/static'
async function main() {
try {
@fangbinwei
fangbinwei / runNpmIfPackageUpdated.js
Created March 17, 2020 09:00
run 'npm install' if package.json was modified
const util = require('util')
const childProcess = require('child_process')
const exec = util.promisify(childProcess.exec)
async function main() {
try {
const { stdout: changeFiles } = await exec(
'git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD'
)
if (changeFiles.includes('package.json')) {
@fangbinwei
fangbinwei / pre-commit.js
Created October 1, 2019 13:08
git pre-commit hooks for detecting 'console.log'
const shell = require('shelljs')
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
shell.exec('git diff --cached',{silent: true}, async (code, stdout, stderr) => {
if (code !== 0) return
if (!stdout.match(/console\.log/)) return