Skip to content

Instantly share code, notes, and snippets.

View satyrius's full-sized avatar

Anton Egorov satyrius

  • Tallinn, Estonia
View GitHub Profile
@satyrius
satyrius / exercise-44.go
Created October 23, 2013 06:25
A Tour of Go. Exercise: Fibonacci closure. Let's have some fun with functions. Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers.
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
var a, b int
return func() int {
a, b = b, a + b
@satyrius
satyrius / exercise-41.go
Created October 23, 2013 06:23
A Tour of Go. Exercise: Maps. Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
res := make(map[string]int)
for _, w := range strings.Fields(s) {
@satyrius
satyrius / exercise-36.go
Created October 23, 2013 06:18
A Tour of Go. Exercise: Slices. Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values. The choice of image is up to you. Interesting functions include x^y, (x+y)/2…
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
res := make([][]uint8, dy)
for y := range res {
res[y] = make([]uint8, dx)
for x := range res[y] {
res[y][x] = uint8((x + y) /2)
@satyrius
satyrius / exercise-24.go
Last active December 26, 2015 07:09
A Tour of Go. Exercise: Loops and Functions. As a simple way to play with functions and loops, implement the square root function using Newton's method. In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: To begin with, just repeat that calculation 10 times and see how close you get to the an…
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 1; i <= 10; i++ {
@satyrius
satyrius / install.sh
Created February 28, 2012 08:36
Dotfiles installation
cd $HOME
git clone git@github.com:satyrius/dotfiles.git .dotfiles
cd .dotfiles
for f in $(ls); do df="../.$f"; rm $df; ln -s "$(pwd)/$f" $df; done;
cd $HOME
rm .README.dm
@satyrius
satyrius / install.sh
Last active September 29, 2015 17:08 — forked from asenchi/notes.md
Homebrew formula for VIM with python interpreter support
brew install python --framework
mkdir ~/Library/Frameworks/
cd ~/Library/Frameworks/
ln -s /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework .
brew install -v https://gist.github.com/satyrius/1635076/raw/vim.rb