moves
This commit is contained in:
1 parent
107e880cf8
commit
1030e9d739
5 files changed
No files matched your search
@@ -0,0 +1,34 @@
|
||||
def next_number(n: int, base: int):
|
||||
dih = n # DIH
|
||||
bih = 1 # track position of first not largest
|
||||
cih = 0 # number until not largest
|
||||
fih = -1 # digit cumulate
|
||||
while dih:
|
||||
if fih > (gih := dih % base):
|
||||
fih = gih
|
||||
break
|
||||
fih = gih
|
||||
cih = cih + gih * bih
|
||||
bih *= base
|
||||
dih //= base
|
||||
print(bih, cih, dih, fih, gih, base)
|
||||
assert n == (cih + dih * bih)
|
||||
assert dih % base == fih
|
||||
assert n == cih + dih * bih
|
||||
dih //= base
|
||||
print(fih * bih + cih)
|
||||
gih = 1 # track position of first larger
|
||||
hih = cih
|
||||
ret = 0 # realest
|
||||
while hih:
|
||||
if fih < (jih := hih % base):
|
||||
ret += jih * gih
|
||||
ret = ret * base + fih
|
||||
fih = base + 1
|
||||
else:
|
||||
ret = ret * base + jih
|
||||
hih //= base
|
||||
gih *= base
|
||||
print(gih, ret, hih, fih, jih)
|
||||
print(dih)
|
||||
return ret + dih * base * bih
|
||||
@@ -0,0 +1,60 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/qrcode.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<textarea
|
||||
name="what"
|
||||
id="wow"
|
||||
rows="20"
|
||||
cols="100"
|
||||
style="min-width: 20%; min-height: 20dvh"
|
||||
></textarea>
|
||||
<button type="button" id="cuh">cuh</button>
|
||||
<div id="qrcode"></div>
|
||||
<script>
|
||||
/** @type { HTMLTextAreaElement } */
|
||||
const wow = document.getElementById("wow");
|
||||
/** @type { HTMLDivElement } */
|
||||
const qrcode = document.getElementById("qrcode");
|
||||
const cuh = () => {
|
||||
for (const i of wow.value.split(/\r?\n/)) {
|
||||
const l = i.split("|", 1)[0].trim();
|
||||
const d = document.createElement("div");
|
||||
const h = document.createElement("a");
|
||||
h.href = l;
|
||||
h.textContent = l;
|
||||
console.log(l);
|
||||
const a = document.createElement("div");
|
||||
try {
|
||||
new QRCode(a, {
|
||||
text: l,
|
||||
correctLevel: QRCode.CorrectLevel.L,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
d.appendChild(h);
|
||||
d.appendChild(a);
|
||||
qrcode.appendChild(d);
|
||||
}
|
||||
};
|
||||
window.addEventListener("load", (_) => {
|
||||
wow.value = decodeURI(
|
||||
new URLSearchParams(window.location.search).get("data") ??
|
||||
""
|
||||
);
|
||||
document.getElementById("cuh").addEventListener("click", cuh);
|
||||
wow.addEventListener("input", (_) => {
|
||||
const f = new URL(window.location.href);
|
||||
f.searchParams.set("data", wow.value);
|
||||
history.replaceState(null, "", f.href);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
import io
|
||||
from sys import stdin
|
||||
import qrcode
|
||||
|
||||
|
||||
def link_extract_from_onetab(line):
|
||||
"link | title"
|
||||
link = line.split("|", 1)[0].strip()
|
||||
return link
|
||||
|
||||
|
||||
def qrcodify(link):
|
||||
q = qrcode.QRCode()
|
||||
q.add_data(link)
|
||||
a = io.StringIO()
|
||||
q.print_ascii(a)
|
||||
return a.getvalue()
|
||||
|
||||
|
||||
def fuck(line):
|
||||
link = link_extract_from_onetab(line)
|
||||
print(link)
|
||||
print(qrcodify(link))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
list(map(fuck, stdin.readlines()))
|
||||
@@ -0,0 +1,45 @@
|
||||
"why outdated"
|
||||
|
||||
from collections import deque
|
||||
|
||||
import flask
|
||||
|
||||
|
||||
def link_extract_from_onetab(line):
|
||||
"link | title"
|
||||
link = line.split("|", 1)[0].strip()
|
||||
return link
|
||||
|
||||
|
||||
a = flask.Flask(__name__)
|
||||
queue: deque[str] = deque()
|
||||
|
||||
|
||||
@a.route("/q")
|
||||
def no():
|
||||
"if i click the link then it proceed. if i reload it doesnt."
|
||||
current_link = queue[0] if queue else None
|
||||
return flask.render_template("reader.html", current_link=current_link)
|
||||
|
||||
|
||||
@a.route("/r")
|
||||
def redir():
|
||||
"reload == proceed"
|
||||
if queue:
|
||||
q = queue.popleft()
|
||||
return flask.redirect(q)
|
||||
return flask.render_template("reader.html", current_link=None)
|
||||
|
||||
|
||||
@a.route("/queuein", methods=["GET", "POST"])
|
||||
def cuh():
|
||||
if flask.request.method == "POST":
|
||||
for line in flask.request.form.get("l", "").splitlines():
|
||||
queue.append(link_extract_from_onetab(line))
|
||||
return flask.redirect("/queuein", 303)
|
||||
return flask.render_template("queue.html", queue_items=list(queue))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
a.run("0.0.0.0", 2222)
|
||||
# flask --app .\uhhhh.py run -h "0.0.0.0" -p 2222
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
"gemini converted"
|
||||
|
||||
import socket
|
||||
import string
|
||||
from collections import deque
|
||||
from itertools import islice
|
||||
from random import choice
|
||||
from typing import Optional
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
from fastapi import FastAPI, Form, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse, PlainTextResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
queue: deque[str] = deque() # fifo ahh
|
||||
|
||||
|
||||
def get_local_ip():
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
try:
|
||||
# doesn't even have to be reachable
|
||||
s.connect(("10.255.255.255", 1))
|
||||
IP = s.getsockname()[0]
|
||||
except Exception:
|
||||
IP = "127.0.0.1"
|
||||
finally:
|
||||
s.close()
|
||||
return IP
|
||||
|
||||
|
||||
def link_extract_from_onetab(line: str) -> str:
|
||||
"link | title"
|
||||
link = line.split("|", 1)[0].strip()
|
||||
return urlunsplit(urlsplit(link)) # encoded is xn something
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request):
|
||||
"idgaf"
|
||||
# Construct the URL using the local IP
|
||||
port = request.url.port or 2222
|
||||
local_ip = get_local_ip()
|
||||
page_url = f"{request.url.scheme}://{local_ip}:{port}"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
request, "index.html", {"routes": app.routes, "page_url": page_url}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/q", response_class=HTMLResponse)
|
||||
async def no(request: Request):
|
||||
current_link = queue[0] if queue else None
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"reader.html",
|
||||
{"current_link": current_link, "queue_length": len(queue)},
|
||||
)
|
||||
|
||||
|
||||
@app.get("/t", response_class=HTMLResponse)
|
||||
async def trail(request: Request):
|
||||
current_link = queue[0] if queue else None
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"trail.html",
|
||||
{"current_link": current_link, "queue_length": len(queue)},
|
||||
)
|
||||
|
||||
|
||||
@app.get("/r")
|
||||
async def redir(request: Request):
|
||||
if queue:
|
||||
q = queue.popleft()
|
||||
return RedirectResponse(url=q)
|
||||
return templates.TemplateResponse(
|
||||
request, "reader.html", {"current_link": None, "queue_length": len(queue)}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/m", response_class=HTMLResponse)
|
||||
async def mlti(request: Request):
|
||||
"""request first new style.
|
||||
js still breaking (on mobile. they dont like mass popups) im so sad
|
||||
"""
|
||||
return templates.TemplateResponse(request, "multi.html")
|
||||
|
||||
|
||||
@app.get("/api/queue")
|
||||
async def queue_view(n: int | None = None, s: int | None = None):
|
||||
return list(islice(queue, s, n))
|
||||
|
||||
|
||||
@app.get("/api/queue/len")
|
||||
async def queue_len():
|
||||
return len(queue)
|
||||
|
||||
|
||||
@app.post("/api/queue/clear")
|
||||
async def clear_queue():
|
||||
queue.clear()
|
||||
|
||||
|
||||
@app.get("/qrcode_queue", response_class=HTMLResponse)
|
||||
async def qrcodequeue(request: Request):
|
||||
return templates.TemplateResponse(request, "qq.html", {"queue_items": list(queue)})
|
||||
|
||||
|
||||
@app.get("/queuein", response_class=HTMLResponse)
|
||||
async def queue_in(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
request, "queue.html", {"queue_items": list(queue)}
|
||||
)
|
||||
|
||||
|
||||
@app.post("/queuein")
|
||||
async def send_queue(lines: str = Form("")):
|
||||
"""var name == form ele name (name="lines")"""
|
||||
queue.extend(
|
||||
link_extract_from_onetab(line) for line in lines.splitlines() if line.strip()
|
||||
)
|
||||
return RedirectResponse(url="/queuein", status_code=303)
|
||||
|
||||
|
||||
texts: dict[str, str] = {} # name (auto or rewrite): content
|
||||
|
||||
|
||||
class Paste(BaseModel):
|
||||
content: str
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
@app.get("/pastepad")
|
||||
async def pastepad_ui(request: Request):
|
||||
return templates.TemplateResponse(request, "pastepad.html")
|
||||
|
||||
|
||||
def random_str(length: int = 8, charset=string.ascii_letters + string.digits):
|
||||
return "".join(choice(charset) for _ in range(length))
|
||||
|
||||
|
||||
@app.get("/api/pastepad")
|
||||
async def paste_list():
|
||||
return [{"name": n, "content": c} for n, c in texts.items()]
|
||||
|
||||
|
||||
@app.post("/api/pastepad", status_code=201)
|
||||
async def paste_create(paste: Paste):
|
||||
"""Create a new paste. If name is provided and exists, returns 409."""
|
||||
if paste.name and paste.name in texts:
|
||||
raise HTTPException(status_code=409, detail="Paste name already exists")
|
||||
|
||||
name = paste.name or random_str()
|
||||
while name in texts: # collision check for random
|
||||
name = random_str()
|
||||
|
||||
texts[name] = paste.content
|
||||
return {"name": name, "content": texts[name]}
|
||||
|
||||
|
||||
@app.get("/api/pastepad/{name}")
|
||||
async def paste_get(name: str):
|
||||
if name not in texts:
|
||||
raise HTTPException(status_code=404, detail="Paste not found")
|
||||
return {"name": name, "content": texts[name]}
|
||||
|
||||
|
||||
@app.get("/api/pastepad/{name}/raw", response_class=PlainTextResponse)
|
||||
async def paste_get_raw(name: str):
|
||||
"""Return just the raw text content, useful for curl or scripts."""
|
||||
if name not in texts:
|
||||
raise HTTPException(status_code=404, detail="Paste not found")
|
||||
return texts[name]
|
||||
|
||||
|
||||
@app.put("/api/pastepad/{name}")
|
||||
async def paste_update(name: str, paste: Paste):
|
||||
"""Update an existing paste."""
|
||||
if name not in texts:
|
||||
raise HTTPException(status_code=404, detail="Paste not found")
|
||||
|
||||
texts[name] = paste.content
|
||||
return {"name": name, "content": texts[name]}
|
||||
|
||||
|
||||
@app.delete("/api/pastepad/{name}")
|
||||
async def paste_delete(name: str):
|
||||
if name not in texts:
|
||||
raise HTTPException(status_code=404, detail="Paste not found")
|
||||
|
||||
content = texts.pop(name)
|
||||
return {"name": name, "content": content}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("uhhhhup:app", host="0.0.0.0", port=2222, reload=True)
|
||||
# uvicorn --host "0.0.0.0" --port 2222 --reload uhhhhup:app
|
||||
Reference in new issue
Block a user