Skip to content

Instantly share code, notes, and snippets.

View KR1470R's full-sized avatar
🇺🇦
fuck russia

KR1470R

🇺🇦
fuck russia
View GitHub Profile
@KR1470R
KR1470R / binary_search.js
Created July 12, 2020 07:30
Binary search
let arr = [3,4,15,17,20,23,24,31,33,37,40,51,54]
function binary_search(a,e){
let high = a.length-1
let mid = 0
let low = 0
while (low <= high) {
mid = Math.floor((low+high)/2)
if (a[mid] === e){
return arr[mid]
}else if (a[mid] < e){
@KR1470R
KR1470R / bubble_sort.js
Created July 12, 2020 07:31
Bubble sort
let arrJertva = [5,3,1,2]
let bubble_sort = arr=>{
for (let i=1,n=arr.length;i<n;i++) {//make bubble
for (let j=1;j<n;j++) { //iterate every element in bubble
if (arr[j] < arr[j-1]) {
[arr[j],arr[j-1]] = [arr[j-1],arr[j]] // swaping elements if they equally of condition
}
}
}
}
@KR1470R
KR1470R / factorial.js
Created July 12, 2020 07:32
Factorial Quick-Simple Way
let facrorial = number=>{
let f = 1
let i = 1
while (i<number){
i+=1
f = f*i
}
return f
}
let res = facrorial(5)
@KR1470R
KR1470R / selection_sort.js
Created July 12, 2020 07:32
Selection sort
let arr1 = [8,5,9,1,6,0,2]
const selectionSort = arr => {
for (let i=0;i<arr.length;i++){
let min = i ///// choose first number
for (let j=i+1;j<arr.length;j++){ ///// iterate all array
if (arr[min] > arr[j]){
min = j ///////////////////// switching indexs if current iteration less current min number
}
}
if (min !== i){
@KR1470R
KR1470R / okular-bookmarks-restore.sh
Last active May 7, 2022 14:22
This script actually used for multiline replacing href in ~/.local/share/okular/bookmarks.xml
#!/usr/bin/env sh
echo ${1:?Destination path is not specified}
export lines=$(cat $1 | egrep '<folder href|<bookmark href')
export IFS=$(printf '>')
# sed -i 's,link,new-link,g' $1
function main () {
for line in $lines; do
# echo "Current line>"$line
@KR1470R
KR1470R / okular-docdata-restore.sh
Last active May 7, 2022 14:23
This script actually used for massive changing name and url of ~/.local/share/okular/docdata/*.pdf.xml files
#!/usr/bin/env sh
echo ${1:?Destination path is not specified}
export filenames=$(ls -1 $1)
export IFS=$'\n'
function main () {
export previus_href
export previus_input
@KR1470R
KR1470R / file-renamer.sh
Last active May 7, 2022 14:25
Use this script to massive file renaming or conservation(as copy prefix in name of file) files in specific directory
#!/usr/bin/env sh
trap 'echo "Usage: $0 path/to/folder {copy|replace} \"old_name|new_name\""' 0
export path=${1?"File to path wasn't specified!"};shift
export status=${1?"Status wasn't specified!"};shift
if [[ -z "$@" ]]; then
echo "Name files wasn't specified!"
exit 1
else
# exmpl "name1part1 name1part2|name2part1 name2part2"
@KR1470R
KR1470R / vscodium-update
Last active March 20, 2023 08:54
Update VSCodium with custom tar.gz updates.
#!/bin/sh
set -e
if [ -z "$1" ] || ! [ -e "$1" ]; then
printf "\e[31mHave nothing from update.\e[0m\n\n"
exit 1
fi
DEFAULT_VSCODIUM_PATH="/usr/share/vscodium"
if [ -z "$2" ] || ! [ -d "$2" ]; then
@KR1470R
KR1470R / findFreePort.ts
Created April 15, 2023 07:24
Node.js get any available port
import net from "node:net";
const port_constraints = {
min: 1024,
max: 65535,
};
/**
* @param ip Host ip (default localhost)
* @param minPort Min available port (default 1024)
* @param maxPort Max available port (default 65535)
@KR1470R
KR1470R / cv-files-corrector.py
Last active August 31, 2023 08:17
CV Type file corrector
###########################################################################################
#################################### Requirements #####################################
# Python version 3.10 and newest(didn't tested on older versions)
# pip install python-magic
#################################### How does it work #####################################
# Traverses through files in specified directory, checking the metadata of each file:
# - if file type is not pdf/docx/doc/txt - REMOVES it,
# - if extension file different from the type in metadata(pdf/docx/doc/txt) - RENAMES it.
#################################### How to Run #####################################
# 1. save the script to your system.