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
# \W: Current dir | |
# \w: Path from home dir | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[00m\]\[\033[01;34m\][\w]\[\033[00m\] \$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\W \$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# If this is an xterm set the title to user@host:dir |
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
# Some useful bash aliases used by Vikram Negi | |
# navigation | |
alias ..="cd .." | |
# copy to clipboard (pipe sysin) | |
alias copy="xclip -selection clipboard" | |
# python | |
alias venv-init="python -m venv venv" |
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
"use strict"; | |
// ttl = time in ms | |
const setLocalData = (key, val, ttl) => { | |
const item = { | |
data: val, | |
expiry: new Date().getTime() + ttl | |
} |
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 updateInventory = (arr1, arr2) => { | |
const upInv = arr1.slice(); | |
for (const newItem of arr2) { | |
let found = false; | |
for (const curItem of arr1) { | |
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
def get_permutations(sequence): | |
''' | |
Enumerate all permutations of a given string | |
Returns: a list of all permutations of sequence | |
Example: | |
>>> get_permutations('abc') | |
['abc', 'acb', 'bac', 'bca', 'cab', 'cba'] | |
''' |
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
// divide the list into left & right | |
// keep dividing until only one element is left | |
function mergeSort(array) { | |
const half = Math.floor(array.length / 2); | |
if (array.length < 2) { | |
return array; | |
} | |
let left = array.splice(0, half); |
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 sym(...args) { | |
function filterRepeat(arr) { | |
const filteredList = []; | |
for (const n of arr) { | |
if (!filteredList.includes(n)) { | |
filteredList.push(n); | |
} | |
} |
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 largestPrimeFactor(num) { | |
let larFac = 0; | |
let count = 2; | |
while (count * count <= num) { | |
if (num % count === 0) { | |
num /= count; | |
larFac = count; | |
} else count++; | |
} | |
if (num > larFac) larFac = num; |