This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import asyncio | |
import asyncio.subprocess | |
from textual import work | |
from textual.app import App, ComposeResult | |
from textual.widgets import Log | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// script | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "llm", | |
# "textual", | |
# ] | |
# /// | |
from textual import on, work | |
from textual.app import App, ComposeResult | |
from textual.widgets import Header, Input, Footer, Markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mmap | |
def get_last_lines(path: str, count: int) -> list[str]: | |
"""Get count last lines from a file.""" | |
with open(path, "r+b") as text_file: | |
text_mmap = mmap.mmap(text_file.fileno(), 0, mmap.ACCESS_READ) | |
position = len(text_mmap) | |
while count and (position := text_mmap.rfind(b"\n", 0, position)) != -1: | |
count -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cook the pinto beans in a pressure cooker with 3 parts water to 1 part beans, and some salt. | |
While that is cooking dice an onion and 3 stalks of cellery, add a few cloves of garlic crushed with a knife. Fry lightly and stir for around 20 minutes. Add sliced sausage and fry for another 10 minutes. | |
When the beans are ready take a couple of scoops and add them to the onion mixture. Mash the beans so they are completely broken down (this will thicken the sauce). Add paprika, chipotle, tomatoe puree and black bepper, then combine with the beans. | |
Simmer for another 10 minutes or so until the sauce thickens. Add some vinegar and chopped parsely near the end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Screen { | |
overflow: auto; | |
} | |
#calculator { | |
layout: table; | |
table-size: 4; | |
table-gutter: 1 2; | |
table-columns: 1fr; | |
table-rows: 2fr 1fr 1fr 1fr 1fr 1fr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stopwatch { | |
layout: horizontal; | |
background: $panel-darken-1; | |
height: 5; | |
min-width: 50; | |
margin: 1; | |
padding: 1; | |
} | |
TimeDisplay { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TimerWidget { | |
layout: horizontal; | |
height: 5; | |
background: $panel-darken-1; | |
border: tall $panel-darken-2; | |
margin: 1; | |
padding: 0 1; | |
transition: background 200ms linear; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def segments_float(size, parts): | |
end = 0.0 | |
part = size / parts | |
for n in range(parts): | |
start = int(end) | |
end += part | |
print(str(n) * int(end - start), end="") | |
print() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lru_cache(maxsize=4096) | |
def intersection(self, region: Region) -> Region: | |
"""Get the overlapping portion of the two regions. | |
Args: | |
region (Region): A region that overlaps this region. | |
Returns: | |
Region: A new region that covers when the two regions overlap. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
class Region(NamedTuple): | |
x: int | |
y: int | |
width: int | |
height: int | |
NewerOlder