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 bubbleSort(nums){ | |
if (!nums) return; | |
for(let i = 0;i < nums.length; ++i){ | |
for(let j = 0;j < nums.length-1; ++j) { | |
if (nums[j] > nums[j+1]) { | |
let tmp = nums[j]; | |
nums[j] = nums[j+1]; | |
nums[j+1] = tmp; | |
} |
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 permuate(seq) { | |
if (seq.length === 0) return [[]]; | |
const solutions = []; | |
for(let i = 0; i < seq.length; ++i){ | |
const subSolutions = permuate(seq.filter((num, j) => j !== i)); | |
subSolutions.forEach(solution => solutions.push([seq[i]].concat(solution))); | |
} | |
return solutions; | |
} |
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
### linux | |
# find biggest top 10 files or folders in current dir | |
du -a -h | sort -n -r | head -n 10 | |
# find runing process | |
# example args: | |
# process_name: nginx | |
ps -ax | grep {{process_name}} | |
### docker |
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 duplicate(arr){ | |
let set = new Set(); | |
let result = []; | |
for(let i = 0;i < arr.length; ++i) { | |
if(!set.has(arr[i])) result.push(arr[i]); | |
set.add(arr[i]); | |
} | |
return result; | |
} |
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 debounce(fn, delay) { | |
let timer = setTimeout(fn, delay); | |
return function(){ | |
clearTimeout(timer); | |
fn.apply(this, arguments); | |
}; | |
} | |
function throttle(fn, delay) { | |
let timer = setTimeout(fn, delay); |
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
// the router should be sigleton | |
class Router { | |
constructor(routeMap) { | |
this._routeMap = routeMap; | |
this.bindEvent(); | |
} | |
init(url) { | |
let fn = this._routeMap[url]; | |
window.history.replaceState({url: url}, '', url); |
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 binarySearch(nums, target) { | |
let i = 0, j = nums.length - 1; | |
while (i <= j) { | |
const mid = (i + j) >> 1; | |
if (nums[mid] === target) return mid; | |
else if (nums[mid] > target) j = mid; | |
else i = mid + 1; | |
} | |
return -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
[*] | |
end_of_line = lf | |
insert_final_newline = true | |
charset = utf-8 | |
indent_style = space | |
indent_size = 2 | |
[Makefile] | |
indent_style = tab |
OlderNewer