small pixel drawing of a pufferfish existentialcrisis.sh

Voila, sadness
Jes Olson j3s@c3f.net
Tue, 25 Jan 2022 05:21:21 -0600
commit

defdf186908af34a3be5ef67ddc0eb75f0a84755

parent

62d34276c33f5d0c1d0ea61bf9252a2ff04ba3a2

5 files changed, 147 insertions(+), 40 deletions(-)

jump to
M main.gomain.go

@@ -5,6 +5,7 @@ "html/template"

"path/filepath" "net/http" "log" + "time" "strconv" "os" "fmt"

@@ -14,7 +15,9 @@

func main() { http.HandleFunc("/", serveTemplate) http.HandleFunc("/api/v1/crisis/quote", quoteHandler) - http.HandleFunc("/api/v1/crisis/life", lifeHandler) + http.HandleFunc("/api/v1/crisis/saturday", saturdayHandler) + http.HandleFunc("/api/v1/crisis/remember", rememberHandler) + http.HandleFunc("/api/v1/crisis/percentage", percentageHandler) log.Println("listening on :4357 tbh") err := http.ListenAndServe(":4357", nil)

@@ -64,7 +67,7 @@ randomQuote := quote.GetRandomQuote()

fmt.Fprintf(w, randomQuote) } -func lifeHandler(w http.ResponseWriter, r *http.Request) { +func saturdayHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") ageraw, _ := r.URL.Query()["age"]

@@ -81,24 +84,111 @@ }

yearsTilDeath := 77 - age weeksToLive := yearsTilDeath * 52 - text := "saturdays of your life:\n\n" - weeksOfLifeOnAverage := 4004 - weekOfLifeYouAreOn := weeksOfLifeOnAverage - weeksToLive + weeksLived := age * 52 - for i := 0; i < weeksOfLifeOnAverage; i++ { - if i == weekOfLifeYouAreOn { - text = text + "\n[*] you are here\n" - log.Println(i) - } else if i % 50 == 0 { - text = text + "*\n" - } else { - text = text + "*" - } + var text string + if age > 77 { + text = "" + } else { + text = fmt.Sprintf("you have lived through ~%d saturdays\n\n~%d saturdays remain", weeksLived, weeksToLive) + } - if age >= 77 { - text = "any day now" - } + fmt.Fprintf(w, text) +} + +func rememberHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + + yearsraw, _ := r.URL.Query()["years"] + years, err := strconv.Atoi(yearsraw[0]) + if err != nil { + http.Error(w, http.StatusText(500), 500) + return } + ageraw, _ := r.URL.Query()["age"] + age, err := strconv.Atoi(ageraw[0]) + if err != nil { + http.Error(w, http.StatusText(500), 500) + return + } + + if ! (1 <= years && years <= 1000) { + http.Error(w, http.StatusText(500), 500) + return + } + if ! (1 <= age && age <= 100) { + http.Error(w, http.StatusText(500), 500) + return + } + + t := time.Now() + nowYear := t.Year() + predictionYear := nowYear + years + predictionAge := age + years + + var firstTense string + var secondTense string + var thirdTense string + var peopleWhoKnowYou int + var peopleWhoLoveYouDearly int + var peopleWhoKnewYouThatDied int + var peopleWhoLovedYouThatDied int + var status string + if predictionAge < 77 { + status = "alive" + } else { + status = "dead" + yearsPostDeath := predictionAge - 77 + peopleWhoKnewYouThatDied = yearsPostDeath * 10 + peopleWhoLovedYouThatDied = yearsPostDeath * 1 + } + + if status == "alive" { + firstTense = "you are" + secondTense = "know you" + thirdTense = "love" + peopleWhoKnowYou = predictionAge * 10 + peopleWhoLoveYouDearly = predictionAge * 1 + } else { + firstTense = "you would have been" + secondTense = "remember you" + thirdTense = "loved" + peopleWhoKnowYou = 770 - peopleWhoKnewYouThatDied + peopleWhoLoveYouDearly = 77 - peopleWhoLovedYouThatDied + } + + if peopleWhoKnowYou < 0 { + peopleWhoKnowYou = 0 + } + + if peopleWhoLoveYouDearly < 0 { + peopleWhoLoveYouDearly = 0 + } + + text := fmt.Sprintf("in the year %d you are %s. %s %d. %d people %s, and %d of them %s you dearly.", predictionYear, status, firstTense, predictionAge, peopleWhoKnowYou, secondTense, peopleWhoLoveYouDearly, thirdTense) + + fmt.Fprintf(w, text) +} + +func percentageHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + + ageraw, _ := r.URL.Query()["age"] + age, err := strconv.Atoi(ageraw[0]) + if err != nil { + http.Error(w, http.StatusText(500), 500) + return + } + + if ! (1 <= age && age <= 100) { + http.Error(w, http.StatusText(500), 500) + return + } + agef := float64(age) + + percentageCompleted := agef / 77.0 * 100 + + text := fmt.Sprintf("%f", percentageCompleted) fmt.Fprintf(w, text) }
M quote/quote.goquote/quote.go

@@ -23,9 +23,17 @@ quoteCollection = append(quoteCollection, "I was assailed by memories of a life that wasn't mine anymore, but one in which I'd found the simplest and most lasting joys: the smells of summer, the part of town I loved, a certain evening sky, Marie's dresses and the way she laughed.")

quoteCollection = append(quoteCollection, "Every existing thing is born without reason, prolongs itself out of weakness and dies by chance.") quoteCollection = append(quoteCollection, "Life has no meaning the moment you lose the illusion of being eternal.") quoteCollection = append(quoteCollection, "All human activities are equivalent. All are on principle doomed to failure.") - quoteCollection = append(quoteCollection, "Time is too large. It can’t be filled up. Everything you plunge into it is stretched and disintegrates.") + quoteCollection = append(quoteCollection, "Time is too large. It can't be filled up. Everything you plunge into it is stretched and disintegrates.") quoteCollection = append(quoteCollection, "All the labor of all the ages, all the devotion, all the inspiration, all the noonday brightness of human genius are destined to extinction.") quoteCollection = append(quoteCollection, "And yet sometimes we become the person we most dread. Or maybe we dread most the person we know we are to become.") + quoteCollection = append(quoteCollection, "Everyone you meet will die. After a few decades of you being dead, people will forget you.") + quoteCollection = append(quoteCollection, "We have yet to identify any kind of empirical evidence for the persistence of consciousness. It's very likely none of us are actually alive, and that dying and going to sleep are, from a practical standpoint, the exact same thing.") + quoteCollection = append(quoteCollection, "To cause birth is to cause death.") + quoteCollection = append(quoteCollection, "On a long enough timeline the survival rate of everything declines to 0.") + quoteCollection = append(quoteCollection, "Please wake up, we all miss you so much.") + quoteCollection = append(quoteCollection, "Your memory will become an abstract notion - if it survives at all.") + quoteCollection = append(quoteCollection, "") + quoteCollection = append(quoteCollection, "") } func GetRandomQuote() string {
D templates/api.html

@@ -1,17 +0,0 @@

-{{define "title"}}existentialcrisis.sh/api{{end}} -{{define "body"}} -<p>The below tools should all be very helpful in triggering an existential crisis. They are used inadvertently by the author every day.</p> -<h4>receive an existential quote that may trigger a crisis</h4> -<pre>GET <a href="/api/v1/crisis/quote">/api/v1/crisis/quote</a></pre> - -<h4>estimate the amount of time you have left alive on average, based on your age</h4> -<pre>GET <a href="/api/v1/crisis/life?age=28">/api/v1/crisis/life?age=N</a> -N = your age (1-100)</pre> - -<h4>estimate the number of people who will remember you in a given number of years</h4> -<pre>GET <a href="/api/v1/crisis/remember?years=100">/api/v1/crisis/remember?years=N</a> -N = number of years</pre> - -<h4>estimate how valuable your legacy will be</h4> -<pre>GET <a href="/api/v1/crisis/legacy">/api/v1/crisis/legacy</a></pre> -{{end}}
M templates/index.htmltemplates/index.html

@@ -1,7 +1,23 @@

{{define "title"}}existentialcrisis.sh{{end}} {{define "body"}} <p>existentialcrisis.sh is a powerful API toolkit that you may use if you'd like to have an existential crisis.</p> -<p>it's very simple to use - we offer a variety of methods for inducing dread.</p> -<p>see our <a href="/api.html">api docs</a>.</p> -<p>ugh</p> +<p>The below tools should all be very helpful in triggering an existential crisis. They are used inadvertently by the author every day.</p> +<hr> +<h2>receive a quote that may induce existential dread</h2> +<pre>GET <a href="/api/v1/crisis/quote">/api/v1/crisis/quote</a></pre> +<hr> +<h2>estimate the percentage of life you have lived</h2> +<pre>GET <a href="/api/v1/crisis/percentage?age=28">/api/v1/crisis/percentage?age=X</a> +X = your age (1-100)</pre> +<hr> +<h2>estimate the number of saturdays remaining</h2> +<pre>GET <a href="/api/v1/crisis/saturday?age=28">/api/v1/crisis/saturday?age=X</a> +X = your age (1-100)</pre> +<hr> +<h2>estimate the number of people who will remember you in a given number of years</h2> +<pre>GET <a href="/api/v1/crisis/remember?age=28&years=100">/api/v1/crisis/remember?age=X&years=Y</a> +X = your age (1-100) +Y = number of years from now (1-1000)</pre> +<hr> +<sub>❀ made with love and sadness by j3s</sub> {{end}}
M templates/layout.htmltemplates/layout.html

@@ -2,13 +2,23 @@ {{define "layout"}}

<!doctype html> <html> <head> + <style> + body {background-color: #222222;} + a {color: #ffffff;} + pre {color: #ffffff;} + sub {color: #4e4e4e;} + h1,h2,h3,h4 {color: #ffffff;} + p {color: #ffffff96;} + </style> + <!-- a j3s.sh production --> <meta charset="utf-8"> + <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22><text y=%2226%22 font-size=%2226%22>πŸ’€</text></svg>"> <title>{{template "title"}}</title> </head> <body> - <h1><a href="/">😱</a> existentialcrisis.sh</h1> -<p><a href="/api.html">api</a> <a href="/features.html">features</a> <a href="/pricing.html">pricing</a> <a href="/why.html">WHY??</a></p> + <h1><a href="/">πŸ’€</a> existentialcrisis.sh</h1> +<p><a href="/features.html">features</a> <a href="/pricing.html">pricing</a> {{template "body"}} </body> </html>