Skip to content

Instantly share code, notes, and snippets.

View YaoKaiLun's full-sized avatar
🎯
Focusing

yaokailun YaoKaiLun

🎯
Focusing
View GitHub Profile
/**
* Recursively flatten the data
* [{path:string},{path:string}] => {path,path2}
* @param menus
*/
export const getFlatMenuKeys = (menuData: MenuDataItem[] = []): string[] => {
let keys: string[] = [];
menuData.forEach(item => {
if (!item) {
return;
@YaoKaiLun
YaoKaiLun / knapsack.js
Last active January 6, 2019 07:38
javascript algorithm
/*
* 要求:0 1 背包问题
* 参考:https://segmentfault.com/a/1190000012829866
*/
function knapsack(weights, values, W) {
/*
* 根据公式计算填写表格 f(i, j)
* i=0 && j<wi f(i, j)=0
* i=0 && j>=wi f(i, j)=v0
@YaoKaiLun
YaoKaiLun / animation.js
Last active January 29, 2019 09:02
the practice of javascript
/*
* 要求:实现一个div滑动的动画,由快至慢5s结束
* 参考:https://developers.google.com/web/fundamentals/design-and-ux/animations/css-vs-javascript?hl=zh-tw
*/
function Box() {
let startTime = 0
const ACCEL = 30
const TIME = 5
let initSpeed = ACCEL * TIME
for i in range(3):
try:
posts = get_userposts(user)
break
except:
print 'Failed user ' + user + ', retrying'
time.sleep(4)
@YaoKaiLun
YaoKaiLun / vue-init
Created January 21, 2018 04:17
use vue cli to init a project template
#!/usr/bin/env node
const download = require('download-git-repo')
const program = require('commander')
const exists = require('fs').existsSync
const path = require('path')
const ora = require('ora')
const home = require('user-home')
const tildify = require('tildify')
const chalk = require('chalk')
@YaoKaiLun
YaoKaiLun / fc-nodejs-sdk
Created January 16, 2018 01:27
check async support
function supportAsyncFunctions() {
try {
new Function('(async function () {})()');
return true;
} catch (ex) {
return false;
}
}
module.exports = supportAsyncFunctions() ? require('./lib/client.js') : require('./es5/client.js');