Skip to content

Instantly share code, notes, and snippets.

@TianyiLi
TianyiLi / generate.js
Created August 11, 2020 09:48
apidocjs generate typescript definition token
// ==UserScript==
// @name apidoc json to typescript definition
// @namespace Violentmonkey Scripts
// @match https://t.onramplab.com/docs*
// @grant none
// @version 1.01
// @author [email protected]
// @description apidoc json generate to tsd
// ==/UserScript==
{
import { useState, Dispatch, SetStateAction, useMemo } from 'react';
const reactiveKeys = ['add', 'clear', 'delete'];
const reactive = <K>(set: Set<K>, setSet: Dispatch<SetStateAction<Set<K>>>) => {
const _proxy = Proxy.revocable(set, {
get(target, value: keyof Set<K>) {
if (reactiveKeys.includes(value)) {
return (arg: K) => {
target[value as 'add' | 'clear' | 'delete'].bind(target)(arg);
@TianyiLi
TianyiLi / umijs-useSet.ts
Last active May 18, 2020 14:22
react-map-and-set-hooks-sample
import { useState, useMemo, useCallback } from 'react';
interface StableActions<K> {
add: (key: K) => void;
remove: (key: K) => void;
reset: () => void;
}
interface Actions<K> extends StableActions<K> {
has: (key: K) => boolean;
@TianyiLi
TianyiLi / overview.js
Last active December 11, 2019 04:18
github readme outline - violent monkey
// ==UserScript==
// @name New script - github.com
// @namespace Violentmonkey Scripts
// @match https://github.com/*
// @grant none
// @version 1.0
// @author [email protected]
// @description 12/9/2019, 5:20:26 PM
// ==/UserScript==
if (document.querySelector('#readme article')) {
@TianyiLi
TianyiLi / vue.config.js
Created August 14, 2019 02:13
vue config
const path = require('path')
const ImageminPlugin = require('imagemin-webpack-plugin').default
function resolve (dir) {
return path.join(__dirname, dir)
}
let externals = {}
let plugins = []
if (process.env.NODE_ENV === 'production') {
// 外部有引入cdn的話
externals = {
@TianyiLi
TianyiLi / index.html
Created July 22, 2019 08:17
drag-drop-multiple
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.card {
{
"link": {
"self": {
"href": "/order"
},
"cancel": {
"method": "delete",
"href": "/order/cancel/{id}"
},
"change": {
@TianyiLi
TianyiLi / inject.js
Created July 1, 2019 14:04
very simple live reload
// <![CDATA[ <-- For SVG support
if ('WebSocket' in window) {
(function () {
function refreshCSS () {
var sheets = [].slice.call(document.getElementsByTagName("link"));
var head = document.getElementsByTagName("head")[0];
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
head.removeChild(elem);
@TianyiLi
TianyiLi / index.html
Created December 11, 2018 06:06
nav-icon animation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
#nav-check {
display: none;
@TianyiLi
TianyiLi / sequenceTasks.js
Created April 4, 2018 04:55
Promise sequence
function sequenceTasks(tasks) {
function recordValue(results, value) {
results.push(value);
return results;
}
var pushValue = recordValue.bind(null, []);
return tasks.reduce(function (promise, task) {
return promise.then(task).then(pushValue);
}, Promise.resolve());
}