Skip to content

Instantly share code, notes, and snippets.

View eightHundreds's full-sized avatar
💤

eightHundreds

💤
  • China
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>regex基准</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@eightHundreds
eightHundreds / javaEnum2js.js
Last active October 14, 2023 06:36
java 转 js
function javaEnumToTs(code) {
return code.replace(
/(?![\n\r]+)(\w+)\((-?\d+),\s"([^"]+)"[^\n\r]+/g,
(match, g1, g2,g3) => `/**${g3}**/
${g1}:${g2},`
);
}
@eightHundreds
eightHundreds / api.ts
Created February 26, 2021 09:28
api.ts 接口请求代码
{
"pp-api": {
"prefix": "ppa",
"body": [
"import { message } from 'antd';",
"import { AxiosResponse } from 'axios';",
"import http from 'helper/http';",
"import microservice from 'helper/microservice';",
"import { get as _get } from 'lodash';",
"const { javaAdmin } = microservice;",
@eightHundreds
eightHundreds / node-memory-config.md
Last active January 27, 2021 10:36
修改node内存限制

当不是用node方式启动时

NODE_OPTIONS=--max_old_space_size=4096 webpack xxx
@eightHundreds
eightHundreds / text-width.ts
Created November 27, 2020 01:55
计算文本宽度
/**
* 计算文本长度
* @param text
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
*/
function getTextWidth(text: string) {
// @ts-ignore
const canvas: HTMLCanvasElement = getTextWidth.canvas || (getTextWidth.canvas = document.createElement('canvas'));
const context = canvas.getContext('2d');
context!.font = '14px sans-serif'; // 14px是猜测的,不能确定
@eightHundreds
eightHundreds / hide-scrollbar.vue
Last active August 3, 2020 07:04
滚动条隐藏
<template>
</template>
<script lang="ts">
const onSomethingScrollFactory = () => {
const SCROLL_HIDE_TIMEOUT = 150;
const removeScrolling = debounce((el) => {
el.classList.remove('scrolling');
}, SCROLL_HIDE_TIMEOUT);
@eightHundreds
eightHundreds / api.ts
Last active July 17, 2020 03:38
Ts工具类型声明
namespace Api {
type PageParam<T = {}> = T & { pageNum?: number; pageSize?: number };
type ApiResult<T = {}> = {
[key: string]: any; // 其他基本用不到,想知道看文档
/**
* 调用是否成功
*/
success: boolean;
/**
* 业务状态码
@eightHundreds
eightHundreds / scrollbar.css
Last active July 15, 2020 03:19
滚动条
::-webkit-scrollbar {/* 滚动条整体样式 */
width: 4px; /* 高宽分别对应横竖滚动条的尺寸 */
height: 0;
}
::-webkit-scrollbar-thumb {/* 滚动条里面小方块 */
border-radius: 2px;
background: rgba(0, 0, 0, 0.13);
height: 60px;
}
@eightHundreds
eightHundreds / insertImports.js
Created May 20, 2020 03:44
jscodeshift工具方法
const j = require('jscodeshift')
/**
* 为代码插入import语句,只能处理import不能处理require,只能插入import语句,其他代码会被忽略
* @param {*} source
* @param {*} imports
* @copyright 抄自vue-cli/packages/@vue/cli/lib/util/codemods/injectImports.js
*/
module.exports.injectImports = function(source, imports) {
const root = j(source)
@eightHundreds
eightHundreds / playground.json
Last active May 8, 2020 13:16
moment-playground
{
"scripts": [
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.25.3/moment.min.js"
],
"styles": [],
"showConsole": true,
"scriptType": "module"
}