Skip to content

Instantly share code, notes, and snippets.

View joyqi's full-sized avatar
🤖
Upgrading firmware...

joyqi joyqi

🤖
Upgrading firmware...
View GitHub Profile
@joyqi
joyqi / proxy.php
Created February 6, 2020 04:16
用PHP写的简单AJAX跨域代理
<?php
define('REFERER', 'joyqi.github.io');
define('REDIS_CACHE', '127.0.0.1:6379');
define('TIMEOUT', 5);
function check_host($host) {
if ('localhost' == $host) {
return false;
}
@joyqi
joyqi / example.ts
Last active February 15, 2022 10:35
A simple state manager
import {createStore} from './store';
const [store, watch] = createStore({ counter: 1 });
watch((data) => {
console.log(data.counter);
});
store.counter += 1;
store.counter += 1;
@joyqi
joyqi / singleton.ts
Last active December 12, 2022 10:38
Implement a simple singleton function in TypeScript
const instances = new WeakMap();
// Create a singleton instance.
export function singleton<T>(fn: () => T): () => T {
return () => {
let instance = instances.get(fn);
if (!instance) {
instance = fn();
instances.set(fn, instance);
@joyqi
joyqi / build_wxwasm.sh
Last active May 8, 2024 03:15
通过 wasm-pack 为微信小程序构建 wasm 文件,并修复可能存在的问题
#!/bin/bash
# build wasm
wasm-pack build --target web
# find wasm files
wasm_file=$(find pkg -name "*.wasm")
name=$(basename -s "_bg.wasm" $wasm_file)
js_file="pkg/${name}.js"
old_js_file="pkg/${name}.old.js"