Skip to content

Instantly share code, notes, and snippets.

View galatolofederico's full-sized avatar
🙃
This is fine

Federico Galatolo galatolofederico

🙃
This is fine
View GitHub Profile
@galatolofederico
galatolofederico / first_completed.py
Created February 20, 2025 18:40
Run multiple tasks concurrently and return the result of the first one that completes without using async/await
import concurrent.futures
def first_completed(f, args, num_workers=10):
executor = concurrent.futures.ThreadPoolExecutor(max_workers=num_workers)
try:
futures = [executor.submit(f, *arg) for arg in args]
ret = None
for future in concurrent.futures.as_completed(futures):
ret = future.result()
@galatolofederico
galatolofederico / multiline-pygame.py
Created February 23, 2023 14:08
pygame function to display multiline texts and auto scroll to the bottom
import pygame
import math
pygame.init()
SIZE = WIDTH, HEIGHT = (1024, 720)
FPS = 30
screen = pygame.display.set_mode(SIZE, pygame.RESIZABLE)
clock = pygame.time.Clock()
@galatolofederico
galatolofederico / presentation_to_pdf.sh
Last active October 21, 2021 23:33
Transform a presentation with animations in a pdf by automatically clicking and screenshotting
#!/bin/bash
#
# Transform a presentation with animations in a pdf by automatically clicking and screenshotting
#
presentation_window_name="WPS Presentation Slide Show"
output_file="presentation.pdf"
tmp_folder="./presentation-to-pdf-tmp"
click_delay=0.2
trim=1
@galatolofederico
galatolofederico / virtualenvs_cleanup.sh
Created October 10, 2020 12:21
Freeze and remove old virtualenvs
#! /bin/bash
# shellcheck source=/dev/null
# Example:
# Freeze and delete virtualenvs folders older than 100 days:
#
# find ./ -maxdepth 1 -type d -mtime +100 -print | ./virtualenvs_cleanup.sh
#
REQUIREMENTS_FILE="requirements.bak.txt"
@galatolofederico
galatolofederico / project-flattener.sh
Last active September 22, 2020 12:05
This script takes a folder with a project with multiple files, folders and subfolders and convert it in a project with all the files on the first folder level
#! /bin/bash
# ./project-flattner.sh <source folder> <destination folder>
#
# Some Editorial Management System require LaTeX sources submissions to be on the same folder level.
# This script takes a folder with a project with multiple folders and subfolders and
#
# 1) copies all the files from the source folder to the destination one
# renaming all of them from "path/to/file.ext" to "path_to_file.ext"
# 2) sobsitutes in all the new files all the occurences of
@galatolofederico
galatolofederico / pisearch.py
Created June 2, 2020 13:58
Search a text in pi (or other continued fractions) in Python
import sys
import time
import argparse
import string
chars = string.ascii_lowercase
parser = argparse.ArgumentParser()
parser.add_argument("--constant", type=str, choices=["pi", "phi"], default="pi")
@galatolofederico
galatolofederico / pisearch.py
Created June 2, 2020 13:58
Search a text in pi (or other continued fractions) in Python
import sys
import time
import argparse
import string
chars = string.ascii_lowercase
parser = argparse.ArgumentParser()
parser.add_argument("--constant", type=str, choices=["pi", "phi"], default="pi")
import os
import torch
from torch.nn import functional as F
from torch.utils.data import DataLoader
from torchvision.datasets import MNIST
from torchvision import transforms
from argparse import ArgumentParser
from pytorch_lightning import Trainer
@galatolofederico
galatolofederico / tablet_mode.sh
Created June 2, 2019 14:31
HP Pavilion x2 tablet mode switch script
#! /usr/bin/bash
KEYBOARD="HID 04f3:074d"
MODE="pc"
pc_mode() {
killall florence
set_layout "it"
}
@galatolofederico
galatolofederico / 70-tablet.conf
Created April 3, 2019 16:30
Wizardpen configuration for Magicart75 Graphic Tablet (EMRight Technology Co.)
# Wizardpen configuration for "Magicart75" Graphic Tablet
# xinput name: EMRight Technology Co. Graphic Tablet
# USB Vendor ID: 2c68
# USB Product ID: e003
Section "InputClass"
Identifier "wizardpen"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
MatchProduct "EMRight"