Skip to content

Instantly share code, notes, and snippets.

View SamadiPour's full-sized avatar
❤️
Love Coding

Amir Hossein SamadiPour

❤️
Love Coding
View GitHub Profile
@SamadiPour
SamadiPour / script.sh
Created February 19, 2023 14:50
Download the most recent release from GitHub using the checksum - only for releases that have a sha256 file in their release section.
#!/bin/bash
url="https://github.com/<owner>/<repo>/releases/latest/download/<file_name_with_extension>"
current_file="<filename>.<extension>"
if [ -f "$current_file" ]; then
new_checksum=$(curl -L "$url.sha256" | cut -d " " -f 1)
current_checksum=$(shasum -a 256 "$current_file" | cut -d " " -f 1)
# Compare the two checksums
@SamadiPour
SamadiPour / main.js
Last active May 27, 2024 07:23
ADSL TCI plan sorter
const planCards = document.querySelectorAll('#service-list .uk-card');
const cardDetails = [];
function convertPersianNumbersToEnglish(text) {
return text.replace(/[۰-۹]/g, (char) => String.fromCharCode(char.charCodeAt(0) - '۰'.charCodeAt(0) + '0'.charCodeAt(0)));
}
planCards.forEach(card => {
const title = convertPersianNumbersToEnglish(card.querySelector('.uk-card-title').textContent.trim());
const description = convertPersianNumbersToEnglish(card.querySelector('.uk-card-body p').textContent.trim());
@SamadiPour
SamadiPour / script.sh
Last active November 30, 2023 11:32
Localisation file sorting
# Sort first by Word Count and then Characters count - only if it's is <String, String>
jq 'to_entries | map({ key: .key, value: .value, word_count: (.value | split(" ") | length), char_count: (.value | length) }) | sort_by(.word_count, .char_count) | from_entries' en.json > sorted_en.json && mv sorted_en.json en.json
# Sort first by Word Count, then by Characters count, and then alphabetical - skips collections that are at end
jq '. | to_entries | reduce .[] as $entry ( {}; if $entry.value | type == "object" then .collections += [$entry] else .non_collections += [$entry] end ) | (.non_collections | map({ key: .key, value: .value, word_count: (.value | split("\n") | map(split(" ")) | map(length) | add), char_count: (.value | length) }) | sort_by(.word_count, .char_count, .key)) + .collections | from_entries' en.json > sorted_en.json && mv sorted_en.json en.json