Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
package main
import "fmt"
func main() {
mydict := map[string]int{
"1": 1,
"2": 2,
"3": 3,
}
package main
import (
"fmt"
"html/template"
"os"
"time"
)
func buildTemplate(name string, leftDelim string, rightDelim string) *template.Template {
@yanmhlv
yanmhlv / pool.go
Last active July 7, 2016 15:57
worker thread pool example
type Payload interface{}
// Job represents the job to be run
type Job struct {
Payload Payload `json:"payload"`
}
type WorkerHandler func(job Job)
// Worker represents the worker that executes the job
@yanmhlv
yanmhlv / query_controller.go
Last active April 1, 2016 14:14
simple query controller, handle GET-params
package main
import (
"fmt"
"log"
"time"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
)
function levelOrder (node, visit) {
'use strict'
let queue = [node]
while (queue.length > 0) {
node = queue.pop()
if (!node) {
continue
}
package main
import "fmt"
type Node struct {
Value string
Left *Node
Right *Node
}
@yanmhlv
yanmhlv / example.go
Created February 8, 2016 14:49
JSONB in gorm
package main
import (
"database/sql/driver"
"encoding/json"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
FROM golang:1.5.3
EXPOSE 3000
RUN mkdir -p /go/src/myapp
COPY . /go/src/myapp
RUN cd /go/src/myapp \
&& go get -d \
&& go install myapp
ENTRYPOINT /go/bin/myapp
@yanmhlv
yanmhlv / get_banners.go
Last active January 19, 2017 10:21
go run get_banners.go; wrk -s wrk.lua -d30s -t10 -c100 http://localhost:3000/
package main
import (
"errors"
"log"
"net/http"
"strconv"
"sync"
//"sync/atomic"
"encoding/json"