@ -0,0 +1,95 @@ | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
3 | |||||
3 | |||||
3 | |||||
3 | |||||
4 | |||||
3 | |||||
4 | |||||
5 | |||||
5 | |||||
sssssssssssssssssssssssss | |||||
sssssssssssssssssssssssss | |||||
ttttttttttttttttttt | |||||
ttttttttttttttttttt | |||||
4r | |||||
ew | |||||
rw | |||||
f | |||||
ds | |||||
f | |||||
dsf | |||||
d | |||||
f | |||||
asf | |||||
sad | |||||
fd | |||||
sf | |||||
d | |||||
sfa | |||||
ads | |||||
f | |||||
saf | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
dsa | |||||
fd | |||||
sf | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
dsf | |||||
dsa | |||||
f | |||||
d | |||||
af | |||||
ds | |||||
af | |||||
ds | |||||
af | |||||
dsf | |||||
s | |||||
f | |||||
sdaf | |||||
sd | |||||
afa | |||||
sf | |||||
af | |||||
d | |||||
f | |||||
sf | |||||
sa | |||||
fas | |||||
f | |||||
ds | |||||
fs | |||||
af | |||||
as | |||||
f | |||||
sdf | |||||
sa | |||||
fs | |||||
df | |||||
sf | |||||
s | |||||
fs | |||||
adfas | |||||
f | |||||
dsa | |||||
fd | |||||
saf | |||||
sa | |||||
fas |
@ -0,0 +1,91 @@ | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
1 | |||||
3 | |||||
3 | |||||
3 | |||||
3 | |||||
4 | |||||
3 | |||||
4 | |||||
5 | |||||
5 | |||||
4r | |||||
ew | |||||
rw | |||||
f | |||||
ds | |||||
f | |||||
dsf | |||||
d | |||||
f | |||||
asf | |||||
sad | |||||
fd | |||||
sf | |||||
d | |||||
sfa | |||||
ads | |||||
f | |||||
saf | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
dsa | |||||
fd | |||||
sf | |||||
ds | |||||
f | |||||
dsa | |||||
f | |||||
dsf | |||||
dsa | |||||
f | |||||
d | |||||
af | |||||
ds | |||||
af | |||||
ds | |||||
af | |||||
dsf | |||||
s | |||||
f | |||||
sdaf | |||||
sd | |||||
afa | |||||
sf | |||||
af | |||||
d | |||||
f | |||||
sf | |||||
sa | |||||
fas | |||||
f | |||||
ds | |||||
fs | |||||
af | |||||
as | |||||
f | |||||
sdf | |||||
sa | |||||
fs | |||||
df | |||||
sf | |||||
s | |||||
fs | |||||
adfas | |||||
f | |||||
dsa | |||||
fd | |||||
saf | |||||
sa | |||||
fas |
@ -0,0 +1,11 @@ | |||||
package main | |||||
import "fmt" | |||||
const boilingF = 212.0 | |||||
func main(){ | |||||
var F = boilingF | |||||
var c = (F - 32) * 5 /9 | |||||
fmt.Printf("boiling point = %g F or %g C\n", F, c) | |||||
} |
@ -0,0 +1,29 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"io/ioutil" | |||||
"os" | |||||
"strings" | |||||
) | |||||
func main() { | |||||
counts := make(map[string]int) | |||||
for _, filename := range os.Args[1:] { | |||||
data, err := ioutil.ReadFile(filename) | |||||
if err != nil { | |||||
fmt.Fprintf(os.Stderr, "dup3: %v\n", err) | |||||
continue | |||||
} | |||||
for _, line := range strings.Split(string(data), "\n") { | |||||
fmt.Printf("YYY1111: %v \n", line) | |||||
counts[line]++ | |||||
} | |||||
} | |||||
for line, n := range counts { | |||||
if n > 1 { | |||||
fmt.Printf("YYY: %v \t %d \n", line, n) | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,23 @@ | |||||
package main | |||||
import( | |||||
"fmt" | |||||
"io/ioutil" | |||||
"net/http" | |||||
"os" | |||||
) | |||||
func main(){ | |||||
for _, url := range os.Args[1:]{ | |||||
resp, err := http.Get(url) | |||||
if err != nil{ | |||||
fmt.Fprintf(os.Stderr, "fetch:%v\n", err) | |||||
os.Exit(1) | |||||
} | |||||
b, err := ioutil.ReadAll(resp.Body) | |||||
resp.Body.Close() | |||||
if err != nil{ | |||||
fmt.Fprintf(os.Stderr, "fetch: reading %s: %v\n", url, err) | |||||
os.Exit(1) | |||||
} | |||||
fmt.Printf("IMY****\n %s\n", b) | |||||
} | |||||
} |
@ -0,0 +1,41 @@ | |||||
package main | |||||
import( | |||||
"fmt" | |||||
"io" | |||||
"io/ioutil" | |||||
"net/http" | |||||
"os" | |||||
"time" | |||||
) | |||||
func main() { | |||||
start := time.Now() | |||||
ch := make(chan string) | |||||
for _, url := range os.Args[1:]{ | |||||
go fetch(url, ch) // 启动一个goroutine | |||||
} | |||||
for range os.Args[1:]{ | |||||
fmt.Println(<- ch) | |||||
} | |||||
fmt.Printf("IMY*****main* %2fs elapsed\n", time.Since(start).Seconds()) | |||||
} | |||||
func fetch(url string, ch chan <- string){ | |||||
start := time.Now() | |||||
resp, err := http.Get(url) | |||||
if err != nil{ | |||||
ch <- fmt.Sprint(err) // 发送到通道ch | |||||
return | |||||
} | |||||
nbytes, err := io.Copy(ioutil.Discard, resp.Body) | |||||
resp.Body.Close() //不要泄露资源 | |||||
if err != nil{ | |||||
ch <- fmt.Sprintf("while reading %s %v", url, err) | |||||
return | |||||
} | |||||
secs := time.Since(start).Seconds() | |||||
ch <- fmt.Sprintf("IMY***fetch* %.2fs, %7d %s ", secs, nbytes, url) | |||||
} |
@ -0,0 +1,63 @@ | |||||
package main | |||||
import ( | |||||
"image" | |||||
"image/color" | |||||
"image/gif" | |||||
"io" | |||||
"log" | |||||
"math" | |||||
"math/rand" | |||||
"net/http" | |||||
"os" | |||||
"time" | |||||
) | |||||
var palette = []color.Color{color.White, color.Black} | |||||
const ( | |||||
whiteIndex = 0 | |||||
blackIndex = 1 | |||||
) | |||||
func main() { | |||||
rand.Seed(time.Now().UTC().UnixNano()) | |||||
if len(os.Args) > 1 && os.Args[1] == "web" { | |||||
handler := func(w http.ResponseWriter, r *http.Request) { | |||||
liss(w) | |||||
} | |||||
http.HandleFunc("/", handler) | |||||
log.Fatal(http.ListenAndServe("localhost:8000", nil)) | |||||
return | |||||
} | |||||
liss(os.Stdout) | |||||
} | |||||
func liss(out io.Writer) { | |||||
const ( | |||||
cycles = 5 | |||||
res = 0.0001 | |||||
size = 100 | |||||
nframes = 64 | |||||
delay = 8 | |||||
) | |||||
freq := rand.Float64() * 3.0 | |||||
anim := gif.GIF{LoopCount: nframes} | |||||
phase := 0.0 | |||||
for i := 0; i < nframes; i++ { | |||||
rect := image.Rect(0, 0, 2*size+1, 2*size+1) | |||||
img := image.NewPaletted(rect, palette) | |||||
for t := 0.0; t < cycles*2*math.Pi; t += res { | |||||
x := math.Sin(t) | |||||
y := math.Sin(t*freq + phase) | |||||
img.SetColorIndex(size+int(x*size+0.5), size+int(y*size+0.5), blackIndex) | |||||
} | |||||
phase += 0.1 | |||||
anim.Delay = append(anim.Delay, delay) | |||||
anim.Image = append(anim.Image, img) | |||||
} | |||||
gif.EncodeAll(out, &anim) | |||||
} |