<commit_before>// Copyright 2015 <NAME>
// Copyright 2015 <NAME>

package store

import (
	"crypto/rand"
	"encoding/json"
	"github.com/jinzhu/gorm"
	"io"
	"math/big"
)

func Schema(db *gorm.DB) {
	// TODO: error detection
	(Captcha{}).schema(db)
	(Medium{}).schema(db)
	(Group{}).schema(db)
	(GroupAddress{}).schema(db) // must come after Group and Medium
	(Message{}).schema(db)      // must come after Group
	(User{}).schema(db)
	(Session{}).schema(db) // must come after User
	(ShortUrl{}).schema(db)
	(UserAddress{}).schema(db)  // must come after User and Medium
	(Subscription{}).schema(db) // must come after Group and UserAddress
}

func SchemaDrop(db *gorm.DB) {
	// This must be in the reverse order of Schema()
	// TODO: error detection
	db.DropTable(&Subscription{})
	db.DropTable(&UserAddress{})
	db.DropTable(&ShortUrl{})
	db.DropTable(&Session{})
	db.DropTable(&User{})
	db.DropTable(&Message{})
	db.DropTable(&GroupAddress{})
	db.DropTable(&Group{})
	db.DropTable(&Medium{})
	db.DropTable(&Captcha{})
}

// Simple dump to JSON, good for most entities
func defaultEncoders(o interface{}) map[string]func(io.Writer) error {
	return map[string]func(io.Writer) error{
		"application/json": func(w io.Writer) error {
			bytes, err := json.Marshal(o)
			if err != nil {
				return err
			}
			_, err = w.Write(bytes)
			return err
		},
	}
}

const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

var alphabetLen = big.NewInt(int64(len(alphabet)))

func randomString(size int) string {
	var randStr []byte
	for i := 0; i < size; i++ {
		bigint, err := rand.Int(rand.Reader, alphabetLen-1)
		if err != nil {
			panic(err)
		}
		randStr[i] = alphabet[bigint.Int64()]
	}
	return string(randStr[:])
}<commit_msg>fix randomString helper<commit_after>// Copyright 2015 <NAME>
// Copyright 2015 <NAME>

package store

import (
	"crypto/rand"
	"encoding/json"
	"github.com/jinzhu/gorm"
	"io"
	"math/big"
)

func Schema(db *gorm.DB) {
	// TODO: error detection
	(Captcha{}).schema(db)
	(Medium{}).schema(db)
	(Group{}).schema(db)
	(GroupAddress{}).schema(db) // must come after Group and Medium
	(Message{}).schema(db)      // must come after Group
	(User{}).schema(db)
	(Session{}).schema(db) // must come after User
	(ShortUrl{}).schema(db)
	(UserAddress{}).schema(db)  // must come after User and Medium
	(Subscription{}).schema(db) // must come after Group and UserAddress
}

func SchemaDrop(db *gorm.DB) {
	// This must be in the reverse order of Schema()
	// TODO: error detection
	db.DropTable(&Subscription{})
	db.DropTable(&UserAddress{})
	db.DropTable(&ShortUrl{})
	db.DropTable(&Session{})
	db.DropTable(&User{})
	db.DropTable(&Message{})
	db.DropTable(&GroupAddress{})
	db.DropTable(&Group{})
	db.DropTable(&Medium{})
	db.DropTable(&Captcha{})
}

// Simple dump to JSON, good for most entities
func defaultEncoders(o interface{}) map[string]func(io.Writer) error {
	return map[string]func(io.Writer) error{
		"application/json": func(w io.Writer) error {
			bytes, err := json.Marshal(o)
			if err != nil {
				return err
			}
			_, err = w.Write(bytes)
			return err
		},
	}
}

const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

var alphabet_len = big.NewInt(int64(len(alphabet)))

func randomString(size int) string {
	bytes := make([]byte, size)
	for i := 0; i < size; i++ {
		bigint, err := rand.Int(rand.Reader, alphabet_len)
		if err != nil {
			panic(err)
		}
		bytes[i] = alphabet[bigint.Int64()]
	}
	return string(bytes[:])
}
{'fraction_non_alphanumeric': 0.16709438266324494, 'fraction_numerical': 0.013401767892785858, 'mean_word_length': 4.339421613394216, 'pattern_counts': {'":': 2, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690773', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1265, 'n_words': 292}