Example #1
0
// Wait for input and send output to client.
func takeInput(conn net.Conn) (err error) {
	for {
		query, err := bufioutil.NewReader(conn).ReadLine()
		if err != nil {
			if err.Error() == "EOF" {
				break
			}
			return errutil.Err(err)
		}

		// Do something with the query
		switch query {
		case settings.QueryUpdates:
			// Encode (send) the value.
			err = gob.NewEncoder(conn).Encode(settings.Updates)
		case settings.QueryClearAll:
			settings.Updates = make(map[string]bool)
			err = settings.SaveUpdates()
		case settings.QueryForceRecheck:
			pages, err := ini.ReadPages(settings.PagesPath)
			if err != nil {
				return errutil.Err(err)
			}
			err = page.ForceUpdate(pages)
		}
		if err != nil {
			return errutil.Err(err)
		}
	}
	return nil
}
Example #2
0
func main() {
	// Get input from stdin.
	br := bufioutil.NewReader(os.Stdin)
	rna, err := br.ReadLine()
	if err != nil {
		log.Fatalln(err)
	}

	// Translate the RNA sequence into a protein.
	prot, err := rosa.Prot(rna)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(prot)
}
Example #3
0
func main() {
	// Get input from stdin.
	br := bufioutil.NewReader(os.Stdin)
	a, err := br.ReadLine()
	if err != nil {
		log.Fatalln(err)
	}
	b, err := br.ReadLine()
	if err != nil {
		log.Fatalln(err)
	}

	// Calculate the Hamming distance between the two DNA sequences.
	n, err := HamDist(a, b)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(n)
}
Example #4
0
func main() {
	// Get input from stdin.
	br := bufioutil.NewReader(os.Stdin)
	s, err := br.ReadLine()
	if err != nil {
		log.Fatalln(err)
	}
	t, err := br.ReadLine()
	if err != nil {
		log.Fatalln(err)
	}

	// Print all locations of the substring t in s with indicies starting at 1.
	locs := Subs(s, t)
	for i, loc := range locs {
		fmt.Print(loc + 1)
		if i != len(locs)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}