Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
#!/bin/sh
### BEGIN INIT INFO
# Provides: btsync
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multi-user daemonized version of btsync.
@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 / 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{}) {

What is sync.Pool in golang and How to use it

sync.Pool (1/2)

Many Go libraries include custom thread-safe free lists, like this:

var objPool = make(chan *Object, 10)

func obj() *Object {

select {

@yanmhlv
yanmhlv / mergesort.lhs
Created October 5, 2016 12:23 — forked from callistabee/mergesort.lhs
Haskell Implementation of Mergesort
- Haskell Mergesort
- Copyright (C) 2014 by Kendall Stewart
First we define a couple of helper functions that
will be useful in splitting the list in half:
> fsthalf :: [a] -> [a]
> fsthalf xs = take (length xs `div` 2) xs
@yanmhlv
yanmhlv / porno.md
Created January 26, 2017 09:30 — forked from strizhechenko/porno.md
Код ниже генерирует прекрасные названия, не знаю для чего, новые жанры порно или названия программных проектов.
#!/usr/bin/env bash

if [ ! -f /tmp/linux ]; then
    curl -sS https://www.linux.org.ru/ | egrep -o /tag/[0-9a-z-]+ | sed 's|/tag/||' > /tmp/linux
fi
if [ ! -f /tmp/pron ]; then
    curl -sS http://www.xvideos.com/tags  | egrep -o /tags/[a-z0-9-]+ | sed 's|/tags/||' > /tmp/pron
fi
@yanmhlv
yanmhlv / bash-cheatsheet.sh
Created April 30, 2017 13:22 — forked from bilun167/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@yanmhlv
yanmhlv / gist:a608d7a342cd00b839147d15dbbf9dcd
Created September 15, 2017 12:07 — forked from the42/gist:1956518
GZip encoding for GO V1 using custom responsewriter
package main
import (
"compress/gzip"
"io"
"net/http"
"strings"
)
type gzipResponseWriter struct {