Skip to content

Instantly share code, notes, and snippets.

@junftnt
junftnt / main.go
Created September 3, 2019 21:52 — forked from zupzup/main.go
Example for Basic AST Traversal in Go
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
@junftnt
junftnt / unmarshal_interface.go
Created August 30, 2019 23:42 — forked from tkrajina/unmarshal_interface.go
Unmarshal JSON to specific interface implementation
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Something interface{}
@junftnt
junftnt / chat.go
Created August 28, 2019 23:37
simple golang chat server
package main
import (
"bufio"
"net"
)
type Client struct {
incoming chan string
outgoing chan string
@junftnt
junftnt / concurrency-in-go.md
Created August 28, 2019 00:59 — forked from kachayev/concurrency-in-go.md
Channels Are Not Enough or Why Pipelining Is Not That Easy
@junftnt
junftnt / benchmark+go+nginx.md
Created August 27, 2019 01:47
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
@junftnt
junftnt / hello.c
Created August 22, 2019 22:57 — forked from tbelaire/hello.c
A small concurrent C example
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
// Small channel library here.
// It mimics unbuffered Go channels.
typedef struct chan_int {
int message;
@junftnt
junftnt / Install_gcc7_ubuntu_16.04.md
Created August 22, 2019 19:32 — forked from jlblancoc/Install_gcc7_ubuntu_16.04.md
Installing gcc-7 & g++-7 in Ubuntu 16.04LTS Xenial

Run the following in the terminal:

Install the gcc-7 packages:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y

Set it up so the symbolic links gcc, g++ point to the newer version:

@junftnt
junftnt / clang.md
Created August 22, 2019 18:24 — forked from Ouroboros/clang.md
How to install latest clang (5.0) on Ubuntu 16.04 (xenial) / WSL
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
sudo apt-get update
sudo apt-get install -y clang-5.0 lld-5.0
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
@junftnt
junftnt / multivalChSample.go
Created August 2, 2019 17:35 — forked from slav/multivalChSample.go
Golang sending sending multiple values through channel
package main
import "fmt"
func f(c chan func() (int, string)) {
c <- (func() (int, string) { return 0, "s" })
}
func main() {
c := make(chan func() (int, string))
@junftnt
junftnt / aes-256-gcm.go
Created August 1, 2019 18:13 — forked from cannium/aes-256-gcm.go
golang aes-256-gcm
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
)