Skip to content

Instantly share code, notes, and snippets.

View maxcnunes's full-sized avatar
🏠
Working from home forever and ever

Max Claus Nunes maxcnunes

🏠
Working from home forever and ever
View GitHub Profile
@maxcnunes
maxcnunes / dump-request.go
Created June 6, 2019 21:35
Dump http request in Go
// Save a copy of this request for debugging.
requestDump, err := httputil.DumpRequest(r, true)
if err != nil {
fmt.Println("--->DEBUG ERROR", r.URL, err)
}
fmt.Println("--->DEBUG BODY", r.URL, string(requestDump))
@maxcnunes
maxcnunes / gist:3e64a3422564f88b5629da5a0ccd4fc1
Created March 18, 2019 21:11
Docker - list all containers' ip and find container by ip
for i in $(docker ps -aq); do docker inspect -f '{{.Name}}: IP={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$i"; done | grep <ip-here>
@maxcnunes
maxcnunes / status_test.go
Last active March 9, 2019 13:10
Performance over different approaches to get a mask format from a HTTP status code (e.g. 201=2xx, 204=2xx, 405=4xx, 500=5xx)
package util_test
import (
"fmt"
"math"
"regexp"
"strconv"
"testing"
)
@maxcnunes
maxcnunes / result
Created March 8, 2019 22:46
Performance and memory profiling Go concat vs fmt.Sprintf
go test -bench=. -memprofile=mem0.out -benchmem -benchtime=5s
goos: darwin
goarch: amd64
pkg: github.com/InVisionApp/craft-api/util
BenchmarkHello/concat-8 300000000 19.8 ns/op 0 B/op 0 allocs/op
BenchmarkHello/sprintf-8 50000000 119 ns/op 19 B/op 2 allocs/op
PASS
@maxcnunes
maxcnunes / pull_pr.sh
Last active December 25, 2017 12:26
Simple script to pull Git PRs
pull_pr() {
pr_num=$1
git fetch origin refs/pull/$pr_num/head:pr/$pr_num
}
@maxcnunes
maxcnunes / remove-node_module-recursively-1.sh
Last active January 25, 2017 17:24
Remove all node_module folders recursively. Useful to free up disk space by removing the node_module from those projects you have not used for a while.
# Simple version using only "find"
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
Code move event for unknown code: 0x3c010c699080
Code move event for unknown code: 0x3c010c69b9c0
Code move event for unknown code: 0x3c010c5729a0
Code move event for unknown code: 0x3c010c57daa0
Code move event for unknown code: 0x3c010c5c8f00
Code move event for unknown code: 0x3c010c5d90a0
Statistical profiling result from v8.log, (22371 ticks, 0 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
μ sqlectron/sqlectron-gui master ❯ npm run dist
> @ dist /Users/maxcnunes/Development/sqlectron/sqlectron-gui
> npm run compile && build --arch all
> @ compile /Users/maxcnunes/Development/sqlectron/sqlectron-gui
> rimraf app/out && cross-env NODE_ENV=production babel-node scripts/compile.js -v
> cleaning old distribution files
brew install dnsmasq
mkdir -pv $(brew --prefix)/etc/
echo 'address=/.dev/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'
@maxcnunes
maxcnunes / load-connection-uri-from-env-config.go
Created April 12, 2016 11:13
Load connection URI from ENV config
func connectionURIFromEnvConfig() string {
errMsg := "no valid connection string provided"
connConfig, err := url.Parse(os.Getenv("DB_PORT"))
if err != nil {
log.Fatalln(errMsg)
}
dbHost, dbPort, err := net.SplitHostPort(connConfig.Host)
if err != nil {