Skip to content

Instantly share code, notes, and snippets.

View suyanhanx's full-sized avatar
🥦

Suyan suyanhanx

🥦
  • Shanghai,China
  • 09:53 (UTC +08:00)
View GitHub Profile
@suyanhanx
suyanhanx / license-summarize.mjs
Created December 9, 2023 09:08
Generate licenses group text
import licenseData from './license.json' assert { type: 'json'}
import fs from 'node:fs'
let store = new Map()
Object.entries(licenseData).forEach(([name, data]) => {
const { licenses } = data
if (store.has(licenses)) {
store.get(licenses).push(name)
} else {
store.set(licenses, [name])
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
#[macro_use]
extern crate napi_derive;
use napi::bindgen_prelude::*;
pub struct Foo {}
impl napi::bindgen_prelude::TypeName for Foo {
@suyanhanx
suyanhanx / index.js
Last active September 1, 2022 11:05 — forked from hax/index.js
JS trick to mimic C# obj.onevent += delegate
const HandlerID = Symbol()
export function defineEvent(obj, name) {
const handlers = new Set()
const fn = function () {
for (const handler of handlers) {
try {
handler()
} catch (e) {
Promise.reject(e)
/**
* 获取 promise 的 tuple
*
* @export
* @template T
* @template R
* @param promise 需要获取结果的 promise 对象
* @returns {(Promise<[R] | [null, T]>)}
*/
@suyanhanx
suyanhanx / get_free_vars.ts
Created August 27, 2020 09:26 — forked from buhichan/get_free_vars.ts
js get free variables hack
/**
* some insane hack, just want to avoid using expensive parser.
*/
export function getFreeVariables(expr:string, knownSymbols:Record<string,unknown>){
const freeVariables = new Set<string>();
//eslint-disable-next-line
const anyThingPrimitive = ()=>{};
@suyanhanx
suyanhanx / resetVueData.ts
Created April 17, 2020 08:38
重置 Vue 组件的数据
/**
* 重置 Vue 组件的数据
* @param {Vue} instance
*/
export function resetVueData(instance: Vue): void {
Object.assign(instance.$data, (instance.$option.data as any).call(instance))
}
@suyanhanx
suyanhanx / hook-form.tsx
Created November 6, 2019 09:03 — forked from buhichan/hook-form.tsx
react hook form
import * as React from "react"
import { BehaviorSubject } from 'rxjs';
const ERROR_DETAIL = Symbol("errors")
const HAS_ERROR = Symbol("has error")
const InternalSymbolKeys = [ERROR_DETAIL,HAS_ERROR]
enum FieldType {
arrayItem,
@suyanhanx
suyanhanx / formatAmountCapitalized.js
Created July 4, 2019 07:34
formatAmountCapitalized 将金额数字转换成大写
export function formatAmountCapitalized(n) {
let fraction = ['角', '分'];
let digit = [
'零', '壹', '贰', '叁', '肆',
'伍', '陆', '柒', '捌', '玖'
];
let unit = [
['元', '万', '亿'],
['', '拾', '佰', '仟']
];
function sleep(d){
for(var t = Date.now();Date.now() - t <= d;);
}
sleep(5000); //当前方法暂停5秒
@suyanhanx
suyanhanx / call.js
Last active January 17, 2019 05:30
// 无root拉起钉钉打卡
var a = app.intent({
action: "VIEW",
data: "dingtalk://dingtalkclient/page/link?url=https://attend.dingtalk.com/attend/index.html"
});
app.startActivity(a);
//需要用到root权限 否则打不开
var TimeStamp = Math.round(new Date());
var corpId = ""; //自己想办法获取公司的ID ding开头的一串码