Skip to content

Instantly share code, notes, and snippets.

@eli-kha
eli-kha / cross_platform_get_netmask.py
Created July 24, 2023 09:51
a short piece of dependency free code to get the OS netmask
import ipaddress
import platform
import re
import subprocess
def get_netmask(ipv4_address):
"""Gets the computer's current netmask for a given IP.
Returns:
str: The computer's current netmask.
@eli-kha
eli-kha / demo_auto_color_nicegui_button.py
Created June 11, 2023 13:44
A demo of automatic text color selection based on the background color for NiceGUI
import re
from typing import Optional, Callable, Any, Tuple
from nicegui import ui
from nicegui.colors import set_background_color, set_text_color
from nicegui.elements.button import Button
def get_rgb(hex_color: str) -> Tuple[int, int, int]:
""" 6 or 8 characters supported """
@eli-kha
eli-kha / nicegui_pydantic_form.py
Last active January 2, 2024 16:29
An initial implementation of autogenerating a user input form with nicegui from a pydantic model or an instance of a model
from typing import Optional, Callable, List, Dict, Any, Union, Type
from nicegui import ui
from nicegui.elements.mixins.value_element import ValueElement
from pydantic import BaseModel
TYPE_TO_INPUT_UI_MAP = {
int: ui.number,
bool: ui.switch,
str: ui.input,
@eli-kha
eli-kha / nicegui_webview_demo.py
Created March 11, 2023 20:36
A small demo of using pywebview with NiceGUI based on wrapping both Unicorn.Server and webview in processes.
#!/usr/bin/env python3
import multiprocessing
import tempfile
from fastapi import FastAPI
from uvicorn import Config, Server
import webview
from nicegui import ui