<commit_before>// example of HTTP server that uses the captcha package.
package main

import (
	"github.com/dchest/captcha"
	"http"
	"io"
	"log"
	"template"
)

var formTemplate = template.MustParse(formTemplateSrc, nil)

func showFormHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}
	d := struct {
		CaptchaId  string
		JavaScript string
	}{
		captcha.New(captcha.StdLength),
		formJavaScript,
	}
	if err := formTemplate.Execute(w, &d); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
	}
}

func processFormHandler(w http.ResponseWriter, r *http.Request) {
	if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) {
		io.WriteString(w, "Wrong captcha solution! No robots allowed!\n")
	} else {
		io.WriteString(w, "Great job, human! You solved the captcha.\n")
	}
	io.WriteString(w, "<br><a href='/'>Try another one</a>")
}

func main() {
	http.HandleFunc("/", showFormHandler)
	http.HandleFunc("/process", processFormHandler)
	http.Handle("/captcha/", captcha.Server(captcha.StdWidth, captcha.StdHeight))
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(err)
	}
}

const formJavaScript = `
function playAudio() {
	var e = document.getElementById('audio')
	e.style.display = 'block';
	e.play();
	return false;
}

function reload() {
	function setSrcQuery(e, q) {
		var src  = e.src;
		var p = src.indexOf('?');
		if (p >= 0) {
			src = src.substr(0, p);
		}
		e.src = src + "?" + q
	}
	setSrcQuery(document.getElementById('image'), "reload=" + (new Date()).getTime());
	setSrcQuery(document.getElementById('audio'), (new Date()).getTime());
	return false;
}<commit_msg>example: print the address of server.<commit_after>// example of HTTP server that uses the captcha package.
package main

import (
	"fmt"
	"github.com/dchest/captcha"
	"http"
	"io"
	"log"
	"template"
)

var formTemplate = template.MustParse(formTemplateSrc, nil)

func showFormHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}
	d := struct {
		CaptchaId  string
		JavaScript string
	}{
		captcha.New(captcha.StdLength),
		formJavaScript,
	}
	if err := formTemplate.Execute(w, &d); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
	}
}

func processFormHandler(w http.ResponseWriter, r *http.Request) {
	if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) {
		io.WriteString(w, "Wrong captcha solution! No robots allowed!\n")
	} else {
		io.WriteString(w, "Great job, human! You solved the captcha.\n")
	}
	io.WriteString(w, "<br><a href='/'>Try another one</a>")
}

func main() {
	http.HandleFunc("/", showFormHandler)
	http.HandleFunc("/process", processFormHandler)
	http.Handle("/captcha/", captcha.Server(captcha.StdWidth, captcha.StdHeight))
	fmt.Println("Server is at localhost:8666")
	if err := http.ListenAndServe(":8666", nil); err != nil {
		log.Fatal(err)
	}
}

const formJavaScript = `
function playAudio() {
	var e = document.getElementById('audio')
	e.style.display = 'block';
	e.play();
	return false;
}

function reload() {
	function setSrcQuery(e, q) {
		var src  = e.src;
		var p = src.indexOf('?');
		if (p >= 0) {
			src = src.substr(0, p);
		}
		e.src = src + "?" + q
	}
	setSrcQuery(document.getElementById('image'), "reload=" + (new Date()).getTime());
	setSrcQuery(document.getElementById('audio'), (new Date()).getTime());
	return false;
}
{'fraction_non_alphanumeric': 0.16996841803043353, 'fraction_numerical': 0.004593741027849555, 'mean_word_length': 4.452269170579029, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, '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': '2705699', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1242, 'n_words': 280}