Skip to content

Instantly share code, notes, and snippets.

@KR1470R
KR1470R / file-renamer.sh
Last active May 7, 2022
Use this script to massive file renaming or conservation(as copy prefix in name of file) files in specific directory
View file-renamer.sh
#!/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 / okular-docdata-restore.sh
Last active May 7, 2022
This script actually used for massive changing name and url of ~/.local/share/okular/docdata/*.pdf.xml files
View okular-docdata-restore.sh
#!/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 / okular-bookmarks-restore.sh
Last active May 7, 2022
This script actually used for multiline replacing href in ~/.local/share/okular/bookmarks.xml
View okular-bookmarks-restore.sh
#!/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
View selection_sort.js
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 / factorial.js
Created Jul 12, 2020
Factorial Quick-Simple Way
View factorial.js
let facrorial = number=>{
let f = 1
let i = 1
while (i<number){
i+=1
f = f*i
}
return f
}
let res = facrorial(5)
View bubble_sort.js
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
}
}
}
}
View binary_search.js
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){