Skip to content

Instantly share code, notes, and snippets.

View keshavab's full-sized avatar

Keshava keshavab

  • Bangalore
  • 16:53 (UTC +05:30)
View GitHub Profile
@keshavab
keshavab / testnilchannel.go
Created June 17, 2016 08:23
testing nil channel
package main
import (
"fmt"
"time"
)
func main() {
var ch chan int
(dlv) vars
panic: runtime error: makeslice: len out of range
goroutine 75 [running]:
panic(0x4620220, 0xc820ea3f30)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
github.com/derekparker/delve/proc.(*Thread).readMemory(0xc820d76190, 0xc820090000, 0xfffffffffffffff0, 0x0, 0x0, 0x0, 0x0, 0x0)
/private/tmp/delve20160603-64173-7ebqc8/delve-0.11.0-alpha/src/github.com/derekparker/delve/proc/threads_darwin.go:112 +0x9c
github.com/derekparker/delve/proc.cacheMemory(0x61a0ad8, 0xc820ef92f0, 0xc820090000, 0xfffffffffffffff0, 0x0, 0x0)
/private/tmp/delve20160603-64173-7ebqc8/delve-0.11.0-alpha/src/github.com/derekparker/delve/proc/mem.go:42 +0xf2
index - 3, value - 4
index - 3, value - 4
index - 3, value - 4
index - 3, value - 4
package main
import "fmt"
func functions() []func() {
// pitfall of using loop variables
arr := []int{1, 2, 3, 4}
result := make([]func(), 0)
// functions are not evaluated, functions definitions are returned
counter - 100
counter1 - 100
counter - 101
counter1- 100
counter - 101
counter1- 102
package main
import "fmt"
func counter(start int) (func() int, func()) {
// if the value gets mutated, the same is reflected in closure
ctr := func() int {
return start
}
package main
import "fmt"
func outer(name string) func() {
// variable
text := "Modified " + name
// closure. function has access to text even after exiting this block
foo := func() {
@keshavab
keshavab / closure1.go
Created March 31, 2016 10:31
closure introduction
package main
import "fmt"
func outer(name string) {
// variable in outer function
text := "Modified " + name
// foo is a inner function and has access to text variable, is a closure
// closures have access to variables even after exiting this block
@keshavab
keshavab / anonfuncs.go
Last active March 31, 2016 10:15
anonymous function
package main
import "fmt"
func printMessage(message string) {
fmt.Println(message)
}
func getPrintMessage() func(string) {
// returns an anonymous function
@keshavab
keshavab / wercker.yml
Created March 15, 2016 05:39
wercker for automated github pages deployment
box: debian
build:
steps:
- script:
name: install git
code: |
apt-get update
apt-get install git -y
- script:
name: fetch theme sub module