Skip to content

Instantly share code, notes, and snippets.

View Natumsol's full-sized avatar
🎯
Focusing

青岚 Natumsol

🎯
Focusing
View GitHub Profile
@Natumsol
Natumsol / withProps.js
Created August 14, 2019 08:29
withProps
import React from 'react';
// use forwardRef polyfills, preparing for future upgrades to React 16
import forwardRef from 'create-react-ref/lib/forwardRef';
const withProps = (defaultProps = {}) => Base => {
class WithRef extends React.Component {
render() {
const { forwardRef, ...rest } = this.props;
const mergedProps = { ...defaultProps, ...rest };
var list = [1, 1, 2, 3,3,3, 2, 1, 2, 1];
function parseList(result, node) {
if (result.length) {
const parent = result[result.length - 1];
if (parent.value < node) {
if (!parent.children)
parent.children = [];
parent.children = parseList(parent.children, node)
} else {
@Natumsol
Natumsol / copy.js
Last active September 24, 2018 14:55
复制文本到剪切板 #util
const copyToClipboard = input => {
const el = document.createElement('textarea');
el.value = input;
// Prevent keyboard from showing on mobile
el.setAttribute('readonly', '');
el.style.contain = 'strict';
el.style.position = 'absolute';
@Natumsol
Natumsol / is-plain-object.js
Last active September 17, 2018 09:26
check POJO(Plain Old Javascript Object)
/**
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
@Natumsol
Natumsol / getParams.js
Created December 20, 2017 05:50
获取url 查询参数
function getParams(url) {
var result = {};
url = decodeURI(url);
if (typeof url == "string" && url.indexOf("?") != -1) {
var params = url.match(/\?.*/)[0].trim().replace(/^\?/, "").split("&");
for (var i = 0; i < params.length; i++) {
var temp = params[i].split("=");
result[temp[0]] = temp[1];
}
}
@Natumsol
Natumsol / 0_reuse_code.js
Created August 1, 2017 12:23
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Natumsol
Natumsol / phantomjs_login.js
Created April 25, 2017 13:28
利用PhantomJS进行模拟登陆
var testindex = 0;
var loadInProgress = false;//This is set to true when a page is still loading
/*********SETTINGS*********************/
var webPage = require('webpage');
var page = webPage.create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36';
page.settings.javascriptEnabled = true;
page.settings.loadImages = false;//Script is much faster with this field set to false
phantom.cookiesEnabled = true;
@Natumsol
Natumsol / netEase_music_level_up.js
Created April 24, 2017 06:19
刷网易云音乐听歌量...
/**
* 作者:Alexa
* 链接:https://www.zhihu.com/question/40207029/answer/159826450
* 来源:知乎
* 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
*/
var Music163 = {};
Music163.Send = function (index, count) {
var bd = NEJ.P,
cg = NEJ.O,
@Natumsol
Natumsol / upperFirstChar.js
Created April 14, 2017 01:27
将句子中单词首字母大写
function upperFirstChar(str) {
// replace的第二个参数可以为函数,第一个为匹配到的字符串,第二个为匹配在原字符串中的索引,第三个为原字符串
return str.replace(/\w+/g, function(match, offset, string){
return match[0].toUpperCase() + match.slice(1);
});
}
console.log(upperFirstChar(" hello, world my World hehe"));