Skip to content

Instantly share code, notes, and snippets.

View mijorus's full-sized avatar
😎

Lorenzo Paderi mijorus

😎
View GitHub Profile
@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
@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 / 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 / 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 January 21, 2026 11:42
Lazygit: how to cherry-pick

How to cherry pick with LazyGit

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 Shift + c, you can select more than one
  2. Go to the "Commit" panel (in the "Branches" panel it doesn't work) and press Shift + v, will ask for confirmation.
  3. DONE

NOTE On older versions, you simply had to press c and v without Shift