Skip to content

Instantly share code, notes, and snippets.

View mnikn's full-sized avatar
🕳️
Strike the earth

mnikn mnikn

🕳️
Strike the earth
  • earth
View GitHub Profile
@mnikn
mnikn / cookie.js
Last active February 27, 2019 01:40
[cookie] web cookie utils #utils
@mnikn
mnikn / sort.js
Last active February 25, 2019 08:37
[sort] sort algorithms #algorithm
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;
}
@mnikn
mnikn / permutation.js
Last active June 19, 2019 09:42
[permutation] permutation and combination algorithm #algorithm
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;
}
@mnikn
mnikn / bash.sh
Last active July 29, 2019 01:46
[bash] linux bash common commands #linux
### 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
@mnikn
mnikn / array.js
Last active September 30, 2023 03:17
[array] array utils #utils
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;
}
@mnikn
mnikn / debounce.js
Created February 27, 2019 01:48
[debounce] debounce and throttle #utils
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);
@mnikn
mnikn / router.js
Last active April 18, 2020 05:19
[router] a simple web router #utils
// 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);
@mnikn
mnikn / search.js
Last active June 19, 2019 07:09
[search] search algorithm #algorithm
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;
}
@mnikn
mnikn / ctags
Last active August 26, 2019 14:42
[ctags]
--recurse=yes
--tag-relative=yes
--exclude=tags
--exclude=TAGS
--exclude=GTAGS
--exclude=GPATH
--exclude=*node_modules*
--exclude=*.git*
@mnikn
mnikn / editorconfig
Created August 27, 2019 23:35
[editorconifg]
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab