Skip to content

Instantly share code, notes, and snippets.

View KartaviK's full-sized avatar
📟
Do some stuff

Roman Varkuta KartaviK

📟
Do some stuff
View GitHub Profile
@KartaviK
KartaviK / implode.sh
Created January 17, 2020 08:13
Implode array of items using given separator
function implode() {
local IFS="${1}";
shift;
echo "${*}";
}
echo $(implode ${1} ${@:2})
@KartaviK
KartaviK / index_of.sh
Last active June 13, 2022 22:18
Function to get index of needs element in array
#!/bin/bash
function index_of() {
index=0;
for arg in ${@:2}; do
index=$((index + 1))
if [[ ${1} == ${arg} ]]; then
echo ${index};
break;
fi
done
@KartaviK
KartaviK / remaining.js
Created October 29, 2019 12:40
Calculate remaining days to next month
function remainingDays(date) {
let time = new Date(date.getTime());
time.setMonth(date.getMonth() + 1);
time.setDate(0);
return time.getDate() > date.getDate() ? time.getDate() - date.getDate() : 0;
}
@KartaviK
KartaviK / separateDaysByWeek.js
Created October 29, 2019 12:17
Separating days number on weeks
/**
* Separating days by week with init day setting
*
* @param days
* @param initDay
* @param initWeekDay
* @returns {Array[]}
*/
function separateDaysByWeek(days, initDay, initWeekDay = 0) {
let result = [[]];
@KartaviK
KartaviK / groupify.js
Last active November 19, 2019 22:47
Group your array by multiple keys with comparing customization!
/**
* Group your items in array by multiple keys!
*
* @param collection
* @param retrieveFunctions
* @param compareFunctions
* @returns {Array}
*/
function groupify(
collection,
@KartaviK
KartaviK / in-page-search.jquery.js
Last active October 15, 2019 09:33
Searching substring in sub-nodes of exist collection htmlnode elements
/**
* Simple usage:
* Initing:
* $.search.init(
* '.node' // Selector of elements
* ['.inner_title', 'description', 'comments'], // Colelciton of selectors where is need to search substring,
* 'search-ui', // Name of data attribute to write index of element to search and state
* 'search-highlight' // Name of class for highlighting of find substrings
* );
* Searching:
@KartaviK
KartaviK / gist:ba2fcaf77cf2ead60dcf6a095be0b74f
Created April 24, 2019 16:29
add_user_to_docker_sock.sh
sudo chown $USER:docker /var/run/docker.sock
@KartaviK
KartaviK / UkrainianPassportRegex.txt
Last active October 17, 2018 12:32
Perfect for ukrainian passport validation
clean regex:
^[ыЫа-яА-Яa-zA-ZіІєЄґҐїЇ]{2}\d{6}$
php:
/^[ыЫа-яА-Яa-zA-ZіІєЄґҐїЇ]{2}\d{6}$/u