Skip to content

Instantly share code, notes, and snippets.

View rafaeljesus's full-sized avatar

Rafael Jesus rafaeljesus

  • Berlin, Germany
View GitHub Profile
@rafaeljesus
rafaeljesus / limitConcurrentGoroutines.go
Created June 18, 2017 15:47 — forked from AntoineAugusti/limitConcurrentGoroutines.go
Limit the maximum number of goroutines running at the same time
package main
import (
"flag"
"fmt"
"time"
)
// Fake a long and difficult work.
func DoWork() {
@rafaeljesus
rafaeljesus / gist:1952d9d94f72979c3b5733c87a165d41
Created June 9, 2017 05:51 — forked from dmitshur/gist:6927554
How to `go get` private repos using SSH key auth instead of password auth.
$ ssh -A vm
$ git config --global url."[email protected]:".insteadOf "https://github.com/"
$ cat ~/.gitconfig
[url "[email protected]:"]
	insteadOf = https://github.com/
$ go get github.com/private/repo && echo Success!
Success!
@rafaeljesus
rafaeljesus / benchmark+go+nginx.md
Created April 29, 2017 06:37 — 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
@rafaeljesus
rafaeljesus / .vimrc
Created April 14, 2017 13:51 — forked from doMynation/.vimrc
.vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"Plugin 'tpope/vim-fugitive'
Plugin 'scrooloose/nerdtree'
Plugin 'Shougo/neocomplete.vim'
@rafaeljesus
rafaeljesus / context.go
Created February 1, 2017 13:49 — forked from iamralch/context.go
An example that illustrates how to work with https://godoc.org/golang.org/x/net/context
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
"golang.org/x/net/context"
@rafaeljesus
rafaeljesus / sortmap.go
Created January 29, 2017 13:17 — forked from ikbear/sortmap.go
Sort Map(golang)
package main
// sort a map's keys in descending order of its values.
import "sort"
type sortedMap struct {
m map[string]int
s []string
}
@rafaeljesus
rafaeljesus / chain-of-responsibility.rb
Created December 9, 2016 17:45 — forked from martindemello/chain-of-responsibility.rb
chain of responsibility example in ruby
class PurchaseApprover
# Implements the chain of responsibility pattern. Does not know anything
# about the approval process, merely whether the current handler can approve
# the request, or must pass it to a successor.
attr_reader :successor
def initialize successor
@successor = successor
end
@rafaeljesus
rafaeljesus / asyncfetchtimeout.go
Created November 11, 2016 23:09 — forked from pranjal5215/asyncfetchtimeout.go
Non working code panics on runtime.
package main
import (
"fmt"
"net"
"net/http"
"time"
)
var urls = []string{
@rafaeljesus
rafaeljesus / test.js
Created October 31, 2016 20:32 — forked from alanhoff/test.js
const nsq = require('nsq')
const crypto = require('crypto')
module.exports = async (req, res) => {
async validarAuth(req.header.authentication)
// Depois de validar iniciar a escuta em uma fila única para essa request
const replyQueue = crypto.randomBytes(30).toString('hex')
nsq.on(replyQueue, data => {
res.json(data)
@rafaeljesus
rafaeljesus / gist:d832cc5a5038a2b46493dfbf8f47a4d8
Created October 26, 2016 16:58 — forked from rubencaro/gist:9545060
Reversible encryption for url json data
require 'openssl'
require 'digest/sha1'
require 'base64'
require 'json'
def go_demo!
key = Digest::SHA1.hexdigest("clave1")[0..15] # 16bytes => 128bits
iv = 'clave2 con chicha'[0..15] # 16bytes forced
data = { esto: 'es', un: 'hash', en: 'ruby' }