<commit_before>package web

import (
	"fmt"
	"github.com/unrolled/render"
	"html/template"
	"net/http"
	"strings"
	"time"
)

var SUFFIXES = []string{"b", "K", "M", "G", "P"}

func NewRenderer(version string, debug bool, ctx *Context) *render.Render {

	return render.New(render.Options{
		Extensions:    []string{".html"},
		IsDevelopment: debug,
		Asset: func(name string) ([]byte, error) {
			return Asset(name)
		},
		AssetNames: func() []string {
			return AssetNames()
		},
		IndentJSON: true,
		Funcs: []template.FuncMap{
			template.FuncMap{
				"HumanizeBytes": func(max int, number uint64) string {
					i := 0
					for {
						if number < 1024 {
							break
						}
						number = number / 1024
						i++
						if i >= max || i >= len(SUFFIXES) {
							break
						}
					}
					return fmt.Sprintf("%d%s", number, SUFFIXES[i])
				},
				"LimitString": func(limit int, s string) string {
					slen := len(s)
					if slen <= limit {
						return s
					}<commit_msg>Fix HumanizeBytes template helper<commit_after>package web

import (
	"fmt"
	"github.com/unrolled/render"
	"html/template"
	"net/http"
	"strings"
	"time"
)

var SUFFIXES = []string{"b", "K", "M", "G", "T"}

func NewRenderer(version string, debug bool, ctx *Context) *render.Render {

	return render.New(render.Options{
		Extensions:    []string{".html"},
		IsDevelopment: debug,
		Asset: func(name string) ([]byte, error) {
			return Asset(name)
		},
		AssetNames: func() []string {
			return AssetNames()
		},
		IndentJSON: true,
		Funcs: []template.FuncMap{
			template.FuncMap{
				"HumanizeBytes": func(max int, number uint64) string {
					i := 0
					for {
						if number < 10240 {
							break
						}
						number = number / 1024
						i++
						if i >= max || i >= len(SUFFIXES) {
							break
						}
					}
					return fmt.Sprintf("%d%s", number, SUFFIXES[i])
				},
				"LimitString": func(limit int, s string) string {
					slen := len(s)
					if slen <= limit {
						return s
					}
{'fraction_non_alphanumeric': 0.1539240506329114, 'fraction_numerical': 0.011645569620253165, 'mean_word_length': 2.6457564575645756, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4862383', 'n_tokens_mistral': 923, 'n_tokens_neox': 691, 'n_words': 177}