Skip to content

Instantly share code, notes, and snippets.

@cassava
Created June 28, 2013 06:58
Show Gist options
  • Save cassava/5882955 to your computer and use it in GitHub Desktop.
Save cassava/5882955 to your computer and use it in GitHub Desktop.
Binary selection mechanism similar to Facemash.
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)
}
@cassava
Copy link
Author

cassava commented Jun 28, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment