Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / snippets.js
Last active November 23, 2022 13:39
PHP html snippets for VS Code (File > Preferencies > User Snippets > html). List always updating
{
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@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 / ThemedIcon.md
Last active December 15, 2022 07:54
List of Gio.ThemedIcon
@mijorus
mijorus / howtoCherryPickLazygit.md
Last active May 28, 2024 13:43
Lazygit: how to cherry-pick

I'm writing this because I found it harder than expected, but actually is super easy.

  1. From the "Commit" panel (or the "Branches" panel) focus on a commit an press c, you can select more than one
  2. Go to the "Commit" panel (in the "Branches" panel it doesn't work) and press v, will ask for confirmation.
  3. DONE

EDIT: With the latest release, c and v are replaced with Shift + c and Shift + v

@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 / 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.