This commit is contained in:
kejaro committed 2026-10-07 12:31:50 +01:00
1 parent d0ff21db2e
commit ea974f6704
18 files changed
+535

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
from collections import Counter
import urllib.request
def load_dictionary():
"""Download and return a clean set of valid English words."""
url = "https://raw.githubusercontent.com/raun/Scrabble/master/words.txt"
with urllib.request.urlopen(url) as response:
words = response.read().decode("utf-8").splitlines()
# Filter out proper nouns/short words and normalize to lowercase
return [
word.strip().lower()
for word in words
if word.isalpha() and 2 <= len(word) <= 9
]
def solve_countdown(letters, dictionary):
"""Find the longest valid words that can be formed from the input letters."""
letters_count = Counter(letters.lower())
valid_words = []
for word in dictionary:
# Check if word letter frequencies fit within the available letters
if not (Counter(word) - letters_count):
valid_words.append(word)
# Sort by word length (descending), then alphabetically
valid_words.sort(key=lambda w: (-len(w), w))
return valid_words
if __name__ == "__main__":
print("Loading word list...")
dictionary = load_dictionary()
rack = input("\nEnter your letters (e.g., 'mdaisuteo'): ").strip()
matches = solve_countdown(rack, dictionary)
if not matches:
print("No valid words found.")
else:
max_len = len(matches[0])
print(f"\nLongest word length: {max_len} letters")
print("--- Top Matches ---")
# Group and display top results by length
current_len = 0
for word in matches[:20]: # Show top 20 matches
if len(word) != current_len:
current_len = len(word)
print(f"\n{current_len}-letter words:")
print(f" • {word}")
+173
View File
@@ -0,0 +1,173 @@
import sys
import threading
import urllib.request
from collections import Counter
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gtk
# --- Core Countdown Logic ---
def fetch_dictionary():
"""Download and filter valid English words."""
url = "https://raw.githubusercontent.com/raun/Scrabble/master/words.txt"
try:
with urllib.request.urlopen(url, timeout=10) as response:
words = response.read().decode("utf-8").splitlines()
return [
w.strip().lower()
for w in words
if w.isalpha() and 2 <= len(w) <= 9
]
except Exception as e:
print(f"Error fetching dictionary: {e}")
return []
def solve_countdown(letters, dictionary):
"""Find and return matching words sorted by length (descending)."""
letters_count = Counter(letters.lower())
valid_words = []
for word in dictionary:
if not (Counter(word) - letters_count):
valid_words.append(word)
valid_words.sort(key=lambda w: (-len(w), w))
return valid_words
# --- GTK 4 Application Window ---
class CountdownWindow(Gtk.ApplicationWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs, title="Countdown Solver")
self.set_default_size(480, 550)
self.dictionary = []
# --- Main Layout Box ---
main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
main_box.set_margin_top(16)
main_box.set_margin_bottom(16)
main_box.set_margin_start(16)
main_box.set_margin_end(16)
self.set_child(main_box)
# --- Input Section ---
input_box = Gtk.Box(
orientation=Gtk.Orientation.HORIZONTAL, spacing=8
)
self.entry = Gtk.Entry()
self.entry.set_placeholder_text("Enter letters (e.g. mdaisuteo)...")
self.entry.set_hexpand(True)
self.entry.connect("activate", self.on_solve_clicked) # Trigger on Enter
input_box.append(self.entry)
self.solve_button = Gtk.Button(label="Solve")
self.solve_button.connect("clicked", self.on_solve_clicked)
self.solve_button.set_sensitive(False) # Disabled until dictionary loads
input_box.append(self.solve_button)
main_box.append(input_box)
# --- Status / Info Label ---
self.status_label = Gtk.Label(
label="Downloading word list in background..."
)
self.status_label.set_xalign(0)
main_box.append(self.status_label)
# --- Results List Box in Scrolled Window ---
scrolled = Gtk.ScrolledWindow()
scrolled.set_vexpand(True)
self.list_box = Gtk.ListBox()
self.list_box.set_selection_mode(Gtk.SelectionMode.NONE)
scrolled.set_child(self.list_box)
main_box.append(scrolled)
# --- Load Dictionary Asynchronously ---
threading.Thread(target=self._load_dictionary_thread, daemon=True).start()
def _load_dictionary_thread(self):
"""Fetch dictionary off the main thread."""
words = fetch_dictionary()
# Schedule GUI updates on the main GTK thread
GLib.idle_add(self._on_dictionary_loaded, words)
def _on_dictionary_loaded(self, words):
"""Update UI state once dictionary is ready."""
self.dictionary = words
if words:
self.status_label.set_text(
f"Dictionary loaded ({len(words):,} words). Ready!"
)
self.solve_button.set_sensitive(True)
else:
self.status_label.set_text("Failed to load dictionary. Check connection.")
def on_solve_clicked(self, widget):
"""Handle solve trigger."""
letters = self.entry.get_text().strip()
if not letters or not self.dictionary:
return
# Clear existing result rows
while child := self.list_box.get_first_child():
self.list_box.remove(child)
matches = solve_countdown(letters, self.dictionary)
if not matches:
self.status_label.set_text("No valid words found.")
return
max_len = len(matches[0])
self.status_label.set_text(
f"Found {len(matches)} words (Longest: {max_len} letters)"
)
current_len = 0
for word in matches:
word_len = len(word)
# Insert section header row when length changes
if word_len != current_len:
current_len = word_len
header_label = Gtk.Label()
header_label.set_markup(
f"<b>{current_len}-Letter Words</b>"
)
header_label.set_xalign(0)
header_label.set_margin_top(8)
header_label.set_margin_bottom(4)
self.list_box.append(header_label)
# Word row
row_label = Gtk.Label(label=f" • {word}")
row_label.set_xalign(0)
row_label.set_margin_start(8)
self.list_box.append(row_label)
# --- GTK Application Entry Point ---
class CountdownApp(Gtk.Application):
def __init__(self):
super().__init__(application_id="org.countdown.solver")
def do_activate(self):
win = self.props.active_window
if not win:
win = CountdownWindow(application=self)
win.present()
if __name__ == "__main__":
app = CountdownApp()
app.run(sys.argv)
+90
View File
@@ -0,0 +1,90 @@
import itertools
def solve_countdown(numbers, target):
"""
Solves the Countdown numbers game.
Returns (closest_target, math_expression_string).
"""
# Memoization dictionary: maps frozen sets of numbers to expressions
# Structure: { numbers_tuple: { value: expression_string } }
memo = {}
def get_all_results(nums):
# Sort to ensure consistent dictionary key representation
key = tuple(sorted(nums))
if key in memo:
return memo[key]
results = {}
# Base case: single number
if len(nums) == 1:
results[nums[0]] = str(nums[0])
memo[key] = results
return results
# Try all partitions of the list into two non-empty subsets
n = len(nums)
for i in range(1, n):
for left_indices in itertools.combinations(range(n), i):
right_indices = [j for j in range(n) if j not in left_indices]
left_nums = [nums[j] for j in left_indices]
right_nums = [nums[j] for j in right_indices]
left_results = get_all_results(left_nums)
right_results = get_all_results(right_nums)
for l_val, l_expr in left_results.items():
for r_val, r_expr in right_results.items():
# Addition
val = l_val + r_val
if val not in results:
results[val] = f"({l_expr} + {r_expr})"
# Subtraction (Countdown rules: results must be positive integers)
if l_val > r_val:
val = l_val - r_val
if val not in results:
results[val] = f"({l_expr} - {r_expr})"
# Multiplication
if l_val > 1 and r_val > 1: # Avoid trivial x * 1
val = l_val * r_val
if val not in results:
results[val] = f"({l_expr} * {r_expr})"
# Division (Countdown rules: exact integer division only)
if r_val > 1 and l_val % r_val == 0:
val = l_val // r_val
if val not in results:
results[val] = f"({l_expr} / {r_expr})"
memo[key] = results
return results
# Evaluate all valid combinations across all possible subset sizes (1 to len(numbers))
all_possible = {}
for r in range(1, len(numbers) + 1):
for sub in itertools.combinations(numbers, r):
res = get_all_results(sub)
all_possible.update(res)
# Check for exact match
if target in all_possible:
return target, all_possible[target]
# Find closest match if exact target isn't reachable
closest_val = min(all_possible.keys(), key=lambda x: abs(x - target))
return closest_val, all_possible[closest_val]
# --- Example Usage ---
if __name__ == "__main__":
nums = [6, 7, 6, 8, 6, 3]
target = 854
result_val, expression = solve_countdown(nums, target)
print(f"Target: {target}")
print(f"Reached: {result_val}")
print(f"Solution: {expression}")
Binary file not shown.
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
set -e
# Must run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)"
exit 1
fi
# Need at least 2 args: user + 1 group
if [ $# -lt 2 ]; then
echo "Usage: $0 <username> <group1> [group2 group3 ...]"
exit 1
fi
USER_NAME="$1"
shift # remove username, leaving groups
# Check user exists
if ! id "$USER_NAME" &>/dev/null; then
echo "User '$USER_NAME' does not exist"
exit 1
fi
for GROUP_NAME in "$@"; do
# Create group if it doesn't exist
if ! getent group "$GROUP_NAME" >/dev/null; then
echo "Group '$GROUP_NAME' does not exist, creating..."
groupadd "$GROUP_NAME"
fi
echo "Adding $USER_NAME to $GROUP_NAME"
usermod -aG "$GROUP_NAME" "$USER_NAME"
done
echo "Done."
echo "Updated groups for $USER_NAME:"
id "$USER_NAME"
Binary file not shown.
+113
View File
@@ -0,0 +1,113 @@
sudo dnf update -y
sudo dnf install -y ./rpmfusion-free-release-44.noarch.rpm
sudo dnf install -y ./rpmfusion-nonfree-release-44.noarch.rpm
sudo dnf update @core -y
sudo dnf install rpmfusion-\*-appstream-data
sudo dnf swap -y ffmpeg-free ffmpeg --allowerasing
sudo dnf update -y @multimedia --setopt="install_weak_deps=False" --exclude=PackageKit-gstreamer-plugin
sudo dnf install -y mesa-va-drivers-freeworld
sudo dnf update -y
sudo dnf remove -y firefox
sudo dnf remove -y gnome-tour
sudo dnf install -y audacity
sudo dnf install -y blender
sudo dnf install -y darktable
sudo dnf install -y deskflow
sudo dnf install -y digikam
sudo dnf install -y fritzing
sudo dnf install -y gimp
sudo dnf install -y gparted
sudo dnf install -y gnome-tweaks
sudo dnf install -y inkscape
sudo dnf install -y meld
sudo dnf install -y obs-studio
sudo dnf install -y picard
sudo dnf install -y rawtherapee
sudo dnf install -y thonny
sudo dnf install -y transmission
sudo dnf install -y video-downloader
sudo dnf install -y wireshark
sudo dnf install -y vlc
sudo dnf install -y ddcutil
sudo dnf install kernel-headers-$(uname -r) gcc python3-devel
sudo dnf --nogpgcheck -y install ./03_tethering_RapidRAW*.rpm
sudo dnf --nogpgcheck -y install ./vivaldi-stable-*.rpm
sudo dnf update -y
sudo flatpak install -y flathub it.mijorus.gearlever
sudo flatpak install -y flathub org.gnome.World.PikaBackup
sudo flatpak install -y flathub com.boxy_svg.BoxySVG
sudo flatpak install -y flathub org.freecad.FreeCAD
sudo flatpak install -y flathub org.gnome.Extensions
sudo flatpak install -y flathub com.mattjakeman.ExtensionManager
sudo flatpak install -y flathub io.github.nokse22.Exhibit
sudo flatpak install -y flathub com.bitwarden.desktop
sudo flatpak install -y flathub com.google.AndroidStudio
sudo flatpak install -y flathub com.orcaslicer.OrcaSlicer
sudo gnome-extensions install ./AlphabeticalAppGridstuarthayhurst.v44.shell-extension.zip
sudo gnome-extensions install ./appindicatorsupportrgcjonas.gmail.com.v64.shell-extension.zip
sudo gnome-extensions install ./clipboard-indicatortudmotu.com.v71.shell-extension.zip
sudo gnome-extensions install ./dash-to-dockmicxgx.gmail.com.v105.shell-extension.zip
sudo mkdir /nas /nas/backup /nas/documents /nas/downloads /nas/media /nas/software
sudo sh -c 'echo "
//192.168.8.2/backup /nas/backup cifs username=Keith,password=N7pg3KMM7y5j88K3257c,vers=2.0,uid=1000,gid=1000 0 2
//192.168.8.2/documents /nas/documents cifs username=Keith,password=N7pg3KMM7y5j88K3257c,vers=2.0,uid=1000,gid=1000 0 2
//192.168.8.2/downloads /nas/downloads cifs username=Keith,password=N7pg3KMM7y5j88K3257c,vers=2.0,uid=1000,gid=1000 0 2
//192.168.8.2/media /nas/media cifs username=Keith,password=N7pg3KMM7y5j88K3257c,vers=2.0,uid=1000,gid=1000 0 2
//192.168.8.2/software /nas/software cifs username=Keith,password=N7pg3KMM7y5j88K3257c,vers=2.0,uid=1000,gid=1000 0 2
" >> /etc/fstab'
sudo systemctl daemon-reload
sudo mount -a
echo 'KERNEL=="uinput", GROUP="uinput"' | sudo tee /etc/udev/rules.d/uinput.rules
echo 'SUBSYSTEM=="i2c-dev", KERNEL=="i2c-[0-9]*", GROUP="i2c"' | sudo tee /etc/udev/rules.d/45-myi2c.rules
echo 'uinput' | sudo tee /etc/modules-load.d/uinput.conf
sudo dnf config-manager addrepo --from-repofile https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable --now docker
sudo dnf install -y @virtualization
sudo systemctl enable --now libvirtd
sudo ./add-user-multi-groups.sh keith docker libvirt dialout input uinput i2c
sudo mkdir /opt/macroPad
sudo chown keith /opt/macroPad
cp /home/keith/Documents/code/kejaro_macroPad/macroPad/device.py /opt/macroPad/
cp /home/keith/Documents/code/kejaro_macroPad/macroPad/monitors.py /opt/macroPad/
cp /home/keith/Documents/code/kejaro_macroPad/macroPad/macroPad.py /opt/macroPad/
cp /home/keith/Documents/code/kejaro_macroPad/macroPad/device.py /opt/macroPad/
chmod +x /opt/macroPad/macroPad.py
sudo sh -c 'echo "
[Unit]
Description=kejaro_MacroPad
After=network.target
[Service]
Type=simple
User=keith
WorkingDirectory=/opt/macroPad
ExecStart=/opt/macroPad/macroPad.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
" >> /etc/systemd/system/macroPad.service'
sudo systemctl daemon-reload
sudo systemctl enable macroPad.service
sudo systemctl start macroPad.service
#curl -fsSL https://tailscale.com/install.sh | sh
#sudo tailscale set --operator=keith --accept-routes --ssh
#tailscale up
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
filename = "/home/keith/.bash_history"
seen = set()
lines = []
with open(filename, "r", encoding="utf-8") as file:
for line in file:
if line not in seen:
lines.append(line)
seen.add(line)
with open(filename, "w", encoding="utf-8") as file:
file.writelines(sorted(lines))
+42
View File
@@ -0,0 +1,42 @@
import os
from pathlib import Path
import subprocess
def create_sorted_m3u_playlist(target_folder: Path):
audio_extensions = {'.mp3', '.flac', '.m4a', '.wav', '.ogg', '.wma'}
playlist_file = target_folder.parent / f"{target_folder.name}.m3u"
music_files = []
for file_path in target_folder.rglob('*'):
if file_path.is_file() and file_path.suffix.lower() in audio_extensions:
music_files.append(file_path)
if not music_files:
print(f"No music files found in '{target_folder}'.")
return
music_files.sort(key=lambda p: (p.parent, p.name))
try:
with open(playlist_file, 'w', encoding='utf-8') as f:
f.write("#EXTM3U\n")
for file_path in music_files:
relative_path = file_path.relative_to(target_folder.parent)
f.write(f"{relative_path.as_posix()}\n")
print(f"Success! Created sorted playlist '{target_folder.name}' inside '{target_folder.parent}'.")
print(f"Added and sorted {len(music_files)} music files.")
subprocess.run(["gnome-text-editor", str(playlist_file)], check=True)
except Exception as e:
print(f"An error occurred while creating the playlist: {e}")
# --- How to run it ---
if __name__ == "__main__":
music_directory = Path(subprocess.run(["zenity", "--file-selection", "--directory","--filename=/nas/media/music/"],text=True, capture_output=True).stdout.strip())
create_sorted_m3u_playlist(music_directory)
+8
View File
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}