This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch | grep -v "master" | xargs git branch -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch -r --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do | |
git branch --track "${branch##*/}" "$branch" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(''); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |