Skip to content

Instantly share code, notes, and snippets.

View lostvikx's full-sized avatar
Focus

Vikram Negi lostvikx

Focus
View GitHub Profile
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;
function sym(...args) {
function filterRepeat(arr) {
const filteredList = [];
for (const n of arr) {
if (!filteredList.includes(n)) {
filteredList.push(n);
}
}
// 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);
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']
'''
const updateInventory = (arr1, arr2) => {
const upInv = arr1.slice();
for (const newItem of arr2) {
let found = false;
for (const curItem of arr1) {
@lostvikx
lostvikx / localStorageExpiry.js
Created January 29, 2022 19:05
Use local storage with expiry.
"use strict";
// ttl = time in ms
const setLocalData = (key, val, ttl) => {
const item = {
data: val,
expiry: new Date().getTime() + ttl
}
@lostvikx
lostvikx / bash_aliases.sh
Created February 7, 2023 13:12
Personal list of bash aliases.
# Some useful bash aliases used by Vikram Negi
# navigation
alias ..="cd .."
# apt packages
alias sysup="sudo apt update && apt list --upgradable && sudo apt upgrade"
# flatpak packages
alias flatup="flatpak update"
@lostvikx
lostvikx / bash_prompt.sh
Created February 7, 2023 13:14
A custom minimal bash prompt.
# \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