Created
June 28, 2013 06:58
-
-
Save cassava/5882955 to your computer and use it in GitHub Desktop.
Binary selection mechanism similar to Facemash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"os/exec" | |
) | |
func run(imgs chan string, out chan string) { | |
for i := range imgs { | |
cmd := exec.Command("feh", "-.", "-B", "black", i) | |
err := cmd.Run() | |
if err != nil { | |
log.Fatal(err) | |
} | |
out <- i | |
} | |
} | |
func main() { | |
pics := os.Args[1:] | |
c := make(chan string, len(pics)) | |
k := make(chan string) | |
go run(c, k) | |
go run(c, k) | |
c <- pics[0] | |
for i := 1; i < len(pics); i++ { | |
c <- pics[i] | |
<-k | |
} | |
fmt.Println(<-k) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to create a program to help me pick a picture of many, and it was soo easy in Go, I was very surprised. I tried before in C++, Python, and D, and found it very awkward. Considering that this is one of my first programs in Go, I really was surprised that I managed it.