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 group = (arr = [], length = 2) => { | |
| if (length > arr.length) return; | |
| const newArr = arr.slice(); | |
| const returnArr = []; | |
| while (newArr.length > length) { | |
| const values = newArr.splice(0, length); | |
| returnArr.push(values); | |
| } | |
| returnArr.push(newArr); | |
| return returnArr; |
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 compose = (...fns) => arg => | |
| fns.reduce((composed, fn) => fn(composed), arg); | |
| const toUpper = str => str.toUpperCase(); | |
| const splitWithSign = sign=>str=>str.split(sign); | |
| const newStrs = compose(toUpper,splitWithSign('|'))('a|bc'); | |
| console.log(newStrs) |
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
| import elasticsearch from 'elasticsearch'; | |
| import config from '../config'; | |
| import proxy from 'proxy-agent'; | |
| const client = new elasticsearch.Client({ | |
| host: 'my.host.com', | |
| createNodeAgent: () => proxy("http://localhost:8888") | |
| }); |
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
| (async () => { | |
| const arrs = [1, 2, 1, 5, 6, 4, 8, 9, 10, 15]; | |
| for (let i = 0; i < 4; i++) { | |
| const delays = arrs | |
| .splice(0, 3) | |
| .map( | |
| delay => | |
| new Promise(resolve => | |
| setTimeout(() => resolve(delay), delay * 1000) | |
| ) |
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 split = (sign = '/') => (str = '') => { | |
| if (!str.includes(sign)) return str.trim(); | |
| const arr = str.split(' '); | |
| const signIndex = arr.findIndex(a => a.includes(sign)); | |
| const scrapeStr = arr.slice(0, signIndex).join(' '); | |
| const splits = arr[signIndex].split(sign); | |
| const sliced = arr.slice(signIndex + 1).join(' '); | |
| const strs = []; | |
| for (const s of splits) { | |
| s && strs.push(split(sign)(`${scrapeStr} ${s} ${sliced}`)); |
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 puppeteer = require('puppeteer'); | |
| (async () => { | |
| const browser = await puppeteer.launch({ headless: false }); | |
| const page = await browser.newPage(); | |
| const prePageSelector = '.btn-group-paging a:nth-child(2)@href'; | |
| const listSelector = '.r-ent'; | |
| const titleSelector = '.title a'; | |
| const titleLinkSelector = '.title a@href'; | |
| const authorSelector = '.meta .author'; | |
| const dateSelector = '.meta .date'; |
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 options= { | |
| index:'index1', | |
| scroll: '2m', | |
| type:'test', | |
| allowNoIndices: true, | |
| ignoreUnavailable: true, | |
| body: { | |
| size: 100, | |
| from: 0 | |
| } |
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 arrToObj=([key,value])=>({[key]:value}); | |
| console.log(arrToObj(['aa','aa'])); //{aa:'aa'} |
NewerOlder