<commit_before>package main

import (
	"crypto/rand"
	"fmt"
	flags "github.com/jessevdk/go-flags"
	"github.com/monochromegane/hoi/option"
	"github.com/monochromegane/hoi/server"
	"os"
	"os/user"
	"path/filepath"
)

var opts option.Options

func main() {

	args, err := flags.Parse(&opts)
	if err != nil {
		os.Exit(1)
	}

	// create hoi public directory
	usr, _ := user.Current()
	homeDir := usr.HomeDir
	publicDir := filepath.Join(homeDir, ".hoi", "public")
	os.MkdirAll(publicDir, 0755)

	if opts.Server {
		// start hoi server
		server.Start(publicDir)
	} else {
		// create random directory
		random := randomString(32)
		randomDir := filepath.Join(publicDir, random)
		os.Mkdir(randomDir, 0755)

		// create symblic link
		file := args[0]
		os.Symlink(file, filepath.Join(randomDir, filepath.Base(file)))

		fmt.Println(filepath.Join(random, filepath.Base(file)))
	}

}

func randomString(length int) string {
	alphanum := "0123456789abcdefghijklmnopqrstuvwxyz"
	var bytes = make([]byte, length)
	rand.Read(bytes)
	for i, b := range bytes {
		bytes[i] = alphanum[b%byte(len(alphanum))]
	}
	return string(bytes)
}
<commit_msg>Run hoi server as a daemon.<commit_after>package main

import (
	"crypto/rand"
	"fmt"
	flags "github.com/jessevdk/go-flags"
	"github.com/monochromegane/hoi/option"
	"github.com/monochromegane/hoi/server"
	"os"
	"os/exec"
	"os/user"
	"path/filepath"
)

var opts option.Options

func main() {

	args, err := flags.Parse(&opts)
	if err != nil {
		os.Exit(1)
	}

	// create hoi public directory
	usr, _ := user.Current()
	homeDir := usr.HomeDir
	publicDir := filepath.Join(homeDir, ".hoi", "public")
	os.MkdirAll(publicDir, 0755)

	if opts.Server {
		// start hoi server
		server.Start(publicDir)
	} else {
		// create random directory
		random := randomString(32)
		randomDir := filepath.Join(publicDir, random)
		os.Mkdir(randomDir, 0755)

		// create symblic link
		file := args[0]
		os.Symlink(file, filepath.Join(randomDir, filepath.Base(file)))

		fmt.Println(filepath.Join(random, filepath.Base(file)))

		// run hoi server as a daemon
		cmd := exec.Command(os.Args[0], "--server")
		cmd.Start()
	}

}

func randomString(length int) string {
	alphanum := "0123456789abcdefghijklmnopqrstuvwxyz"
	var bytes = make([]byte, length)
	rand.Read(bytes)
	for i, b := range bytes {
		bytes[i] = alphanum[b%byte(len(alphanum))]
	}
	return string(bytes)
}

{'fraction_non_alphanumeric': 0.15138772077375945, 'fraction_numerical': 0.01892346509671993, 'mean_word_length': 4.061702127659575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '148231', 'n_tokens_mistral': 1005, 'n_tokens_neox': 930, 'n_words': 186}