Skip to content

Instantly share code, notes, and snippets.

@luluco250
luluco250 / launch.fish
Last active March 8, 2023 13:00
Shell scripts/functions to launch GUI apps without tying them to a terminal.
#!/usr/bin/env fish
function launch --wraps exec
sh -c "(exec $(string escape $argv | string join ' ') >/dev/null 2>&1 &)"
end
@luluco250
luluco250 / toggle-kwin-virtual-keyboard.bash
Last active February 2, 2023 21:52
Bash script that forcibly shows or hides the virtual keyboard in KDE/KWin, useful for mobile devices. Works with Maliit.
#!/bin/bash
call_dbus() {
dbus-send \
--print-reply=literal \
--session \
--dest=org.kde.KWin \
/VirtualKeyboard \
"$@"
}
@luluco250
luluco250 / obj_to_yaml.py
Last active January 24, 2023 15:57
Python dump non-printable object as yaml (not guaranteed to be production ready, just a personal utility).
'''
obj_to_yaml() can print an object to a Yaml-like string.
This is useful to inspect complex objects in a friendlier manner.
'''
from typing import Any
def is_non_printable(obj: Any) -> bool:
return hasattr(obj, '__dict__')
@luluco250
luluco250 / delete.bash
Last active July 8, 2022 23:07
File deletion service script for Finder on macOS
#!/bin/bash
#################
## Description ##
#################
# This service script will allow you to select some files and folders and
# delete them permanently (bypassing the trash), with a confirmation prompt.
#
# To install the script:
@luluco250
luluco250 / firefox-addons.sh
Created April 20, 2022 01:32
List Firefox addons.
#!/bin/sh
cd "$HOME/.mozilla/firefox"
cd "$(ls -d *.default-release/ | head -n 1)"
jq \
-r '.addons[] | select(.type == "extension" and .active == true and .hidden == false) | .defaultLocale.name' \
extensions.json \
| sort
@luluco250
luluco250 / update-mirrors.sh
Created March 2, 2022 23:30
Script to update pacman mirrors using reflector
#!/bin/bash
[[ $(id -u) > 0 ]] && echo 'Error: Needs to be run as root.' && exit 1
reflector \
--country 'Brazil,Canada,Chile,Colombia,Ecuador,Mexico,Paraguay,United States' \
--fastest 10 \
--protocol https \
--sort rate \
--threads $(nproc) \
@luluco250
luluco250 / pong.py
Created February 2, 2022 20:58
Simple single-player pong game in PyGame.
#!/usr/bin/env python3
import sys
import pygame as pg
import enum
import math
import random
# Global game constants.
GAME_TITLE = "Pong"
@luluco250
luluco250 / extension_methods.cpp
Last active November 17, 2021 17:14
Extension methods in C++ using desperation, sweat, tears and bubblegum
#include <iostream>
#include <string>
#include <functional>
using namespace std::placeholders;
template<typename Signature>
struct Extension {
std::function<Signature> func;
@luluco250
luluco250 / wezterm.lua
Last active December 6, 2021 13:08
WezTerm config
local wt = require("wezterm");
local TabBackground = "#000"
local TabForeground = "#aaa"
local TabForegroundActive = "#fff"
function string.split(str, sep)
local t = {}
for s in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, s)
@luluco250
luluco250 / async-sandwich.cpp
Last active July 13, 2021 17:00
Example of using concurrent asynchronous tasks in C++
#include <iostream>
#include <future>
#include <chrono>
#include <thread>
using namespace std::literals;
static std::mutex println_mutex;
constexpr auto println = [](auto... stuff) {