Skip to content

Instantly share code, notes, and snippets.

@arikw
arikw / events.js
Created July 24, 2023 19:10
A helper utility for triggering a callback when events will be triggered or were already triggered
/**
* Triggers a callback function when all the specified events are validated as completed.
* @param {Object[]} eventsWithValidators - An array of objects containing the event name, event target and status checker function for each event.
* @param {string} eventsWithValidators[].eventName - The name of the event to listen for.
* @param {EventTarget} [eventsWithValidators[].eventTarget=window] - The object that emits the event. If not specified, window will be used as the default event target.
* @param {Function} eventsWithValidators[].statusChecker - A function that returns a boolean value indicating whether the event is completed or not.
* @param {Function} callback - The function to execute when all the events are completed.
* @example
* runWhenEventsCompleted([
{ eventName: 'load', statusChecker: () => document.readyState === 'complete' },
@arikw
arikw / apps.md
Last active July 22, 2022 10:27
Gnome Shell Extension Snippets

Icon per browser profile

The goal was to make chromium desktop icon, that was created for a second profile, appear in the Dash and the app switcher (alt+tab) as an independent app icon. I gave that .desktop a StartupWMClass entry and added a --class flag as suggested here, but the problem remained because I believe that chromium changes the wm class name to the default one after the launch. Tried to fiddle with some code via looking glass, but no success there.

For reference, I used the following functions:

imports.gi.Shell.AppSystem.get_default() // Shell.AppSystem (https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/src/shell-app-system.c)
imports.gi.Shell.AppSystem.get_default().get_running() // [ Shell.App ] (https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/src/shell-app.c)
@arikw
arikw / flat-promise-using-non-strict-mode.md
Created September 12, 2021 07:47
A proof-of-concept: How to create a promise that calls the rest of the code without wrapping it with an executor function

A proof-of-concept: How to create a promise that calls the rest of the code without wrapping it with an executor function

function promised(callerArgs) {
  const caller = callerArgs.callee;
  if (!caller.resolve) {
    return {
      promise: new Promise((resolve, reject) => {

        caller.resolve = resolve;
@arikw
arikw / copy-file-permissions.sh
Last active September 23, 2021 12:33
Fedora snippets
# change the following variables:
export SRC=/home/arik/.config/microsoft-edge-beta-original;
export DEST=/home/arik/.config/microsoft-edge-beta;
# remove access to all non current user
chmod go-rwx $DEST/*;
# copy file permissions
cd $SRC;
find * -exec sh -c 'eval $(stat -c "chmod %a $DEST/%N" "$0")' {} \;
@arikw
arikw / docker-snippets.md
Last active April 26, 2021 09:52
Docker snippets

Check if a context name exists (replace $CONTEXT_NAME)

  [ -n "$(docker context ls --format '{{ index .Name }}' | grep -w $CONTEXT_NAME)" ]
@arikw
arikw / dm
Last active October 23, 2019 20:54
docker-machine command with default machine name
#!/bin/bash
set -euo pipefail
MACHINE_NAME=$(printf "%q" ${DOCKER_MACHINE_NAME:-null})
if [ "$MACHINE_NAME" == "null" ]; then
echo "Error: No docker machine env variables are set"
exit -1;
fi
DM_SPECIAL_COMMANDS=(
@arikw
arikw / main-lang-by-country.json
Created May 9, 2016 15:41
A single main language per country. Useful when a fallback language is needed for web visitors. The country can be extracted from their ip (e.g., using maxmind).
{
"af": {
"countryName": "Afghanistan",
"langName": "Pashto",
"countryCodes": {
"iso3166_1": "af",
"GEC": "af"
},
"langCodes": {
"iso639_1": "ps"