<commit_before>package main

import (
	"fmt"
	"html/template"
	"net/http"
	"os"
	"time"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		now := time.Now()
		err := indexTmpl.Execute(w, map[string]interface{}{
			"Title": "900 words",

			"Now":  now,
			"Days": daysOfMonth(now),
		})
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		}
	})
	http.ListenAndServe("localhost:12345", nil)
}

var indexTmpl = template.Must(template.New("index").Parse(`<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>{{ .Title }}</title>

		<style>
		#content {
			display: flex;
			flex-direction: column;
			align-items: center;
		}

		#days {
			list-style-type: none;
			margin-bottom: 2em;
			padding: 0;
			display: flex;
			width: 80vw;
			justify-content: space-around;
		}

		#days li {
			width: 1.5em;
			height: 1.5em;
			text-align: center;
			border: 1px solid;
			border-radius: 100%;
		}

		#days .written {
			background-color: rgba(0, 255, 0, 0.2);
			background-color: green;
		}

		#days .past {
			border-color: lightgreen;
		}

		#days .future {
			color: #999;
			border-color: #ddd;
		}

		#editor textarea {
			width: 40em;
			height: 80vh;
			font-size: 15pt;
			font-family: serif;
			border: none;
			resize: none;
		}

		footer {
			color: #999;
		}

		footer a, footer a:visited {
			color: #999;
		}
		</style>
	</head>

	<body>
		<div id="content">
			<h1>{{ .Title }}</h1>

			<ul id="days">
			{{ $now := .Now }}
			{{ range $day := .Days -}}
			<li{{ if ($day.After $now) }} class="future"{{ else }} class="past"{{ end }}>{{ $day.Day }}</li> 
			{{ end }}
			</ul>

			<section id="editor">
				<textarea id="editor"></textarea>
			</section>

			<footer>
				Made with &lt;3 by strange adventures.  <a href="/about">/about</a>
			</footer>
		</div>
	</body>
</html>
`))

func daysOfMonth(t time.Time) []time.Time {
	s := time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
	e := s.AddDate(0, 1, 0)
	ts := make([]time.Time, 0, 31)<commit_msg>Add a basic word count feature<commit_after>package main

import (
	"fmt"
	"html/template"
	"net/http"
	"os"
	"time"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		now := time.Now()
		err := indexTmpl.Execute(w, map[string]interface{}{
			"Title": "900 words",

			"Now":  now,
			"Days": daysOfMonth(now),
		})
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		}
	})
	http.ListenAndServe("localhost:12345", nil)
}

var indexTmpl = template.Must(template.New("index").Parse(`<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>{{ .Title }}</title>

		<style>
		#content {
			display: flex;
			flex-direction: column;
			align-items: center;
		}

		#days {
			list-style-type: none;
			margin-bottom: 2em;
			padding: 0;
			display: flex;
			width: 80vw;
			justify-content: space-around;
		}

		#days li {
			width: 1.5em;
			height: 1.5em;
			text-align: center;
			border: 1px solid;
			border-radius: 100%;
		}

		#days .written {
			background-color: rgba(0, 255, 0, 0.2);
			background-color: green;
		}

		#days .past {
			border-color: lightgreen;
		}

		#days .future {
			color: #999;
			border-color: #ddd;
		}

		#editor textarea {
			width: 40em;
			height: 80vh;
			font-size: 15pt;
			font-family: serif;
			border: none;
			resize: none;
		}

		footer {
			color: #999;
		}

		footer a, footer a:visited {
			color: #999;
		}
		</style>
	</head>

	<body>
		<div id="content">
			<h1>{{ .Title }}</h1>

			<ul id="days">
			{{ $now := .Now }}
			{{ range $day := .Days -}}
			<li{{ if ($day.After $now) }} class="future"{{ else }} class="past"{{ end }}>{{ $day.Day }}</li> 
			{{ end }}
			</ul>

			<section id="editor">
				<textarea id="editor"></textarea>
				<div id="stats">
					<span id="word-count">0 words</span>
				</div>
			</section>

			<footer>
				Made with &lt;3 by strange adventures.  <a href="/about">/about</a>
			</footer>
		</div>

		<script>
			var editorEl = document.querySelector("#editor textarea");
			var wordCountEl = document.querySelector("#word-count");

			var prevCount = 0;
			function updateCount() {
				var words = editorEl.value.split(/\s+/);
				var count = words.filter(function(w) { return w.trim() != "" }).length;
				if (count != prevCount) {
					var suffix = " words";
					if (count == 1) {
						suffix = " word";
					}
					wordCountEl.textContent = count + suffix;
					prevCount = count;
				}
			}

			editorEl.addEventListener("input", function(ev) {
				updateCount();
			});

			document.addEventListener("DOMContentLoaded", updateCount);
		</script>
	</body>
</html>
`))

func daysOfMonth(t time.Time) []time.Time {
	s := time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
	e := s.AddDate(0, 1, 0)
	ts := make([]time.Time, 0, 31)
{'fraction_non_alphanumeric': 0.19701678060907396, 'fraction_numerical': 0.024238657551274082, 'mean_word_length': 2.828707375099128, 'pattern_counts': {'":': 6, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1471115', 'n_tokens_mistral': 2322, 'n_tokens_neox': 1856, 'n_words': 432}