Skip to content

Instantly share code, notes, and snippets.

@chespinoza
chespinoza / io2str.go
Created July 24, 2013 16:17
Simulating i/o input
package main
import (
"bufio"
"fmt"
"strings"
)
func main() {
str := []byte("T=06/06/2013 23:49:06.000\r\n")
@chespinoza
chespinoza / io2str2time.go
Created July 24, 2013 16:39
io2str in action in order to parse a datetime (Ignoring microsecs)
package main
import (
"bufio"
"fmt"
"strings"
"time"
)
const TLAYOUT = "01/02/2006 15:04:05"
@chespinoza
chespinoza / scanning.go
Created July 24, 2013 16:46
Low level parsing
func main() {
s := "123.45"
r := bytes.NewBufferString(s)
runtime.UpdateMemStats()
println(runtime.MemStats.Mallocs)
var v float64
fmt.Fscanf(r, "%f", &v)
runtime.UpdateMemStats()
println(runtime.MemStats.Mallocs)
}
@chespinoza
chespinoza / io2float.go
Created July 24, 2013 20:35
i/o to float parsing test with go
package main
import (
"bufio"
"bytes"
"fmt"
"strconv"
"strings"
)
@chespinoza
chespinoza / iosample.go
Created July 24, 2013 21:32
i/o to several floats
package main
import (
"bufio"
"fmt"
"strconv"
"strings"
)
func main() {
@chespinoza
chespinoza / io2int.go
Created July 24, 2013 21:37
io2int test
package main
import (
"bufio"
"fmt"
"strconv"
"strings"
)
func main() {
@chespinoza
chespinoza / tick.go
Created July 25, 2013 15:54
Ticker demo for repeat some task every n seconds...
package main
import (
"fmt"
"time"
)
func main() {
c := time.Tick(1 * time.Second)
for now := range c {
@chespinoza
chespinoza / readlastline.go
Last active December 20, 2015 05:59
Read last line of a long file with go
package main
import (
"fmt"
"os"
"time"
)
const MYFILE = "logfile.log"
const BYTES = 32
@chespinoza
chespinoza / webserver.go
Created July 30, 2013 03:00
Tiny Web Server with Go
package main
import (
//"fmt"
"log"
"net/http"
"time"
)
const (
@chespinoza
chespinoza / nocast.go
Created July 31, 2013 15:44
Simple string concat
package main
import (
"fmt"
"strconv"
)
func main() {
i := 80
fmt.Println(":" + strconv.Itoa(i))