Skip to content

Instantly share code, notes, and snippets.

View rodkranz's full-sized avatar

Rodrigo Lopes rodkranz

View GitHub Profile
@rodkranz
rodkranz / readFileByChunks.go
Created January 14, 2017 12:15
Read big file by chunk in go
// Copyright 2017 Kranz. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
import (
"os"
"log"
"io"
"bufio"
@rodkranz
rodkranz / ReadBigFileAndParse.go
Created January 16, 2017 01:24
Read big file and unmarshal in json
// Package main
// Copyright 2017 Kranz. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
/**
Test read file by chunks
read ll
total 13241936
drwxr-xr-x 5 rlopes staff 170B 16 Jan 01:19 ./
@rodkranz
rodkranz / bashrc
Last active June 22, 2018 22:23
Golang environment
# OS
# export GOOS=linux
# ROOT FILES
export GOROOT=/usr/local/go
# Define here your path of GO projects
export GOPATH=$HOME/Projects
# Export go project in terminal
export GOBIN=$GOPATH/bin
@rodkranz
rodkranz / convert-id_rsa-to-pem.sh
Created February 15, 2017 14:48
Convert id_rsa to pem file
# Convert
openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
# Permission
chmod 700 id_rsa.pem
@rodkranz
rodkranz / github.md
Last active August 29, 2017 10:08
Github helpers

Rename your local branch.

If you are on the branch you want to rename:

$ git branch -m new-name

If you are on a different branch:

$ git branch -m old-name new-name

Delete the old-name remote branch and push the new-name local branch.

@rodkranz
rodkranz / simpleServer.go
Created April 21, 2017 10:11
Simple file server in GO
package main
import (
"net/http"
"fmt"
"flag"
"log"
)
var (
@rodkranz
rodkranz / middleware.go
Created July 11, 2017 22:11
Example of middleware in GO
package main
import (
"fmt"
"os"
"net/http"
"log"
"context"
"time"
)
@rodkranz
rodkranz / cpu_process.go
Created July 24, 2017 17:50
Test Usage of CPU Raw
// Copyright 2017 rodkranz. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"runtime"
"time"
)
@rodkranz
rodkranz / GoConfigPrivateRepository.md
Last active July 27, 2022 13:15
Go Get from private repository

I had a problem with go get using private repository on gitlab from our company. I lost a few minutes trying to find a solution.... and I did find one:

  1. You need to get a private token at:

    https://gitlab.mycompany.com/profile/account

  2. Configure you git to add extra header with your private token:

$ git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN"

@rodkranz
rodkranz / BuildCoverage.sh
Last active October 9, 2017 10:53
Build all coverage package.
#!/bin/bash
[ -d "$DIRECTORY" ] || mkdir coverage
for pkg in $(go list ./... | tail +2); do
name=$(echo "$pkg" | rev | cut -d'/' -f1 | rev)
go test -coverprofile=coverage/${name}.cover.out ${pkg}
done
echo "mode: set" > coverage/coverage.out && cat coverage/*.cover.out | grep -v mode: | sort -r | awk '{if($1 != last) {print $0;last=$1}}' >> coverage/coverage.out
go tool cover -html='coverage/coverage.out' -o 'coverage/coverage.html'