Browse Source

Initial version

master
Ryan Wark 4 years ago
commit
9d2b9d071e
  1. 42
      b56.go
  2. 3
      go.mod
  3. 16
      static/b56.css
  4. 12
      static/b56.js
  5. 66
      static/flip.css
  6. 5
      static/flip.min.css
  7. 7
      static/flip.min.js
  8. 21
      static/index.html

42
b56.go

@ -0,0 +1,42 @@
package main
import (
"bytes"
"io"
"log"
"math/rand"
"net/http"
"time"
)
func main() {
fs := http.FileServer(http.Dir("./static"))
nextId := func(w http.ResponseWriter, _ *http.Request) {
next := base56Id3()
//log.Printf("Generating ID: %s", next)
io.WriteString(w, next+"\n")
}
http.Handle("/", fs)
http.HandleFunc("/next", nextId)
log.Println("Listening on :8080...")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
func base56Id3() string {
//Base56 alphabet with "ambiguous" characters removed: [0oOIl1]
alphabet := "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
//Initialize rand with the time - this is a problem with multiple requests in the same ns
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var b bytes.Buffer
for i := 0; i < 3; i++ {
n := r.Intn(len(alphabet))
char := alphabet[n]
b.WriteByte(char)
}
return b.String()
}

3
go.mod

@ -0,0 +1,3 @@
module krac.in/b56
go 1.16

16
static/b56.css

@ -0,0 +1,16 @@
html,
body {
background-color:#ccc;
}
.wrapper {
width:500px;
height:500px;
margin:0 auto;
background:#ccc;
position:absolute;
left:50%;
top:50%;
margin-left:-250px;
margin-top:-250px;
}

12
static/b56.js

@ -0,0 +1,12 @@
function handleTickInit(tick) {
// each 3 seconds we'll update the billboard
Tick.helper.interval(function () {
fetch('/next')
.then(response => response.text())
.then(data => {
console.log(data)
next = data.trim()
tick.value = next
});
}, 3000);
}

66
static/flip.css

@ -0,0 +1,66 @@
.tick {
font-size: 1rem;
white-space: nowrap;
font-family: monospace;
}
.tick-flip,
.tick-text-inline {
font-size: 2.5em;
}
.tick-label {
margin-top: 1em;
font-size: 1em;
}
.tick-char {
width: 1.5em;
}
.tick-text-inline {
display: inline-block;
text-align: center;
min-width: 1em;
}
.tick-text-inline+.tick-text-inline {
margin-left: -.325em;
}
.tick-group {
margin: 0 .5em;
text-align: center;
}
body {
background-color: #fff !important;
}
.tick-text-inline {
color: #595d63 !important;
}
.tick-label {
color: #595d63 !important;
}
.tick-flip-panel {
color: #fff !important;
}
.tick-flip {
font-family: monospace !important;
}
.tick-flip-panel-text-wrapper {
line-height: 1.45 !important;
}
.tick-flip-panel {
background-color: #3c3e3c !important;
}
.tick-flip {
border-radius: 0.12em !important;
}

5
static/flip.min.css
File diff suppressed because it is too large
View File

7
static/flip.min.js
File diff suppressed because it is too large
View File

21
static/index.html

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>A static page</title>
<link rel="stylesheet" href="flip.min.css">
<link rel="stylesheet" href="flip.css">
<link rel="stylesheet" href="b56.css">
<script src="b56.js"></script>
</head>
<body>
<div class="wrapper">
<div class="tick" data-did-init="handleTickInit" data-value="---">
<div data-repeat="true" data-layout="horizontal fit">
<span data-view="flip" class="tick-char"></span>
</div>
</div>
</div>
<script src="flip.min.js"></script>
</body>
</html>
Loading…
Cancel
Save