Skip to content

Instantly share code, notes, and snippets.

View P403n1x87's full-sized avatar
⚒️
Tinkering

Gabriele N. Tornetta P403n1x87

⚒️
Tinkering
View GitHub Profile
@P403n1x87
P403n1x87 / class.lua
Last active May 3, 2017 22:12
Object Orientation in Lua
--+--------------------------------------------------------------------------+
-- Class Constructor.
--
-- Supports single inheritance. To define a new class use as
--
-- A = class()
--
-- To define a class B that inherits from A, use as
--
-- B = class(A)
@P403n1x87
P403n1x87 / blighty_spotify
Last active July 30, 2022 11:36
A simple Spotify widget written in Python for Blighty to celebrate the 1k download mark.
#!/usr/bin/env python
"""
This file is part of "blighty" which is released under GPL.
See file LICENCE or go to http://www.gnu.org/licenses/ for full license
details.
blighty is a desktop widget creation and management library for Python 3.
@P403n1x87
P403n1x87 / memory.py
Created December 25, 2018 00:26
Memory usage Blighty widget
from math import pi as PI
import psutil
from attrdict import AttrDict
from blighty import CanvasGravity, TextAlign
from blighty.legacy import Graph
from blighty.x11 import Canvas, start_event_loop
from fonts import Fonts
@P403n1x87
P403n1x87 / fs.py
Created December 25, 2018 00:31
File System Blighty widget
from math import pi as PI
import psutil
from attrdict import AttrDict
from blighty import CanvasGravity, TextAlign
from blighty.legacy import Graph
from blighty.x11 import Canvas, start_event_loop
from fonts import Fonts
@P403n1x87
P403n1x87 / net.py
Created December 25, 2018 00:33
Network Monitor Blighty widget
import socket
from time import sleep
import psutil
from attrdict import AttrDict
from blighty import CanvasGravity, TextAlign
from blighty.legacy import Graph
from blighty.x11 import Canvas, start_event_loop
from requests import get
from multiprocessing import Pool, Queue, Manager, cpu_count
from multiprocessing.queues import Empty
from threading import Thread
from tqdm import tqdm
def parallelize(func: callable, iterable: list, processes: int = None) -> list:
"""Parallelize the execution of a function over a list.
This method runs a given function over chunks of the given list in
class FiniteAutomaton:
def __init__(self):
self._states = {}
self._initial = None
self._current = None
def add_state(self, name, handler, initial=False):
if initial:
if self._initial:
raise RuntimeError("Initial state already added!")
@P403n1x87
P403n1x87 / wake_signal.py
Created May 18, 2020 11:13
Wake Control Signal. A timer with extensible timeout that performs actions at the rising and falling edges. The timeout is extended whenever the wake method is called while the signal is hot.
from threading import Thread, Event
class WakeSignal(Thread):
def __init__(self, interval, rising=None, falling=None):
super().__init__()
self._interval = interval
self._stopped = False
self._awake = False
@P403n1x87
P403n1x87 / y_combinator.py
Created June 10, 2020 15:19
Y combinator in Python
TRUE = lambda x: lambda y: x
FALSE = lambda x: lambda y: y
PAIR = lambda a: lambda b: lambda f: f(a)(b)
D = lambda x: PAIR(x)(x)
FIRST = lambda p: p(TRUE)
SECOND = lambda p: p(FALSE)
@P403n1x87
P403n1x87 / git-credential-helper-libsecret.sh
Created July 21, 2020 08:59
Store git credentials securely on Ubuntu
#!/bin/bash
set -e
sudo apt-get -y install libsecret-1-0 libsecret-1-dev libglib2.0-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret