<commit_before>package main

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"math/big"
	"mime"
	"mime/multipart"
	"net/http"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"time"

	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/crowdmob/goamz/aws"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/tobi/airbrake-go"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/tv42/base58"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/zenazn/goji"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/zenazn/goji/web"
)

var (
	bucketName  string
	baseURL     string
	awsRegion   aws.Region
	username    string
	password    string
	useAirbrake bool
)

func init() {
	bucketName = os.Getenv("BUCKET_NAME")
	baseURL = os.Getenv("BASE_URL")
	username = os.Getenv("HTTP_USER")
	password = os.Getenv("HTTP_PASSWORD")

	if os.Getenv("AWS_REGION") == "" {
		awsRegion = aws.GetRegion("us-east-1")
	} else {
		awsRegion = aws.GetRegion(os.Getenv("AWS_REGION"))
		if awsRegion.Name == "" {
			fmt.Printf("Unknown AWS region: " + os.Getenv("AWS_REGION") + "\n")
			os.Exit(1)
		}
	}

	// Configure Airbrake/Errbit
	apiKey := os.Getenv("AIRBRAKE_API_KEY")
	endpoint := os.Getenv("AIRBRAKE_ENDPOINT")
	environment := os.Getenv("AIRBRAKE_ENVIRONMENT")
	useAirbrake = false
	if apiKey != "" {
		airbrake.ApiKey = apiKey
		useAirbrake = true
		if endpoint != "" {
			airbrake.Endpoint = endpoint
		}
		if environment != "" {
			airbrake.Environment = environment
		}
	}
}

func reportIfAirbake(err error, r *http.Request) {
	if useAirbrake {
		if r != nil {
			airbrake.Error(err, r)
		} else {
			airbrake.Notify(err)
		}
	}
}

func openBucket() (*s3.Bucket, error) {
	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}
	s := s3.New(auth, awsRegion)<commit_msg>Better variable naming<commit_after>package main

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"math/big"
	"mime"
	"mime/multipart"
	"net/http"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"time"

	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/crowdmob/goamz/aws"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/tobi/airbrake-go"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/tv42/base58"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/zenazn/goji"
	"bitbucket.org/matiaskorhonen/gomedia/Godeps/_workspace/src/github.com/zenazn/goji/web"
)

var (
	bucketName  string
	baseURL     string
	awsRegion   aws.Region
	username    string
	password    string
	useAirbrake bool
)

func init() {
	bucketName = os.Getenv("BUCKET_NAME")
	baseURL = os.Getenv("BASE_URL")
	username = os.Getenv("HTTP_USER")
	password = os.Getenv("HTTP_PASSWORD")

	if os.Getenv("AWS_REGION") == "" {
		awsRegion = aws.GetRegion("us-east-1")
	} else {
		awsRegion = aws.GetRegion(os.Getenv("AWS_REGION"))
		if awsRegion.Name == "" {
			fmt.Printf("Unknown AWS region: " + os.Getenv("AWS_REGION") + "\n")
			os.Exit(1)
		}
	}

	// Configure Airbrake/Errbit
	airbrakeApiKey := os.Getenv("AIRBRAKE_API_KEY")
	airbrakeEndpoint := os.Getenv("AIRBRAKE_ENDPOINT")
	airbrakeEnvironment := os.Getenv("AIRBRAKE_ENVIRONMENT")
	useAirbrake = false
	if airbrakeApiKey != "" {
		airbrake.ApiKey = airbrakeApiKey
		useAirbrake = true
		if airbrakeEndpoint != "" {
			airbrake.Endpoint = airbrakeEndpoint
		}
		if airbrakeEnvironment != "" {
			airbrake.Environment = airbrakeEnvironment
		}
	}
}

func reportIfAirbake(err error, r *http.Request) {
	if useAirbrake {
		if r != nil {
			airbrake.Error(err, r)
		} else {
			airbrake.Notify(err)
		}
	}
}

func openBucket() (*s3.Bucket, error) {
	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}
	s := s3.New(auth, awsRegion)
{'fraction_non_alphanumeric': 0.14825945404457802, 'fraction_numerical': 0.004507888805409466, 'mean_word_length': 4.153548387096774, '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': '162859', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1670, 'n_words': 229}