Compare commits
3
Commits
e70a012b03
...
main
No files matched your search
@@ -5,4 +5,4 @@ def decode(string: str, start: int = 0):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
decode("f09c9491b09c949c9491de939f9d", 0) # [email protected]
|
||||
decode("f09c9491b09c949c9491de939f9d", 0) # [email protected]
|
||||
+16
-2
@@ -27,6 +27,20 @@ if [[ -z "$custom_path" || "$custom_path" == *$'\n'* ]]; then
|
||||
printf 'CustomPath must be exactly one non-empty path.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
manifest_path="$("$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" --print-manifest-path \
|
||||
"$custom_path/public/assets/css" "$custom_path/templates")"
|
||||
|
||||
# Move manifests written by earlier script versions out of CustomPath before Gitea dump scans it.
|
||||
for legacy_manifest in \
|
||||
"$custom_path/.gitea-github-theme-files" \
|
||||
"$custom_path/templates/.gitea-github-theme-files"; do
|
||||
if [[ -f "$legacy_manifest" && ! -e "$manifest_path" ]]; then
|
||||
mkdir -p "$(dirname "$manifest_path")"
|
||||
mv -- "$legacy_manifest" "$manifest_path"
|
||||
printf 'Moved theme manifest to %s.\n' "$manifest_path"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ! "$gitea_version" =~ ^v?([0-9]+\.[0-9]+) ]]; then
|
||||
printf 'Unable to determine major.minor from Gitea version: %s\n' "$gitea_version" >&2
|
||||
@@ -54,11 +68,11 @@ if [[ -z "$theme_version" ]]; then
|
||||
exec "$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" --remove \
|
||||
"$custom_path/public/assets/css" \
|
||||
"$custom_path/templates" \
|
||||
"$custom_path/.gitea-github-theme-files"
|
||||
"$manifest_path"
|
||||
fi
|
||||
|
||||
exec "$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" \
|
||||
"$theme_version" \
|
||||
"$custom_path/public/assets/css" \
|
||||
"$custom_path/templates" \
|
||||
"$custom_path/.gitea-github-theme-files"
|
||||
"$manifest_path"
|
||||
@@ -47,6 +47,23 @@ prepare_directory() {
|
||||
printf '%s\n' "$directory"
|
||||
}
|
||||
|
||||
default_manifest_path() {
|
||||
local css_destination="$1"
|
||||
local templates_destination="$2"
|
||||
local state_directory manifest_key
|
||||
|
||||
if [[ -n "${GITEA_GITHUB_THEME_STATE_DIR:-}" ]]; then
|
||||
state_directory="$GITEA_GITHUB_THEME_STATE_DIR"
|
||||
elif [[ $EUID -eq 0 ]]; then
|
||||
state_directory="/var/lib/gitea-github-theme"
|
||||
else
|
||||
state_directory="${XDG_STATE_HOME:-${HOME:-.}/.local/state}/gitea-github-theme"
|
||||
fi
|
||||
|
||||
manifest_key="$(printf '%s\0%s' "$css_destination" "$templates_destination" | sha256sum | awk '{print $1}')"
|
||||
printf '%s/%s.manifest\n' "$state_directory" "$manifest_key"
|
||||
}
|
||||
|
||||
remove_theme_files() {
|
||||
local css_destination="$1"
|
||||
local templates_destination="$2"
|
||||
@@ -98,11 +115,20 @@ main() {
|
||||
local version css_destination templates_destination manifest release_path
|
||||
|
||||
require_command find
|
||||
require_command sha256sum
|
||||
require_command awk
|
||||
|
||||
if [[ "${1:-}" == "--print-manifest-path" ]]; then
|
||||
css_destination="$(prepare_directory "${2:-}")"
|
||||
templates_destination="$(prepare_directory "${3:-}")"
|
||||
default_manifest_path "$css_destination" "$templates_destination"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "${1:-}" == "--remove" ]]; then
|
||||
css_destination="$(prepare_directory "${2:-}")"
|
||||
templates_destination="$(prepare_directory "${3:-}")"
|
||||
manifest="${4:-$templates_destination/.gitea-github-theme-files}"
|
||||
manifest="${4:-$(default_manifest_path "$css_destination" "$templates_destination")}"
|
||||
remove_theme_files "$css_destination" "$templates_destination" "$manifest"
|
||||
printf 'Removed installed Gitea GitHub theme files.\n'
|
||||
return
|
||||
@@ -130,7 +156,7 @@ main() {
|
||||
read -r -p "Templates destination (for example /path/to/gitea/templates): " templates_destination
|
||||
fi
|
||||
templates_destination="$(prepare_directory "$templates_destination")"
|
||||
manifest="${4:-$templates_destination/.gitea-github-theme-files}"
|
||||
manifest="${4:-$(default_manifest_path "$css_destination" "$templates_destination")}"
|
||||
|
||||
if [[ "$version" == "latest" ]]; then
|
||||
release_path="latest/download"
|
||||
|
||||
Executable → Regular
+6
-6
@@ -8,7 +8,6 @@ from pathlib import Path
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
|
||||
PATTERN = re.compile(
|
||||
# r"^rollout-"
|
||||
r"(?P<date>\d{4}-\d{2}-\d{2})"
|
||||
@@ -29,7 +28,7 @@ def parse_session_filename(name: str):
|
||||
return None
|
||||
|
||||
started = datetime.strptime(
|
||||
f'{match.group("date")} {match.group("time")}',
|
||||
f"{match.group('date')} {match.group('time')}",
|
||||
"%Y-%m-%d %H-%M-%S",
|
||||
)
|
||||
|
||||
@@ -49,6 +48,7 @@ def format_size(size: int) -> str:
|
||||
return f"{size} B"
|
||||
return f"{value:.1f} {unit}"
|
||||
value /= 1024
|
||||
raise ValueError() # unreachable
|
||||
|
||||
|
||||
def format_session_line(file: Path) -> str | None:
|
||||
@@ -61,10 +61,10 @@ def format_session_line(file: Path) -> str | None:
|
||||
size = format_size(stat.st_size)
|
||||
|
||||
return (
|
||||
f'{parsed["started"]:%Y-%m-%d %H:%M:%S} | '
|
||||
f'updated {modified:%Y-%m-%d %H:%M:%S} | '
|
||||
f'{size:>8} | '
|
||||
f'codex resume {parsed["uuid"]}'
|
||||
f"{parsed['started']:%Y-%m-%d %H:%M:%S} | "
|
||||
f"updated {modified:%Y-%m-%d %H:%M:%S} | "
|
||||
f"{size:>8} | "
|
||||
f"codex resume {parsed['uuid']}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# /// script
|
||||
# dependencies = [
|
||||
# "pynput",
|
||||
# "pyautogui",
|
||||
# ]
|
||||
# ///
|
||||
|
||||
# uv likes this block
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
import pynput
|
||||
|
||||
controller = pynput.keyboard.Controller()
|
||||
|
||||
|
||||
type Key = pynput.keyboard.Key | pynput.keyboard.KeyCode | None
|
||||
type ListenerFn = Callable[[Key], bool | None]
|
||||
|
||||
|
||||
def h() -> tuple[ListenerFn, ListenerFn]:
|
||||
a_first = True
|
||||
held = False
|
||||
|
||||
A = pynput.keyboard.KeyCode.from_char("a")
|
||||
D = pynput.keyboard.KeyCode.from_char("d")
|
||||
TRIGGER = pynput.keyboard.KeyCode.from_char("\\")
|
||||
FLIP = pynput.keyboard.KeyCode.from_char("/")
|
||||
QUIT = pynput.keyboard.KeyCode.from_char("'")
|
||||
|
||||
def order(do):
|
||||
if a_first:
|
||||
do(A)
|
||||
do(D)
|
||||
else:
|
||||
do(D)
|
||||
do(A)
|
||||
|
||||
def funny(key: Key, press: bool) -> bool | None:
|
||||
nonlocal a_first, held
|
||||
|
||||
if key == TRIGGER:
|
||||
if press and not held:
|
||||
order(controller.press)
|
||||
held = True
|
||||
|
||||
elif not press and held:
|
||||
order(controller.release)
|
||||
held = False
|
||||
|
||||
elif key == FLIP and press:
|
||||
a_first = not a_first
|
||||
print(f"flipped a_first to {a_first}")
|
||||
|
||||
elif key == QUIT and press:
|
||||
return False
|
||||
|
||||
return (
|
||||
lambda key: funny(key, True),
|
||||
lambda key: funny(key, False),
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
press, release = h()
|
||||
with pynput.keyboard.Listener(on_press=press, on_release=release) as listener:
|
||||
listener.join()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+10
-1
@@ -1,3 +1,12 @@
|
||||
# /// script
|
||||
# dependencies = [
|
||||
# "requests",
|
||||
# "beautifulsoup4",
|
||||
# "pypdf",
|
||||
# ]
|
||||
# ///
|
||||
|
||||
|
||||
import io
|
||||
from collections.abc import Iterable
|
||||
from functools import partial
|
||||
@@ -61,7 +70,7 @@ def ts_pdf(s: requests.Session, url: str) -> bytes:
|
||||
|
||||
def main():
|
||||
u, p = input("Username: "), getpass("Password: ")
|
||||
pdfs = ( # example
|
||||
pdfs = ( # example
|
||||
"https://moodle.usth.edu.vn/pluginfile.php/91136/mod_resource/content/1/Chapter%201%20v1.pdf",
|
||||
"https://moodle.usth.edu.vn/pluginfile.php/91137/mod_resource/content/1/Chapter%202.pdf",
|
||||
"https://moodle.usth.edu.vn/pluginfile.php/91138/mod_resource/content/1/Chapter%203%20%20.pdf",
|
||||
|
||||
+88
-4
@@ -22,13 +22,23 @@ class TuringMachine:
|
||||
blank_symbol: Symbol = " "
|
||||
|
||||
def run(
|
||||
self, tape_input: str, max_steps: int = 10_000, verbose: bool = True
|
||||
self,
|
||||
tape_input: str,
|
||||
head: int = 0,
|
||||
max_steps: int = 10_000,
|
||||
verbose: bool = True,
|
||||
) -> Tuple[State, Tape]:
|
||||
tape: Tape = list(tape_input) + [self.blank_symbol] * 20
|
||||
head = 0
|
||||
state = self.start_state
|
||||
steps = 0
|
||||
|
||||
# normalize head position
|
||||
if head < 0:
|
||||
tape = [self.blank_symbol] * (-head) + tape
|
||||
head = 0
|
||||
elif head >= len(tape):
|
||||
tape += [self.blank_symbol] * (head - len(tape) + 1)
|
||||
|
||||
def debug_print():
|
||||
tape_view = "".join(tape).replace(self.blank_symbol, "_")
|
||||
head_marker = " " * head + "^"
|
||||
@@ -109,7 +119,81 @@ tm = TuringMachine(
|
||||
reject_state="reject",
|
||||
)
|
||||
|
||||
final_state, final_tape = tm.run("00110")
|
||||
tape_input = "00110"
|
||||
final_state, final_tape = tm.run(tape_input)
|
||||
print("Final State:", final_state)
|
||||
print("Final Tape:", "".join(final_tape).strip())
|
||||
final_tape_str = "".join(final_tape).strip()
|
||||
print("Final Tape:", final_tape_str)
|
||||
|
||||
classic: TransitionFunction = {}
|
||||
|
||||
# ok idk
|
||||
|
||||
classic[("want_copy", "1")] = ("past_og_1", "X", "R")
|
||||
classic[("want_copy", "0")] = ("past_og_0", "Y", "R")
|
||||
|
||||
for sym in ["0", "1"]:
|
||||
classic[("past_og_1", sym)] = ("past_og_1", sym, "R")
|
||||
classic[("past_og_0", sym)] = ("past_og_0", sym, "R")
|
||||
|
||||
classic[("past_og_1", " ")] = ("copy_1", " ", "R")
|
||||
classic[("past_og_0", " ")] = ("copy_0", " ", "R")
|
||||
|
||||
for sym in ["0", "1"]:
|
||||
classic[("copy_1", sym)] = ("copy_1", sym, "R")
|
||||
classic[("copy_0", sym)] = ("copy_0", sym, "R")
|
||||
|
||||
classic[("copy_1", " ")] = ("back", "1", "L")
|
||||
classic[("copy_0", " ")] = ("back", "0", "L")
|
||||
|
||||
for sym in ["0", "1", " "]:
|
||||
classic[("back", sym)] = ("back", sym, "L")
|
||||
|
||||
for sym, target in [("X", "1"), ("Y", "0")]:
|
||||
classic[("back", sym)] = ("want_copy", target, "R")
|
||||
|
||||
classic[("want_copy", " ")] = ("accept", " ", "R")
|
||||
|
||||
tm_classic = TuringMachine(
|
||||
transition_function=classic,
|
||||
start_state="want_copy",
|
||||
accept_state="accept",
|
||||
reject_state="reject",
|
||||
)
|
||||
|
||||
final_state, final_tape = tm_classic.run(tape_input)
|
||||
print("Final State (Classic):", final_state)
|
||||
final_tape_str = "".join(final_tape).strip()
|
||||
print("Final Tape (Classic):", final_tape_str)
|
||||
|
||||
# for now it will copy with a blank in between. so 00110 → 00110 00110, not 0011000110. but it works. and the other one works too. so that's good enough for now.
|
||||
|
||||
left_shift_1: TransitionFunction = {}
|
||||
|
||||
left_shift_1[("want_copy", "1")] = ("copy_1", " ", "L")
|
||||
left_shift_1[("want_copy", "0")] = ("copy_0", " ", "L")
|
||||
left_shift_1[("want_copy", " ")] = ("accept", " ", "R")
|
||||
|
||||
for sym, target in [("copy_0", "0"), ("copy_1", "1")]:
|
||||
# override for now, i can make a wrapping one but i wont
|
||||
left_shift_1[(sym, "1")] = ("going_balls", target, "R")
|
||||
left_shift_1[(sym, "0")] = ("going_balls", target, "R")
|
||||
left_shift_1[(sym, " ")] = ("going_balls", target, "R")
|
||||
|
||||
left_shift_1[("going_balls", " ")] = ("want_copy", " ", "R")
|
||||
|
||||
left_shift_machine = TuringMachine(
|
||||
transition_function=left_shift_1,
|
||||
start_state="want_copy",
|
||||
accept_state="accept",
|
||||
reject_state="reject",
|
||||
)
|
||||
|
||||
left_shift_input = "101010"
|
||||
|
||||
left_shift_final_state, left_shift_final_tape = left_shift_machine.run(
|
||||
left_shift_input, head=1
|
||||
)
|
||||
print("Final State (Left Shift):", left_shift_final_state)
|
||||
left_shift_final_tape_str = "".join(left_shift_final_tape).strip()
|
||||
print("Final Tape (Left Shift):", left_shift_final_tape_str)
|
||||
Reference in new issue
Block a user