Skip to content

Instantly share code, notes, and snippets.

@TianyiLi
TianyiLi / track.js
Last active October 17, 2017 08:30
javascript lines track
export function logger(...arg){
let parrent = new Error()
.stack
.split("\n")[2]
.trim()
.replace(/^at /, '')
.replace(__dirname, '')
let log = arg.forEach(e=>{ e = typeof e === 'string' ? e : JSON.stringify(e, null, 4)}).join(' ')
return log
}
@TianyiLi
TianyiLi / vue-global.d.ts
Created October 18, 2017 02:25
vue global type declaration
import * as _vue from "./vue";
declare global {
const Vue: typeof _vue.Vue;
}
@TianyiLi
TianyiLi / lib.js
Last active March 9, 2018 02:50
sample lib
module.exports.repeatWord = (length) => _char => Array.from({ length }, e => _char).join('')
module.exports.range = (length, start = 0) => Array.from({ length }, (_, i) => i + start)
module.exports.zeroAdd = (length, str) => (repeatWord(length)('0') + str).slice(length * -1)
@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());
}
@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 / 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);
{
"link": {
"self": {
"href": "/order"
},
"cancel": {
"method": "delete",
"href": "/order/cancel/{id}"
},
"change": {
@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 {
@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 / 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')) {