Skip to content

Instantly share code, notes, and snippets.

@mijorus
mijorus / imwheel-gui.sh
Last active September 1, 2021 21:25
imwheel script gui modified to disable the service on 0
#!/bin/bash
# Comments and complaints http://www.nicknorton.net, last modification
# by mijorus here https://gist.github.com/mijorus/f7c127a62230490df4e796207ce540bf.
# GUI for mouse wheel speed using imwheel in Gnome
# imwheel needs to be installed for this script to work
# sudo apt-get install imwheel
# Pretty much hard wired to only use a mouse with
# left, right and wheel in the middle.
# If you have a mouse with complications or special needs,
# use the command xev to find what your wheel does.
@mijorus
mijorus / toggleDoNotDisturb.sh
Last active October 18, 2021 07:37
Toggle Do Not Disturb mode on Gnome on/off with a sigle command
currentdndstate=$(gsettings get org.gnome.desktop.notifications show-banners); if [ $currentdndstate == "false" ]; then gsettings set org.gnome.desktop.notifications show-banners true; else gsettings set org.gnome.desktop.notifications show-banners false; fi
@mijorus
mijorus / mkdd.md
Last active October 18, 2021 07:38
Create a new directory and switch to it: Fish Shell

Copy to ./config/fish/functions/mkdd.fish

function mkdd -d "Create a directory and set CWD"
    command mkdir $argv
    if test $status = 0
        switch $argv[(count $argv)]
            case '*'
                cd $argv[(count $argv)]
                return
 end
@mijorus
mijorus / gnome-exec.js
Created January 9, 2022 20:38
How to run a command from a gnome extension
/**
The first time I wanted to create an extension for Gnome, I spent two hours trying to understand how to do this, due to bad documentation.
So now I am sharing this once for all.
*/
const ByteArray = imports.byteArray;
function exec(command) {
const output = GLib.spawn_command_line_sync(command);
return {
ok: output[0],
standard_output: ByteArray.toString(output[1]),
@mijorus
mijorus / ask.py
Last active May 3, 2022 10:01
Ask the user to input a choice in the terminal, returns only if the answer matches a list of provided options
def ask(message: str, options: set) -> str:
_input = None
while not _input in options:
_input = input(message)
return _input
@mijorus
mijorus / gtk_image_from_url.py
Last active May 4, 2022 16:25
Load a Gtk.Image from an http URL, with Python
import requests
from gi.repository import Gtk, Adw, GdkPixbuf, GLib
def gtk_image_from_url(url: str, image: Gtk.Image):
"""Using the requests module we load an image from a http endpoint, then we can create a Pixbuf loader to load our image"""
response = requests.get(url)
response.raise_for_status()
loader = GdkPixbuf.PixbufLoader()
loader.write_bytes(GLib.Bytes.new(response.content))
@mijorus
mijorus / key_in_dict.py
Last active May 5, 2022 07:54
Python: search for a nested key in a dictionary but do not throw errors if the key does not exists (kinda like the ?? operator)
def key_in_dict(_dict: dict, key_lookup: str, separator='.'):
"""
Searches for a nested key in a dictionary and returns its value, or None if nothing was found.
key_lookup must be a string where each key is deparated by a given "separator" character, which by default is a dot
"""
if not isinstance(_dict, dict):
raise TypeError('First argument must be type Dict')
keys = key_lookup.split(separator)
subdict = _dict
@mijorus
mijorus / ternary.py
Created June 2, 2022 12:09
Python ternary operator function shorthand
def qq(condition, is_true, is_false):
return is_true if condition else is_false
@mijorus
mijorus / create_dict.py
Created July 8, 2022 13:04
Python create dict from variables names
# Credit: https://stackoverflow.com/questions/39818733/create-dictionary-where-keys-are-variable-names
def create_dict(*args: str):
return dict({i:eval(i) for i in args})
@mijorus
mijorus / bw-backup.py
Last active August 17, 2022 10:04
Exports your bitwarden passwords as temporary json, encrypts and uploads the file to your MEGA
#!/usr/bin/python3
# both megacmd and bw-cli need to be installed and configured before running this script
# bw-cli from snap needs to be configured in order to write in the /tmp folder
# files will be uploaded in the /bw folder on MEGA
import sys
import os
import subprocess
from getpass import getpass