Skip to content

Instantly share code, notes, and snippets.

View slawosz's full-sized avatar

Sławosz Sławiński slawosz

View GitHub Profile
threads = []
3.times do |i|
threads << Thread.new do
3.times do |j|
puts "Thread #{i} says #{j} (#{Thread.current})"
sleep 0.1
end
end
end
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct{
w, h int
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
package main
import "fmt"
type Vertex struct {
X, Y float64
}
func main() {
var vertexp *Vertex;
@slawosz
slawosz / cube.go
Created July 1, 2013 17:32
cube root in Go
package main
import (
"fmt"
"math/cmplx"
)
func Cbrt(x complex128) complex128 {
z := x
// fmt.Println(cmplx.Abs(cmplx.Pow(z, 2) - x))
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
f0 := 0
f1 := 1
return func() int {
@slawosz
slawosz / word_count_and_split.go
Last active December 18, 2015 23:29
counting words in go
package main
import (
"code.google.com/p/go-tour/wc"
"fmt"
)
func WordCount(s string) map[string]int {
dict := make(map[string]int)
@slawosz
slawosz / pictures.go
Created June 24, 2013 18:00
Go pictures
// http://tour.golang.org/#35
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
picture := make([][]uint8, dx)
for i := 0; i < dx; i++ {
picture[i] = make([]uint8, dy)
}
@slawosz
slawosz / newton.go
Last active December 18, 2015 04:28
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := x
delta := 0.00000000001