Skip to content

Instantly share code, notes, and snippets.

View rodkranz's full-sized avatar

Rodrigo Lopes rodkranz

View GitHub Profile
@rodkranz
rodkranz / update-git-folders.go
Last active March 27, 2020 11:24
Update all git repository in subfolders.
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
@rodkranz
rodkranz / CutBetweenText.go
Last active October 29, 2018 14:56
cut slice of text between start text and end text.
func CutBetweenText(s, start, end string) (string, bool) {
if !strings.HasPrefix(s, start) || !strings.HasSuffix(s, end) {
return "", false
}
if len(s) <= (len(start) + len(end)) {
return "", false
}
@rodkranz
rodkranz / image
Created July 19, 2018 18:14
get information of image without download all image
package main
import (
_ "image/png"
_ "image/gif"
_ "image/jpeg"
"time"
"net/http"
"log"
"io"
@rodkranz
rodkranz / nested.go
Last active May 18, 2018 09:30
Simple Nested in GO
package main
import (
"testing"
"fmt"
"reflect"
"strings"
)
// Implementation Nested
@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'
@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 / 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 / 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 / simpleServer.go
Created April 21, 2017 10:11
Simple file server in GO
package main
import (
"net/http"
"fmt"
"flag"
"log"
)
var (
@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.