Skip to content

Instantly share code, notes, and snippets.

View suyanhanx's full-sized avatar
🥦

Suyan suyanhanx

🥦
  • Shanghai,China
  • 19:49 (UTC +08:00)
View GitHub Profile
@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)
@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 / 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 / pack.js
Created November 13, 2018 07:52 — forked from Dafrok/pack.js
/**
* @file 在内存中打包 zip 文件的类,需要设置 `/var/run/${namespace}` 的权限为777
* @author o.o@mug.dog
*/
import * as fs from 'fs';
import * as path from 'path';
import * as mkdirp from 'mkdirp';
import * as archiver from 'archiver';
import * as copydir from 'copy-dir';
@suyanhanx
suyanhanx / eslint-pushed-changes.sh
Created October 20, 2018 01:35 — forked from stalniy/eslint-pushed-changes.sh
ESLINT + pre-receive git hook
#!/bin/bash
TEMPDIR=`mktemp -d`
ESLINTRC=$TEMPDIR/.eslintrc
COMMAND="eslint --color -c $ESLINTRC --rule 'import/no-unresolved: 0' --rule 'import/no-duplicates: 0' --rule 'import/export: 0'"
git show HEAD:.eslintrc > $ESLINTRC
echo "### Ensure changes follow our code style... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
@suyanhanx
suyanhanx / eslint-pushed-changes.sh
Created October 20, 2018 01:35 — forked from stalniy/eslint-pushed-changes.sh
ESLINT + pre-receive git hook
#!/bin/bash
TEMPDIR=`mktemp -d`
ESLINTRC=$TEMPDIR/.eslintrc
COMMAND="eslint --color -c $ESLINTRC --rule 'import/no-unresolved: 0' --rule 'import/no-duplicates: 0' --rule 'import/export: 0'"
git show HEAD:.eslintrc > $ESLINTRC
echo "### Ensure changes follow our code style... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive