Skip to content

Instantly share code, notes, and snippets.

View maxlath's full-sized avatar

maxlath maxlath

View GitHub Profile
@maxlath
maxlath / convert_exports_default_object.js
Created January 7, 2023 14:58
Convert `exports defaults { someFunction }` to `export function someFunction {}`
#!/usr/bin/env node
// Convert a modules on the pattern
// export default {
// fnAName: (bla) => {},
// fnBName: (bla) => {},
// }
// to
// export const fnAName = (bla) =>
// export const fnBName = (bla) =>
@maxlath
maxlath / userChrome.css
Last active October 12, 2021 15:33
Hide "Firefox suggests" text in Firefox 93 search menu
/*
Create or edit userChrome.css in your Firefox profile folder,
typically found on Linux at ~/.mozilla/firefox/[your firefox profile folder]/chrome/userChrome.css
*/
.urlbarView-row[label]{
margin-block-start: 0 !important;
}
.urlbarView-row[label]::before{
@maxlath
maxlath / wd_config_from_environment
Created September 3, 2021 20:54
Setup Wikidata OAuth credentials for wikibase-cli from environment variables
#!/usr/bin/env bash
# Assuming that the workflow yaml file sets the following
# env:
# WD_CONSUMER_KEY: ${{ secrets.WD_CONSUMER_KEY }}
# WD_CONSUMER_SECRET: ${{ secrets.WD_CONSUMER_SECRET }}
# WD_TOKEN: ${{ secrets.WD_TOKEN }}
# WD_TOKEN_SECRET: ${{ secrets.WD_TOKEN_SECRET }}
echo "{
@maxlath
maxlath / handlebars2svelte.js
Last active March 15, 2024 01:27
Convert a Handlebars template to Svelte
#!/usr/bin/env node
// Handlebars and Svelte templates are quite similar (that is, looking a lot like plain HTML),
// so converting from Handlebars to Svelte is mostly a matter of converting handlebars helpers argument syntax
// into Svelte JS-based syntax, and importing the helper functions.
// WARNING: if you have been using named arguments in Handlebars (a.k.a. 'hash' arguments),
// the helper function interface will need to be updated (or the arguments passed as `{ hash: argsObject }`)
// STATUS: WIP.
@maxlath
maxlath / inv_add_publisher.sh
Last active January 13, 2021 20:30
add publishers to editions on inventaire.io using curl
# Use your username and password to get session cookies
INV_USERNAME=foo
INV_PASSWORD=bar
INV_SESSION_COOKIES=$(curl -v 'https://inventaire.io/api/auth?action=login' -d "{\"username\":\"$INV_USERNAME\",\"password\":\"$INV_PASSWORD\"}" 2>&1 | grep 'Set-Cookie: inventaire:session' | awk '{print $3}' | xargs echo)
add_claim(){
uri=$1
property=$2
value=$3
curl -s -XPUT "https://inventaire.io/api/entities?action=update-claim" -H "Cookie: $INV_SESSION_COOKIES" -H "Content-Type: application/json" -d "{\"uri\":\"${uri}\",\"property\":\"${property}\",\"new-value\":\"${value}\"}"
@maxlath
maxlath / update_commit_previous_hashes_list
Last active October 30, 2020 12:47
Keep a list of the hashes by which a commit was previously known
#!/usr/bin/env sh
# A script to keep a list of the hashes by which a commit was previously known
# Adapted from https://stackoverflow.com/a/54352290/3324977
# Installation:
# - copy this script to a directory in your $PATH
# - make it executable:
# chmod +x ./update_commit_previous_hashes_list
# - it should now be accessible from any directory, which can be checked like this:
@maxlath
maxlath / branches-diff
Last active August 31, 2020 15:39
Display changes made to a file in all the active branches
#!/usr/bin/env bash
# Display changes made to a file in all the active branches
if [[ $1 == "" ]] ; then
echo "branches-diff <files...|folders...>"
exit 1
fi
branches_on_origin_remote_with_last_commit_less_than_a_year_ago(){
# Initialize the array of favs
source ~/.favs
# Create an alias for each of the favs
for key in $favs
do
directory="$favs[$key]"
alias $key="cd $directory"
done
@maxlath
maxlath / test_sorting.js
Last active February 23, 2020 13:25
testing performance of sorting with or without pre-sorting
#!/usr/bin/env node
// Environment
// ------------------
// NodeJS: v12.14.0
// CPU: 2.50GHz
// arrays length = 1000 (that is, sorting 1000^2 elements)
// Results
// ------------------
@maxlath
maxlath / decaffeinate_cleanup.js
Last active November 10, 2019 21:37
completing bulk-decaffeinate and eslint --fix
#!/usr/bin/env node
// To be run after bulk-decaffeinate is done
// bulk-decaffeinate convert --num-workers 8 --config ~/bulk-decaffeinate.config.js
// cleanup(){
// decaffeinate_cleanup.js "$@" && npm run lint-fix "$@"
// }
//
// cleanup **/*.js