Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-04-08 13:30:53 -04:00
parent ab279fa431
commit ccc6e291fb
5 changed files with 217 additions and 1 deletions

2
.gitignore vendored
View File

@ -14,4 +14,4 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
.DS_Store

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module tulpa.dev/cadey/todayinmarch2020
go 1.16

78
main.go Normal file
View File

@ -0,0 +1,78 @@
package main
import (
"embed"
"encoding/json"
"flag"
"html/template"
"log"
"math/rand"
"net"
"net/http"
"os"
"time"
)
var (
port = flag.String("port", "23698", "TCP port to listen on")
sockPath = flag.String("socket", "", "Unix socket to listen on")
//go:embed templates/* quips.json
content embed.FS
quips []string
)
func main() {
flag.Parse()
tmpl := template.Must(template.ParseFS(content, "templates/index.html"))
fin, err := content.Open("quips.json")
if err != nil {
log.Fatal(err)
}
err = json.NewDecoder(fin).Decode(&quips)
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/", index(tmpl))
var l net.Listener
if *sockPath != "" {
os.Remove(*sockPath)
l, err = net.Listen("unix", *sockPath)
} else {
l, err = net.Listen("tcp", ":"+*port)
}
if err != nil {
log.Fatal(err)
}
srv := &http.Server{
Handler: mux,
}
log.Fatal(srv.Serve(l))
}
func index(tmpl *template.Template) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
then := time.Date(2020, time.March, 1, 0, 0, 0, 0, time.UTC)
now := time.Now().UTC()
dur := now.Sub(then)
tmpl.Execute(w, struct {
Day int
Quip string
}{
Day: int(dur.Hours() / 24),
Quip: quips[rand.Intn(len(quips))],
})
})
}

14
quips.json Normal file
View File

@ -0,0 +1,14 @@
[
"Is today gonna be the day that time comes back to us?",
"The year that's felt like a decade.",
"How deep are you into your Netflix backlog?",
"Now without JavaScript!",
"Green Leader, standing by.",
"We've strayed into a zone with a high magical index.",
"Each second that goes by feels like an eternity and nothing.",
"Never enter an arsekicking contest with a systems developer.",
"Developers didn't kill ordinary people because a) they seldom noticed them, b) it wasn't considered sporting and c) who'd do all the cooking and growing food and things.",
"Some people think this is paranoia, but it isn't. Paranoids only think everyone is out to get them. Developers know it.",
"Weather forecast for tomorrow: RIVERS OF BLOOD ALL DAY",
"A systems programmer will know what to do when society breaks down, because the systems programmer already lives in a world without law."
]

121
templates/index.html Normal file
View File

@ -0,0 +1,121 @@
<!DOCTYPE html>
<html>
<head>
<title>What Day of March, 2020 Is It?</title>
<style>
main {
font-family: monospace, monospace;
max-width: 38rem;
padding: 2rem 0;
margin: auto;
}
@media only screen and (max-device-width: 736px) {
main {
padding: 0rem;
}
}
::selection {
background: #d3869b;
}
body {
background: #282828;
color: #ebdbb2;
}
pre {
background-color: #3c3836;
padding: 1em;
border: 0;
}
a,
a:active,
a:visited {
color: #b16286;
background-color: #1d2021;
}
h1,
h2,
h3,
h4,
h5 {
margin-bottom: .1rem;
}
blockquote {
border-left: 1px solid #bdae93;
margin: 0.5em 10px;
padding: 0.5em 10px;
}
footer {
align: center;
}
@media (prefers-color-scheme: light) {
body {
background: #fbf1c7;
color: #3c3836;
}
pre {
background-color: #ebdbb2;
padding: 1em;
border: 0;
}
a,
a:active,
a:visited {
color: #b16286;
background-color: #f9f5d7;
}
h1,
h2,
h3,
h4,
h5 {
margin-bottom: .1rem;
}
blockquote {
border-left: 1px solid #655c54;
margin: 0.5em 10px;
padding: 0.5em 10px;
}
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body id="top">
<center>
<main>
<big>Today is March <big>{{.Day}}</big>, 2020</big>
<br />
<br />
<br />
<br />
<p>{{.Quip}}</p>
<br />
<br />
<footer>
<p>From <a href="https://christine.website">Within</a> - <a
href="https://twitter.com/theprincessxena">@theprincessxena</a> - <a
href="https://tulpa.dev/cadey/todayinmarch2020">Source Code</a></p>
</footer>
</main>
</center>
</body>
</html>