Skip to content

Instantly share code, notes, and snippets.

View gkristic's full-sized avatar

Gustavo Kristic gkristic

View GitHub Profile

Keybase proof

I hereby claim:

  • I am gkristic on github.
  • I am gkristic (https://keybase.io/gkristic) on keybase.
  • I have a public key ASBw5-o5p-7o4bm_mLdOd6WY2b3V2iF-zGxvbrxUHhTkoAo

To claim this, I am signing this object:

@gkristic
gkristic / main_test.go
Created February 20, 2014 12:32
Regular expressions are flexible, but that obviously comes with a time penalty. If you need to check for very specific cases, you may be better off writing the function yourself. Check this out...
package main
import (
"regexp"
"testing"
)
func matches(str, pattern string) bool {
p, s := 0, 0
matches := true
@gkristic
gkristic / proc.go
Created February 4, 2014 01:16
My idea of a process supervisor, using locking to react immediately to supervised processes deaths. As locks are guaranteed to be released when the process ends, no matter the reason, this can as easily detect crashes or processes killed with SIGKILL. It also writes pid files, though that's a bonus feature, not strictly required.
package main
import (
"fmt"
"os"
"strings"
"syscall"
"time"
)
@gkristic
gkristic / result.txt
Created December 19, 2013 20:56
This is a small benchmark measuring fmt.Sscanf() abilities to parse an integer, vs. strconv.ParseInt(). Run with "go test -bench=." (no quotes) and see for yourself; results are amazing... Sscanf() is 40 times slower parsing a simple integer than ParseInt().
BenchmarkIntParse 50000000 57.1 ns/op
BenchmarkIntScanf 1000000 1911 ns/op
BenchmarkStrScanf 1000000 1675 ns/op
@gkristic
gkristic / fork2.go
Created March 28, 2013 17:54
Proof of concept for deamons
package main
import (
"os"
"log"
"time"
"syscall"
)
func main() {