Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
current_ioloop = tornado.ioloop.IOLoop.instnace()
worker_thread = getattr(current_ioloop, 'worker_thread', None)
if worker_thread:
pass
else:
current_ioloop.worker_thread = Thread(target=..., args=..., kwargs=...)
@yanmhlv
yanmhlv / img to base64.go
Created October 29, 2015 13:38
convert image to base64
package main
import (
"bufio"
"encoding/base64"
"fmt"
"net/http"
"os"
)
@yanmhlv
yanmhlv / benchmark+go+nginx.md
Created November 9, 2015 15:46 — forked from hgfischer/benchmark+go+nginx.md
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@yanmhlv
yanmhlv / index.html
Last active November 20, 2015 16:27
upload
<!DOCTYPE html>
<html ng-app='myapp'>
<head>
<title></title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.11.2/angular-material.min.css">
</head>
<body ng-controller='MyCtrl'>
<div id='files'>
<form name="myForm">
@yanmhlv
yanmhlv / client.go
Created November 30, 2015 20:58 — forked from cryptix/client.go
multipart upload with io.Pipe
package main
import (
"io"
"log"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"runtime"
@yanmhlv
yanmhlv / multipart_upload.go
Created November 30, 2015 20:59 — forked from mattetti/multipart_upload.go
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@yanmhlv
yanmhlv / main.go
Created November 30, 2015 21:03 — forked from mattetti/main.go
Go's reflection example
package main
import(
"fmt"
"reflect"
)
func main(){
// iterate through the attributes of a Data Model instance
for name, mtype := range attributes(&Dish{}) {
package main
import (
// "fmt"
"github.com/gin-gonic/gin"
"reflect"
// "regexp"
)
type User struct {
class Company < ActiveRecord::Base
# id int
# confirmed boolean
has_many :companies
end
class User < ActiveRecord::Base
# id int
# company_id int
# coding: utf-8
import urllib2
import sys
import random
import re
import threading
request_counter = 0
flag = 0