This file contains 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "precise64" | |
config.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
config.vm.network :forwarded_port, guest: 80, host: 8080 |
This file contains 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 utils | |
import ( | |
"bufio" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func IsExists(path string) bool { |
This file contains 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
/* | |
Exercise: Web Crawler | |
In this exercise you'll use Go's concurrency features to parallelize a web crawler. | |
Modify the Crawl function to fetch URLs in parallel without fetching the same URL twice. | |
*/ | |
package main |
This file contains 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
/* | |
Exercise: Equivalent Binary Trees | |
1. Implement the Walk function. | |
2. Test the Walk function. | |
The function tree.New(k) constructs a randomly-structured binary tree holding the values k, 2k, 3k, ..., 10k. | |
Create a new channel ch and kick off the walker: |
This file contains 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
/* | |
Exercise: Rot13 Reader | |
A common pattern is an io.Reader that wraps another io.Reader, modifying the stream in some way. | |
For example, the gzip.NewReader function takes an io.Reader (a stream of gzipped data) and returns a *gzip.Reader that also implements io.Reader (a stream of the decompressed data). | |
Implement a rot13Reader that implements io.Reader and reads from an io.Reader, modifying the stream by applying the ROT13 substitution cipher to all alphabetical characters. | |
The rot13Reader type is provided for you. Make it an io.Reader by implementing its Read method. |
This file contains 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
/* | |
Exercise: Images | |
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data. | |
Define your own Image type, implement the necessary methods, and call pic.ShowImage. | |
Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h). | |
ColorModel should return color.RGBAModel. |
This file contains 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
/* | |
Exercise: HTTP Handlers | |
Implement the following types and define ServeHTTP methods on them. Register them to handle specific paths in your web server. | |
type String string | |
type Struct struct { | |
Greeting string | |
Punct string |
This file contains 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
/* | |
Exercise: Errors | |
Copy your Sqrt function from the earlier exercises and modify it to return an error value. | |
Sqrt should return a non-nil error value when given a negative number, as it doesn't support complex numbers. | |
Create a new type | |
type ErrNegativeSqrt float64 |
This file contains 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
/* | |
Advanced Exercise: Complex cube roots | |
Let's explore Go's built-in support for complex numbers via the complex64 and complex128 types. For cube roots, Newton's method amounts to repeating: | |
Find the cube root of 2, just to make sure the algorithm works. There is a Pow function in the math/cmplx package. | |
*/ | |
package main |