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
| # 如何使用正则表达式从下面的URL中提取字符串“ XMLFileName” | |
| ## 可以使用split(),pop()和replace() ... | |
| ```JavaScript | |
| var x = "C:\\Documents and Settings\\Dig\\Desktop\\XMLFileName.xml"; | |
| var filename = x.split('\\').pop().replace(/\..+$/, ''); | |
| console.log(filename) | |
| ``` | |
| [jsbin](https://jsfiddle.net/h8uK6) | |
| ## 也可以使用单个正则表达式 |
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
| ```css | |
| input[type="search"]::-webkit-search-cancel-button { | |
| -webkit-appearance: none; | |
| height: 16px; | |
| width: 16px; | |
| background: url(https://yxs-web.oss-cn-beijing.aliyuncs.com/328e4d97f9d0d68ea04e872f68e508e3.png) no-repeat; | |
| background-size: contain; | |
| } | |
| ``` | |
| 更改placeholder |
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
| //统计数组中有多少个重复的单词: | |
| // let counts = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0); | |
| // console.log('数组counts中"李"出现的次数是:' + counts(["李", "李", "设", "弟", "弟", "生", "生", "李"], "李")); | |
| // 不用reduce时: | |
| /** | |
| * 统计数组中有多少个重复的单词 | |
| * @param {Array} array 待分页的数组 | |
| * @return {Object} 统计后的对象 | |
| */ | |
| function getRepeatNum(array) { |
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
| # js | |
| ```JavaScript | |
| let arr= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] | |
| function pagination (currentPage, pageSize, array) { | |
| const skipNum = (currentPage - 1) * pageSize; | |
| return (skipNum + pageSize >= array.length) ? array.slice(skipNum, array.length) : array.slice(skipNum, skipNum + pageSize) | |
| } | |
| console.log(pagination(2,4,arr)) | |
| ``` | |
| # ts |
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
| # Base64/hex | |
| Base64与hex都是将二进制数据编码成字符串的编码方式,针对的是二进制字节而非字符串。 | |
| 因此,要获得某个string的base64编码时,应该先得到string的二进制,再对二进制进行base6编码: | |
| ```JavaScript | |
| // 编码 | |
| const str = '哈哈' | |
| let b = Buffer.from(str) // b中存的是哈哈的utf8编码二进制 | |
| let base64Code = b.toString('base64') // '5ZOI5ZOI' | |
| // 解码 | |
| const code = '5ZOI5ZOI' |
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
| ```JavaScript | |
| const arr = [{id: 1, value : "value1", date: "2018-08-08", time: "15:27:17"}, | |
| {id: 2, value : "value2", date: "2018-08-09", time: "12:27:17"}, | |
| {id: 3, value : "value3", date: "2018-08-10", time: "17:27:17"}, | |
| {id: 4, value : "value4", date: "2018-08-10", time: "01:27:17"}, | |
| {id: 5, value : "value5", date: "2018-08-10", time: "09:27:17"}, | |
| {id: 6, value : "value6", date: "2018-08-10", time: "23:27:17"}, | |
| {id: 7, value : "value7", date: "2018-08-10", time: "16:27:17"}, | |
| {id: 8, value : "value8", date: "2018-08-11", time: "10:27:17"} | |
| ]; |
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
| # 第一种 | |
| ```JavaScript | |
| const fs = require('fs') | |
| const path = require('path'); | |
| /** | |
| * 遍历目录里面的所有文件和目录 (同步) | |
| * @param {String} dir 目录名 | |
| * @param {Function} callback 找到一个文件时的回调 | |
| */ |
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
| # 同步遍历 | |
| ```JavaScript | |
| const fs = require('fs'); | |
| const path=require('path'); | |
| function travel(dir,callback){ | |
| fs.readdirSync(dir).forEach((file)=>{ | |
| var pathname=path.join(dir,file) | |
| if(fs.statSync(pathname).isDirectory()){ | |
| travel(pathname,callback) | |
| }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
| # 课程介绍 | |
| 正处于春招的黄金时期,为了帮助大家找到更好的工作,更快的找到工作。组织本次的专项课程。 | |
| 今日的课程主题是 **项目**,会讲到公司项目研发的流程。 |
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
| ```bash | |
| ::定时关机脚本 | |
| ::Author:Tony Chang | |
| ::2016.10.18 | |
| ::原创代码,转载请注明出处 | |
| @echo off | |
| mode con lines=25 | |
| setlocal enabledelayedexpansion | |
| title 定时关机 | |
| color 0a |