Skip to content

Instantly share code, notes, and snippets.

@ekoneko
ekoneko / yapi_to_ts.js
Last active March 15, 2023 07:14
A tampermonkey script for translating yapi to typescript and mock fake data
// ==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==
@ekoneko
ekoneko / yarn-cache-clean.js
Created December 29, 2020 03:12
remove yarn cache
#!/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);
@ekoneko
ekoneko / typescriptreact.json
Last active April 7, 2023 07:49
vscode snip
{
"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 />",
@ekoneko
ekoneko / Semver2Number.ts
Created April 18, 2018 08:09
Semver to Number
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!')
@ekoneko
ekoneko / test.js
Last active August 27, 2017 04:19
node file sync test
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)
@ekoneko
ekoneko / call_vim.js
Last active July 20, 2017 02:17
node trick
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");
});
@ekoneko
ekoneko / pre-commit.sh
Last active June 14, 2017 05:03
ESLint Pre Commit Check
#!/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
@ekoneko
ekoneko / git.sh
Created April 14, 2017 10:15
commonly cmd
# list git commit message
git log --oneline | head -n 4 | cut -d ' ' -f2-
@ekoneko
ekoneko / async-generator.js
Created July 23, 2016 16:41
async generator
/**
* 一个异步生成器的简单函数实现
* 演示参照下方exec
*/
var async = function (makeGenerator) {
return function () {
var generator = makeGenerator();
var continuer = function (result, value) {
if (result && result.done) {
return;
@ekoneko
ekoneko / paste image
Created February 24, 2016 10:11
html5 get ctrl + v image
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();