Skip to content

Instantly share code, notes, and snippets.

@chespinoza
chespinoza / firstclassfunctions.go
Created August 5, 2014 15:25
Uhmm Go have first class functions
// Playing with functions
// This is really useful
package main
import "fmt"
func greet() {
fmt.Println("Hello!")
}
func farewell() {
@chespinoza
chespinoza / vowels.go
Created July 11, 2013 21:14
Finding Vowels with Go
package main
import "fmt"
func main() {
myString := "OLapOKA3EOR"
t := 0
for _, value := range myString {
switch value {
case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U':
@chespinoza
chespinoza / numbers.go
Created July 11, 2013 21:18
FInding Numbers with Go
package main
import "fmt"
func main() {
myString := "OLapOKA3EOR"
t := 0
for _, value := range myString {
switch {
case value >= '0' && value <= '9':
@chespinoza
chespinoza / fib.go
Created July 11, 2013 22:11
A bored FIbonacci Generator
package main
import "fmt"
func main() {
for i, j := 0, 1; j < 100; i, j = i+j,i {
fmt.Println(i)
}
}
@chespinoza
chespinoza / str2slice.go
Last active December 19, 2015 15:58
A example of string to a slice of bytes in Go, using a function example from Effective Go
// From effective Go
// Compare returns an integer comparing the two byte slices,
// lexicographically.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b
package main
import "fmt"
func Compare(a, b []byte) int {
@chespinoza
chespinoza / str2slice2.go
Created July 11, 2013 23:12
A better string -> slice aproach according to myself :-)
package main
import "fmt"
func main() {
str := "abc"
mySlice := []byte(str)
fmt.Printf("%v -> '%s'",mySlice,mySlice )
}
[
{
"startTime":1373528184507.288,
"data":{
},
"children":[
{
"startTime":1373528184507.834,
"data":{
include $(GOROOT)/src/Make.inc
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4
all:
$(GC) jsontest.go
$(LD) -o jsontest.out jsontest.$O
format:
$(GOFMT) -w jsontest.go
@chespinoza
chespinoza / substrings
Last active December 19, 2015 19:09
Comparación entre funciones de busqueda de substrings
func GetId(s string) string {
i := strings.Index(s[0:], "ID=")
if i == -1 {
return ""
}
return s[i+3 : i+18]
}
var idRegex = regexp.MustCompile(`ID=(.*?)<`)
@chespinoza
chespinoza / split.go
Last active December 20, 2015 03:59
Parse a string using blank spaces with Go
package main
import "fmt"
import "strings"
func main() {
someString := "one two three four "
words := strings.Fields(someString)