Skip to content

Instantly share code, notes, and snippets.

<?php
class Py
{
/**
* Get the least common multiple
*
* @param $a
* @param $b
* @return float|int
@nitori
nitori / hexchat.py
Last active February 11, 2017 14:02
Python stub file for hexchat plugin API
"""
Rename hexchat.pyi and add to your IDEs (e.g. PyCharm) Project to get
autocomplete for hexchat API.
Assumes at least Python 3.5
http://img.xrmb2.net/images/940180.png
"""
import enum
# https://www.youtube.com/watch?v=5C6sv7-eTKg
# helpers
def _incr(num):
return num + 1
def show(num):
return print(num(_incr)(0))
@nitori
nitori / smoothy.js
Created July 15, 2022 13:44
JavaScript simple smooth scroll
// Sourced from: https://easings.net/
/**
* @enum {Easings}
*/
export const Easings = {
easeInSine: 'easeInSine',
easeOutSine: 'easeOutSine',
easeInOutSine: 'easeInOutSine',
easeInQuad: 'easeInQuad',
easeOutQuad: 'easeOutQuad',
@nitori
nitori / ffmpeg_grab_to_pygame.py
Created August 31, 2022 16:26
Uses ffmpeg to grab screen and outputs in Surface on pygame
from __future__ import annotations
from threading import Thread, Event
from queue import Queue
import subprocess
import pygame
MONITORS = {
'left': (-1920, 0, 1920, 1080),
'middle': (0, 0, 2560, 1440), # presumably main monitor, hence offset is (0, 0)
@nitori
nitori / snake.py
Created August 31, 2022 16:29
Simple pygame based snake game.
from __future__ import annotations
import random
from collections import deque
import time
import colorsys
import pygame
WIDTH, HEIGHT = 50, 50
TILE_WIDTH = 10
@nitori
nitori / argumentarize.py
Last active September 19, 2024 19:57
Convert a decorator into one that allows multiple forms
from functools import wraps, partial
def argumentarize(func):
@wraps(func)
def decorator(decorated_func=None, /, **kwargs):
if decorated_func is None:
# decorator was used with (...)
# so return the decorator again as partial
return partial(func, **kwargs)
@nitori
nitori / httpserver.py
Created September 3, 2022 11:52
Quick and dirty ~1-hour HTTP server written in python, only using socket, os and threading
from __future__ import annotations
import threading
import socket
import os
DOCROOT = os.path.dirname(os.path.abspath(__file__))
EXT_MIME_MAP = {
'.html': 'text/html; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'.txt': 'text/plain; charset=utf-8',
@nitori
nitori / twitch_bot_with_tui.py
Last active September 4, 2022 13:33
Simple asyncio twitch bot with a textual based TUI
from __future__ import annotations
import asyncio
from rich.text import Text
from textual.app import App
from textual.widgets import ScrollView, Footer
from textual_inputs import TextInput
try:
import tomllib
@nitori
nitori / simple_path_iterator.py
Created September 25, 2022 14:18
Iterate over a nest dictionary/list with a specified path
def extract(obj, path: list[str]):
def _inner(_obj, _path: list[str], used_path: list):
if not _path:
yield tuple(used_path), _obj
return
current, *rest = _path
if current == '*':
# yield from all items on the current level
if isinstance(_obj, list):