Skip to content

Instantly share code, notes, and snippets.

package main
import (
"html/template"
"log"
"net/http"
"time"
)
func main() {
@mmirolim
mmirolim / watcher-example.go
Last active August 29, 2015 14:14
Watcher to automate some tasks (modify as you wish)
// temp solution to run browserify with watch
package main
import (
"flag"
"log"
"os"
"os/exec"
"strings"
"time"
@mmirolim
mmirolim / rate-limit.go
Created February 20, 2015 16:35
rate-limiting with waitGroup
// fetch images concurrently with set limits equal to cl
func fetchImages(imgs Images, cl int, put, del chan<- Img, w *sync.WaitGroup) {
log.Printf("Total images to fetch %+v\n", len(imgs.List))
// loop through all images and retrive them concurrently
for i := 0; i < len(imgs.List); {
w.Add(cl)
for ii := 0; ii < cl; ii++ {
img := imgs.List[i+ii]
go getImg(img, imgs.GetImgName(i+ii), put, del, w)
}
@mmirolim
mmirolim / daemon-listen.go
Created February 25, 2015 17:12
listen to system calls
//write pid into file
f, err := os.Create("/var/run/go-ws-daemon.pid")
if err != nil {
panic(err)
}
pid := os.Getpid()
b := []byte(strconv.Itoa(pid))
_, err = f.Write([]byte(b))
if err != nil {
panic(err)
@mmirolim
mmirolim / start-stop-daemon
Created February 25, 2015 17:14
start stop daemon example
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@mmirolim
mmirolim / post_issue_gitlab.go
Created March 9, 2015 11:16
gitlab post issue in Go
func main() {
// private token for authentications
token := "5p94RchB-9pXWRE71Hv2"
ts := Issue{}
ts.PID = "root%2Fhrkb"
ts.Title = "Auto Issue"
ts.Desc = "Description should be added"
ts.Labels = "UI"
// url of gitlab issues
url := "http://office.newmax.uz:7775/api/v3/projects/" + ts.PID + "/issues"
@mmirolim
mmirolim / gist:509fa3cc0ef8aa6b05f5
Last active August 29, 2015 14:26 — forked from mcastilho/gist:e051898d129b44e2f502
Cheap MapReduce in Go
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
package main
// Example explaining how slices works
// About slice's capacity, pointers and copies
import "fmt"
func main() {
// let's create slice with len 2 and capacity 3
package main
import (
"fmt"
"log"
"net/http"
"time"
)
// handlerFuncs sayHello for http://localhost:4000/hello url
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)