<commit_before># Copyright 2011 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

package main

import (
	"log"
	"fmt"
	"time"
	"http"
	"exp/draw"
	"exp/draw/x11"
	"image"
	"image/png"
	"image/jpeg"
)

func imagePuller(urls chan string, imgs chan *image.Image) {
	for url := range urls {
		r, _, err := http.Get(url)
		if err == nil {
			log.Print("Fetched ", url)
			ctype, found := r.Header["Content-Type"]
			if found {
				switch {
				default:
					log.Print("For ", url, ", unknown type: ", ctype)
				case ctype == "image/png":
					img, err := png.Decode(r.Body)
					if err == nil {
						imgs <- &img
					} else {
						log.Print("For ", url, ", decode error: ", err)
					}
				case ctype == "image/jpeg" || ctype == "image/jpg":
					img, err := jpeg.Decode(r.Body)
					if err == nil {
						imgs <- &img
					} else {
						log.Print("For ", url, ", decode error: ", err)
						return
					}
				}
			} else {
				log.Print("For ", url, ", no content type.")
			}
			r.Body.Close()
		} else {
			log.Print("Error fetching ", url, ": ", err)
		}
	}
}

func urlGen(urls chan string) {
	x := 33981
	y := 23179
	for {
		url := fmt.Sprintf("http://khm1.google.com/kh/v=74&x=%d&s=&y=%d&z=16&s=Ga", x, y)
		urls <- url
		x++
	}
}

func processEvent(ch <-chan interface {}) {
	for {
		if closed(ch) {
			log.Exit("X display closed.")
		}
		ev, ok := <-ch
		if ! ok {
			// no events, return
			return
		}

		switch ev.(type) {
		case draw.ErrEvent:
			log.Exit("X11 err: ", ev.(draw.ErrEvent).Err)
		}
	}
}

func main () {
	urls := make(chan string, 4)
	imgReady := make(chan *image.Image, 4)

	go imagePuller(urls, imgReady)
	go urlGen(urls)

	xdisp, err := x11.NewWindow()
	if err != nil {
		log.Exit("X11 error: ", err)
	}
	screen := xdisp.Screen()

//2010/11/29 16:23:17 one tile is sized (0,0)-(256,256)
//2010/11/29 16:23:17 the screen is sized (0,0)-(800,600)

//	log.Print("one tile is sized ", img.Bounds())
//	log.Print("the screen is sized ", screen.Bounds())

	tileHeight := 256
	tileWidth := 256<commit_msg>Fixed for the current version of Go.<commit_after>// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"log"
	"fmt"
	"time"
	"http"
	"exp/draw"
	"exp/draw/x11"
	"image"
	"image/png"
	"image/jpeg"
)

func imagePuller(urls chan string, imgs chan *image.Image) {
	for url := range urls {
		r, _, err := http.Get(url)
		if err == nil {
			log.Print("Fetched ", url)
			ctype, found := r.Header["Content-Type"]
			if found {
				switch {
				default:
					log.Print("For ", url, ", unknown type: ", ctype)
				case ctype == "image/png":
					img, err := png.Decode(r.Body)
					if err == nil {
						imgs <- &img
					} else {
						log.Print("For ", url, ", decode error: ", err)
					}
				case ctype == "image/jpeg" || ctype == "image/jpg":
					img, err := jpeg.Decode(r.Body)
					if err == nil {
						imgs <- &img
					} else {
						log.Print("For ", url, ", decode error: ", err)
						return
					}
				}
			} else {
				log.Print("For ", url, ", no content type.")
			}
			r.Body.Close()
		} else {
			log.Print("Error fetching ", url, ": ", err)
		}
	}
}

func urlGen(urls chan string) {
	x := 33981
	y := 23179
	for {
		url := fmt.Sprintf("http://khm1.google.com/kh/v=74&x=%d&s=&y=%d&z=16&s=Ga", x, y)
		urls <- url
		x++
	}
}

func processEvent(ch <-chan interface {}) {
	for {
		if closed(ch) {
			log.Fatal("X display closed.")
		}
		var ev interface {}
		select {
			case ev = <-ch:
				// ok, continue
			default:
				// no events
				return
		}

		switch ev.(type) {
		case draw.ErrEvent:
			log.Fatal("X11 err: ", ev.(draw.ErrEvent).Err)
		}
	}
}

func main () {
	urls := make(chan string, 4)
	imgReady := make(chan *image.Image, 4)

	go imagePuller(urls, imgReady)
	go urlGen(urls)

	xdisp, err := x11.NewWindow()
	if err != nil {
		log.Fatal("X11 error: ", err)
	}
	screen := xdisp.Screen()

//2010/11/29 16:23:17 one tile is sized (0,0)-(256,256)
//2010/11/29 16:23:17 the screen is sized (0,0)-(800,600)

//	log.Print("one tile is sized ", img.Bounds())
//	log.Print("the screen is sized ", screen.Bounds())

	tileHeight := 256
	tileWidth := 256
{'fraction_non_alphanumeric': 0.17833951762523192, 'fraction_numerical': 0.036641929499072357, 'mean_word_length': 2.579253112033195, 'pattern_counts': {'":': 6, '<': 13, '<?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': '5540057', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1650, 'n_words': 441}