Conditional machine specific hostname sourcing

This commit is contained in:
Elizabeth Hunt 2023-03-15 22:50:17 -06:00
parent 4c0987e55a
commit 4dbdef1865
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
7 changed files with 196 additions and 2 deletions

@ -1 +1 @@
Subproject commit 19c231b2518efe71cb6dade3ad4cf573377902c3 Subproject commit 6d4584f01dec0143a169186df1608860d1aa1ef0

2
.zshrc
View File

@ -50,4 +50,4 @@ alias gl="git log"
alias sbcl="rlwrap sbcl" alias sbcl="rlwrap sbcl"
# Machine specific config # Machine specific config
source ~/scripts/machine-specific-zsh/$(hostname).zsh [ -f ~/scripts/machine-specific-zsh/$(hostname).zsh ] && source ~/scripts/machine-specific-zsh/$(hostname).zsh

View File

@ -0,0 +1,26 @@
(ql:quickload :woo)
(defparameter *icon-file* "~/scripts/guestbook/icon.png")
(defparameter *message-list-file* "~/scripts/guestbook/list.txt")
(defparameter *routes* (make-hash-table :test 'equal))
(defparameter *rate-limits* (make-hash-table :test 'equal))
(defparameter *not-seen-messages* '())
(defun send-alert (msg)
(uiop:run-program `("notify-send" "--icon" ,*icon-file* ,msg)))
(defun add-message (env)
(woo:run
(lambda (env)
(let* ((path-info (getf env :path-info))
(req-method (getf env :request-method))
(ip (getf env :remote-addr))
(route-fn (getf *routes* path-info
'(200 (:content-type "text/plain") ("Hello, World")))
:worker-num 1)

BIN
scripts/guestbook/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 KiB

BIN
scripts/jalarm/alarm.wav Normal file

Binary file not shown.

69
scripts/jalarm/jar.py Normal file
View File

@ -0,0 +1,69 @@
jar = {
"lineSkips": 1, # Skip the base of the jar
"height": 11, # Height you want filled to, 12 will be the very top of the jar
"width": 20,
"fillLines": [(3,16),(2,17),(2,17),(2,17),(2,17),(2,17),(2,17),(2,17),(2,17),(2,17),(2,17),(3,16)],
"text":""" | |
| |
|| ||
|| ||
|| ||
|| ||
|| ||
|| ||
|| ||
|| ||
|| ||
\\\\ //
--------------"""}
class AwesomeJar:
def __init__(self, jarObject):
self.jarObject = jarObject
self.progress = 0.00
self.dropletLine = 0
self.dropletDelta = 1
def drawJar(self):
jarRepresentation = self.jarObject["text"].split("\n")
linesToFill = int(self.progress * self.jarObject["height"])
dropletX = self.jarObject["width"] // 2
if (self.progress < 1):
jarRepresentation[self.dropletLine] = jarRepresentation[self.dropletLine][0:dropletX] + "O" + jarRepresentation[self.dropletLine][(dropletX+1):]
for y_fill in range(self.jarObject["height"] - linesToFill + self.jarObject["lineSkips"], self.jarObject["height"]+self.jarObject["lineSkips"]):
jarRepresentation[y_fill] = "".join(list(map(lambda x:
"X" if x in range(self.jarObject["fillLines"][y_fill][0],self.jarObject["fillLines"][y_fill][1]+1)
else jarRepresentation[y_fill][x], range(len(jarRepresentation[y_fill])))))
return jarRepresentation
def setProgress(self, progress):
linesToFill = int(self.progress * self.jarObject["height"])
self.dropletLine += self.dropletDelta
if self.dropletLine > self.jarObject["height"]-linesToFill:
self.progress = progress
self.dropletLine = 0
def __str__(self):
return "".join([x + "\n" for x in self.drawJar()])
if __name__ == "__main__":
newJar = AwesomeJar(jar)
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
newJar.setProgress(0.2)
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())
print(newJar.drawJar())

99
scripts/jalarm/take Executable file
View File

@ -0,0 +1,99 @@
#!/usr/bin/python3
import re
import time as t
import curses
import sys
import os
import jar
def formatTime(time):
return ((str(time[0]).zfill(2) + ":") if time[0] else "") + ((str(time[1]).zfill(2) + ":") if time[1] or time[0] else "") + (str(time[2]).zfill(2))
def timeToSeconds(time):
return time[2] + 60*time[1] + 3600*time[0]
def secondsToTime(seconds):
return [seconds // 3600, (seconds - (seconds // 3600) * 3600) // 60, seconds % 60]
def decrementTime(time):
return secondsToTime(timeToSeconds(time) - 1)
class MyTimerWindow:
def __init__(self, message="Timer"):
self.message = message
self.screen = curses.initscr()
curses.noecho()
curses.cbreak()
self.dimensions = self.screen.getmaxyx()
self.screen.keypad(True)
self.jar = jar.AwesomeJar(jar.jar)
def update(self, time, beginningTime):
self.jar.setProgress((timeToSeconds(beginningTime) - timeToSeconds(time))/timeToSeconds(beginningTime))
def step(self, time):
self.screen.clear()
self.screen.addstr(1, self.dimensions[1]//2 - len(self.message)//2, self.message)
self.screen.addstr(3, self.dimensions[1]//2 - len(formatTime(time))//2, formatTime(time))
list(map(lambda x: self.screen.addstr(8+x, self.dimensions[1]//2 - self.jar.jarObject["width"]//2, self.jar.drawJar()[x]), range(0, len(self.jar.drawJar()))))
self.screen.addstr(25,0,"")
self.screen.refresh()
def stop(self):
curses.nocbreak()
self.screen.keypad(False)
curses.echo()
curses.endwin()
os.system("aplay alarm.wav")
def main():
p = re.compile('(^[0-9]*)(?::|^)([0-9]*(?=:)):([0-9]*$)')
beginning_time = list(map(lambda x: int(x) if x else 0, p.match(sys.argv[1]).groups()))
time = beginning_time.copy()
iteration_time = t.time()
if not "file" in sys.argv:
timer = MyTimerWindow() if len(sys.argv) < 3 else MyTimerWindow(sys.argv[2])
timer.update(time, beginning_time)
while any(time):
try:
timer.step(time)
t.sleep(1)
if (t.time() - iteration_time >= 1):
iteration_time = t.time()
time = decrementTime(time)
timer.update(time, beginning_time)
timer.step(time)
except KeyboardInterrupt:
break
timer.stop()
print("\nDONE")
else:
iteration_time = t.time()
try:
pid = open("/home/logan/scripts/state-files/take/pid.txt", "r")
os.system(f"kill -9 {pid.read()} 2> /dev/null")
pid.close()
except:
os.system("mkdir -p /home/logan/scripts/state-files/take")
pass
pid = open("/home/logan/scripts/state-files/take/pid.txt", "w")
pid.write(str(os.getpid()))
pid.close()
while any(time):
t.sleep(.1)
try:
if (t.time() - iteration_time >= 1):
iteration_time = t.time()
file = open("/home/logan/scripts/state-files/take/current-time.txt", "w")
file.write(formatTime(time))
file.close()
time = decrementTime(time)
except KeyboardInterrupt:
break
file = open("/home/logan/scripts/state-files/take/current-time.txt", "w")
file.write("Not Timing")
if __name__ == "__main__":
main()