View yapi_to_ts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YApi to Ts Interface | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Generate ts interface or fake data in yapi | |
// @author Eko | |
// @match {HOST}/project/*/interface/api/* | |
// @icon https://www.google.com/s2/favicons?domain=TO_BE_REPLACED | |
// @grant none | |
// ==/UserScript== |
View yarn-cache-clean.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require("fs"); | |
const path = require("path"); | |
const { execSync } = require("child_process"); | |
function findMetaFile(modulePath) { | |
const name = ".yarn-metadata.json"; | |
function walkDir(dirPath) { | |
const subFiles = fs.readdirSync(dirPath); |
View typescriptreact.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"React_Class": { | |
"prefix": "comp", | |
"body": [ | |
"export interface ${TM_FILENAME_BASE}Props {}", | |
"export interface ${TM_FILENAME_BASE}State {}", | |
"export class ${TM_FILENAME_BASE} extends React.PureComponent<${TM_FILENAME_BASE}Props, ${TM_FILENAME_BASE}State> {", | |
" render () {", | |
" return (", | |
" <div />", |
View Semver2Number.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultBitLength = 6 | |
const maxBitLength = 16 | |
function transformSemver2Number (semver: string): string { | |
const [n1, n2, n3] = semver.split('.').map(Number) | |
const maxNum = Math.max(n1, n2, n3) | |
const minBitLength = Math.ceil(Math.log2(maxNum)) | |
const bitLength = Math.max(minBitLength, defaultBitLength) | |
if (bitLength > maxBitLength) { | |
throw new Error('semver too big!') |
View test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const startTime = Date.now(); | |
console.log('start at', startTime); | |
setTimeout(() => { | |
const endTime = Date.now(); | |
console.log('0.01 sec later', endTime); | |
console.log(endTime - startTime) | |
}, 10) |
View call_vim.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const child_process = require('child_process'); | |
const editor = process.env.EDITOR || 'vi'; | |
const child = child_process.spawn(editor, ['/tmp/somefile.txt'], { | |
stdio: 'inherit' | |
}); | |
child.on('exit', function (e, code) { | |
console.log("finished"); | |
}); |
View pre-commit.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ESLint Pre Commit Check | |
# put to `.git/hooks/pre-commit` | |
eslint_check() { | |
files=$(git diff --cached --name-only --diff-filter=AM | grep '\.jsx\?$') | |
if [[ $files = "" ]] ; then | |
return | |
fi | |
failed=0 |
View git.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list git commit message | |
git log --oneline | head -n 4 | cut -d ' ' -f2- |
View async-generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 一个异步生成器的简单函数实现 | |
* 演示参照下方exec | |
*/ | |
var async = function (makeGenerator) { | |
return function () { | |
var generator = makeGenerator(); | |
var continuer = function (result, value) { | |
if (result && result.done) { | |
return; |
View paste image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paste = (e) => { | |
var file, remoteImages; | |
if (typeof e.clipboardData.types === 'undefined' || e.clipboardData.types.length === 0 || e.clipboardData.types[0] !== 'Files') { | |
return; | |
} | |
file = e.clipboardData.items[0].getAsFile(); | |
render(file); | |
e.stopPropagation(); |
NewerOlder