Skip to content

Instantly share code, notes, and snippets.

View heycqing's full-sized avatar
👾
wroking

heycqing heycqing

👾
wroking
View GitHub Profile
@heycqing
heycqing / use-node-unix.bat
Last active February 6, 2024 07:05
用于切换不同项目下window的node版本
#!/bin/bash
TARGET_VERSION="14"
# 检查 nvm 是否已安装
if ! command -v nvm &> /dev/null; then
echo "nvm is not installed. Installing nvm..."
# 安装 nvm (这里仅提供了基本的安装命令,实际安装可能更复杂)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
@heycqing
heycqing / kye_require2import_text.js
Last active October 10, 2023 08:08
require to import to kye
const fs = require('fs');
const path = require('path');
function findRequireStatements(dir, results = []) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
@heycqing
heycqing / require2import.js
Created October 9, 2023 09:57
require to import
const fs = require('fs');
const path = require('path');
const directoryPath = './your_directory_path';
function replaceRequiresWithImports(directoryPath) {
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
@heycqing
heycqing / withSharedState.js
Last active October 10, 2023 02:17
vue2的高阶函数
/**
* 里面的运作原理:
* 1. props的传递方式: props: WrappedComponent.props,
* 2. emit事件的传递方式: this.$emit(eventName, eventValue)
* 3. HOC内部的共用的逻辑处理,与简单操作原理
*
* @param {component} WrappedComponent
* @returns component
*/
export default function withSharedState(WrappedComponent) {
@davidgilbertson
davidgilbertson / http2.js
Last active February 22, 2025 22:22
HTTP2 server with compression and caching
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const brotli = require('brotli'); // npm package
const PORT = 3032;
const BROTLI_QUALITY = 11; // slow, but we're caching so who cares
const STATIC_DIRECTORY = path.resolve(__dirname, '../dist/');
const cache = {};