<commit_before>package main

import (
	"bytes"
	"fmt"
	"os"
	"regexp"
	"sort"

	"github.com/docker/docker/pkg/archive"
	"github.com/fsouza/go-dockerclient"
	"github.com/rafecolton/go-dockerclient-sort"
	"github.com/sylphon/artifactory"
)

const (
	imageName    = "quay.io/rafecolton/docker-builder:latest"
	resourcePath = "/app/bin/docker-builder"
)

func main() {
	client, err := artifactory.Dockerclient()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	containerID, err := latestImageByName(client, imageName)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	opts := artifactory.NewResourceOptions{
		StorageDir: os.Getenv("PWD"),
		Handle:     artifactory.NewHandle(containerID),
		Path:       resourcePath,
	}

	var resource = artifactory.NewResource(opts)

	artifactBytes, err := resource.ArtifactBytes()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	byteReader := bytes.NewReader(artifactBytes)
	archive.Untar(byteReader, os.Getenv("PWD"), &archive.TarOptions{})
	_ = resource.Reset()
}

func latestImageByName(client *docker.Client, name string) (string, error) {
	images, err := client.ListImages(false)
	if err != nil {
		return "", err
	}
	sort.Sort(dockersort.ByCreatedDescending(images))
	for _, image := range images {
		for _, tag := range image.RepoTags {
			matched, err := regexp.MatchString("^"+name+"$", tag)
			if err != nil {
				return "", nil
			}
			if matched {
				return image.ID, nil
			}
		}
	}

	return "", fmt.Errorf("unable to find image named %s", name)
}
<commit_msg>Adding a comment to the individual_resource example [ci skip]<commit_after>package main

import (
	"bytes"
	"fmt"
	"os"
	"regexp"
	"sort"

	"github.com/docker/docker/pkg/archive"
	"github.com/fsouza/go-dockerclient"
	"github.com/rafecolton/go-dockerclient-sort"
	"github.com/sylphon/artifactory"
)

const (
	imageName    = "quay.io/rafecolton/docker-builder:latest"
	resourcePath = "/app/bin/docker-builder"
)

// The example details how to extract the docker-builder binary from the lastest
// docker-builder image
func main() {
	client, err := artifactory.Dockerclient()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	containerID, err := latestImageByName(client, imageName)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	opts := artifactory.NewResourceOptions{
		StorageDir: os.Getenv("PWD"),
		Handle:     artifactory.NewHandle(containerID),
		Path:       resourcePath,
	}

	var resource = artifactory.NewResource(opts)

	artifactBytes, err := resource.ArtifactBytes()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	byteReader := bytes.NewReader(artifactBytes)
	archive.Untar(byteReader, os.Getenv("PWD"), &archive.TarOptions{})
	_ = resource.Reset()
}

func latestImageByName(client *docker.Client, name string) (string, error) {
	images, err := client.ListImages(false)
	if err != nil {
		return "", err
	}
	sort.Sort(dockersort.ByCreatedDescending(images))
	for _, image := range images {
		for _, tag := range image.RepoTags {
			matched, err := regexp.MatchString("^"+name+"$", tag)
			if err != nil {
				return "", nil
			}
			if matched {
				return image.ID, nil
			}
		}
	}

	return "", fmt.Errorf("unable to find image named %s", name)
}

{'fraction_non_alphanumeric': 0.1473816243336469, 'fraction_numerical': 0.0018814675446848542, 'mean_word_length': 3.945736434108527, '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': '5085139', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1160, 'n_words': 236}