Skip to content

Instantly share code, notes, and snippets.

View kostandy's full-sized avatar
🎯
Focusing

Dmytro Andriushchenko kostandy

🎯
Focusing
View GitHub Profile
@kostandy
kostandy / binarySearch.js
Created January 11, 2021 11:46
The binary search algorithm realization with randomized array generation & performance measurements tracking
const binarySearch = (list = [1, 2, 3, 4, 5, 6, 7, 8, 9], searchableValue = 4) => {
let low = 0,
high = list.length - 1;
while (low <= high) {
let middle = Math.floor(low + (high - low) / 2);
if (list[middle] < searchableValue) {
low = middle + 1;
} else if (list[middle] > searchableValue) {
@kostandy
kostandy / removeLocalBranches.txt
Created October 7, 2019 09:56
Remove all local branches except 'master'
git branch | grep -v "master" | xargs git branch -D
@kostandy
kostandy / removeMergedBranches.txt
Created October 7, 2019 09:14
Remove checkout branches which were merged to master from remote origin (be careful!)
git branch -r --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin
@kostandy
kostandy / checkoutAll.sh
Created October 7, 2019 09:12
Checkout all branches from Git repo
#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
// Make it simple to swap parts of a URL attribute on an element
function updateAttributeURL(element, attr, swapOut, swapIn) {
var url = element.getAttribute(attr);
url = url.replace(swapOut, swapIn);
element.setAttribute(attr, url);
}
// Update the image source on elements in the picture element
function loadImage(picture) {
@kostandy
kostandy / jsonMetric.js
Last active July 5, 2019 08:38
The performance metric of JSON handling
function jsonReturner() {
return [
{
"albumId": 1,
"id": 1,
"title": "accusamus beatae ad facilis cum similique qui sunt",
"url": "https://via.placeholder.com/600/92c952",
"thumbnailUrl": "https://via.placeholder.com/150/92c952"
},
{
@kostandy
kostandy / recursiveSum.js
Last active April 26, 2019 09:48
Recursive sum of array of numbers
const sum = arr => {
return arr.length ? arr[arr.length - 1] + sum(arr.splice(1)) : 0;
}
const arr = [1, 2, 3, 4, 5, 6, 7];
sum(arr); // 49
export default sum;
@kostandy
kostandy / rot13.js
Created March 5, 2019 09:06
ROT13 replaces each letter by its partner 13 characters further along the alphabet. For example, HELLO becomes URYYB (or, conversely, URYYB becomes HELLO again). Read more - https://en.wikipedia.org/wiki/ROT13
const rot13 = message => {
const a = message.split('');
return a.map(s => {
const c = s.charCodeAt();
if (c <= 65 || c >= 123 || s === ' ') return s;
return String.fromCharCode(
c <= 78 && c < 90 || c >= 97 && c < 110 ? c+13 : c-13
);
}).join('');
}
@kostandy
kostandy / FileRename.js
Last active August 14, 2018 14:55
This little script allow you rename files in folder by list of names from any file which contains text
const fs = require('fs'); // Include File System Module to project
let listOfNames; // Initialization of variable
let pathToListOfNames = './example.txt'; // Path to text file with list of names
let pathToFiles = './media/images'; // Path to files which need to rename
let formatFiles = 'jpg'; // Specify your image format (Example: jpg, png, gif, etc.)
try {
listOfNames = fs.readFileSync(pathToListOfNames, 'utf-8')
.split('\n'); // Reading a file by strings and splitting it into an array by '\n'