This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Getting a random integer between two values, inclusive | |
* @param {number} min | |
* @param {number} max | |
* @return {number} | |
*/ | |
export const getRandomIntInclusive = (min, max) => { | |
min = Math.ceil(min) | |
max = Math.floor(max) | |
return Math.floor(Math.random() * (max - min + 1)) + min |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function object(o) { | |
const F = function() {}; | |
F.prototype = o; | |
return new F(); | |
} | |
function extend(Child, Parent) { | |
var prototype = object(Parent.prototype); | |
prototype.constructor = Child; | |
Child.prototype = prototype; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exampleValues = [2, 15, 8, 23, 1, 32]; | |
const [truthyValues, falseyValues] = exampleValues.reduce((arrays, exampleValue) => { | |
if (exampleValue > 10) { | |
arrays[0].push(exampleValue); | |
return arrays; | |
} | |
arrays[1].push(exampleValue); | |
return arrays; | |
}, [[], []]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Cache = { | |
setCache (key, val) { | |
if (!this.isIncognitoMode()) { | |
if (val === null) { | |
localStorage.removeItem(key) | |
} else { | |
localStorage.setItem(key, JSON.stringify(val)) | |
} | |
} else { | |
// 兼容隐身模式 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
from workflow import Workflow3, web | |
# Python2.5 初始化后会删除 sys.setdefaultencoding 这个方法,我们需要重新载入 | |
reload(sys) | |
sys.setdefaultencoding('utf-8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set MOGU_URL to "https://www.mogujie.com/" | |
set LOGIN_URL to "https://portal.mogujie.com/user/newlogin" | |
global TOGGLE_SELECTOR | |
global USERNAME_SELECTOR | |
global PASSWORD_SELECTOR | |
global LOGIN_BTN_SELECTOR | |
set WELCOME_SELECTOR to "#header > div.wrap.header-wrap.clearfix > div.search-nav-content.clearfix > div.site-top-nav.J_sitenav > div > div.header-user-info.fr" | |
set TOGGLE_SELECTOR to "#qrcode-wrapper > div.toggle-regular" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Array<any>} arr | |
*/ | |
function flatten(arr) { | |
return arr.reduce((flat, toFlatten) => { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten) | |
}, []) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 跳转 | |
window.location.replace('https://www.awesomes.cn') // 不将被跳转页面加入浏览器记录 | |
window.location.assign('https://www.awesomes.cn') | |
window.location.href = 'https://www.awesomes.cn' | |
window.location = 'https://www.awesomes.cn' | |
// 返回上一页 | |
window.history.back() | |
window.history.go(-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(win, lib) { | |
var doc = win.document; | |
var docEl = doc.documentElement; | |
var metaEl = doc.querySelector('meta[name="viewport"]'); | |
var flexibleEl = doc.querySelector('meta[name="flexible"]'); | |
var dpr = 0; | |
var scale = 0; | |
var tid; | |
var flexible = lib.flexible || (lib.flexible = {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取表单数据对象 | |
* | |
* @param {HTMLFormElement | string} form | |
* @return {object} | |
*/ | |
export const getFormData = form => { | |
let data = {} | |
const kvObjArray = $(form).serializeArray() |