Skip to content

Instantly share code, notes, and snippets.

View giuseppe998e's full-sized avatar

Giuseppe Eletto giuseppe998e

View GitHub Profile
@giuseppe998e
giuseppe998e / worker.rs
Created January 2, 2026 09:53
Threaded processor that exposes async Sink/Stream interfaces for offloading blocking work
use std::{
pin::Pin,
sync::{Arc, Mutex},
task::{Context, Poll},
thread,
};
use futures::{Sink, SinkExt as _, Stream};
use tokio::sync::mpsc;
use tokio_util::sync::{PollSendError, PollSender};
@giuseppe998e
giuseppe998e / quad9-dns-client.toml
Last active April 24, 2025 16:18
RouteDNS Quad9 Secure DNS (DoH/DoT) Client Configuration
# Quad9 DoT/DoH Client
# DoT Resolvers
[resolvers.main-dot]
protocol = "dot"
address = "dns.quad9.net"
bootstrap-address = "9.9.9.9"
[resolvers.secondary-dot]
protocol = "dot"
@giuseppe998e
giuseppe998e / README.md
Last active September 23, 2024 08:08
Calibre AppImage - Launcher with updater

Calibre AppImage Auto-Update Launcher

This README provides instructions on how to install the launch.sh script for automatically updating and launching Calibre in AppImage format.

Installation Steps

  1. Create the Directory: Open a terminal and create a directory for Calibre in /opt with write permissions for the current user:

sudo mkdir /opt/calibre

@giuseppe998e
giuseppe998e / remove_by_ref.rs
Last active April 11, 2024 07:35
Rust lang example on how to remove a struct from a vector using the item reference
#[derive(Debug)]
struct Structure {
name: String,
}
#[derive(Debug)]
struct StructVector(Vec<Structure>);
impl StructVector {
fn by_name(&self, name: &str) -> Option<&Structure> {
@giuseppe998e
giuseppe998e / serde_peekable_access.rs
Last active March 25, 2024 14:36
Wrappers for peeking into Serde's "MapAccess" and "SeqAccess" implementations without advancing the iterator. The "PeekableMapAccess" struct allows peeking at the next key and/or value in a map, while "PeekableSeqAccess" provides similar functionality for sequences.
//! Licensed under either of:
//! - Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
//! - MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
//!
//! This file may not be copied, modified, or distributed except according to those terms.
use std::marker::PhantomData;
use serde::{__private::de as private_de, de};
@giuseppe998e
giuseppe998e / text_shuffle.js
Last active June 6, 2023 08:58
Javascript code that shuffles the text of an HTML element
!function () {
const shuffleVelocityMs = 50;
const shuffleElement = (element) => {
const elemText = element.getAttribute("data-text");
const elemementChars = Array.from(elemText);
const shuffleChars = (chars) => {
for (let idx = chars.length; --idx; ) {
const randomIdx = parseInt(Math.random() * idx);
@giuseppe998e
giuseppe998e / nge.rs
Last active December 14, 2022 19:29
"Next Greater Element" and "Previous Greater Element" arrays using stack in Rust - Complexity O(n)
fn next_greater_elems<T: Copy + PartialOrd>(array: &[T]) -> Box<[Option<T>]> {
let array_len = array.len();
let mut stack = Vec::<usize>::with_capacity(array_len);
let mut result = Vec::<Option<T>>::with_capacity(array_len);
stack.push(0);
result.push(None);
for (index, element) in array.iter().enumerate().skip(1) {
result.push(None);
@giuseppe998e
giuseppe998e / trait_test.php
Created October 26, 2022 23:12
Test of PHP traits behavior using "self" and "static" keywords
<?php declare(strict_types = 1);
// Tried on PHP 8.0.25
// Trait
trait TestTrait {
public static function spawnSelf(): self {
return new self();
}
public static function spawnStatic(): static {
@giuseppe998e
giuseppe998e / media_rename.py
Created July 16, 2022 14:03
A Python3 script that asynchronously renames files (media) in a directory
#!/usr/bin/env python3
# Copyright 2022 Giuseppe Eletto <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@giuseppe998e
giuseppe998e / twitchchatreader.js
Last active August 4, 2022 07:34
An IRC WebSocket client that reads Twitch channel chat without the need to authenticate
/**
* MIT License
*
* Copyright (c) 2022 Giuseppe Eletto <giuseppe@eletto.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is