Skip to content

Instantly share code, notes, and snippets.

View martinusso's full-sized avatar
🏠
Working from home

Breno Martinusso martinusso

🏠
Working from home
View GitHub Profile
@martinusso
martinusso / sort_reverse_by_values.go
Created February 7, 2021 14:38
sort and reverse map by values - golang
// A slice of pairs that implements sort.Interface to sort and reverse by values
type PairList []Pair
func (p PairList) Len() int { return len(p) }
func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p PairList) Less(i, j int) bool { return p[i].Value < p[j].Value }
func sortMapByValues(m map[string]float64) PairList {
p := make(PairList, len(m))
@martinusso
martinusso / id.go
Created September 25, 2020 19:34
id
package main
import (
"database/sql/driver"
"github.com/google/uuid"
)
type ID string
@martinusso
martinusso / duration.go
Created August 25, 2020 16:32
golang duration in days, months, years...
package main
import (
"fmt"
"math"
"time"
)
func RoundTime(input float64) int {
var result float64
@martinusso
martinusso / round.go
Created August 25, 2020 16:22
golang round
func Round(input float64) int {
var result float64
if input < 0 {
result = math.Ceil(input - 0.5)
} else {
result = math.Floor(input + 0.5)
}
// only interested in integer, ignore fractional
i, _ := math.Modf(result)
return int(i)
@martinusso
martinusso / client.go
Last active August 14, 2020 16:59
gzip http golang
func main() {
req, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}
req.Header.Add("Accept-Encoding", "gzip")
httpClient := &http.Client{Timeout: 15 * time.Second}
res, err := httpClient.Do(req)
if err != nil {

nodejs

Use n module from npm in order to upgrade node

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = 'database_name'
;
@martinusso
martinusso / ambiente_python.md
Last active January 8, 2023 20:54
Preparando ambiente Python

pyenv

dependências

sudo apt update
sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

instala Pyenv

@martinusso
martinusso / deploy_dokku.yml
Created May 23, 2020 21:17
Github Action - Deploy Dokku
name: Deploy using Dokku
on:
push:
branches: [ master ]
jobs:
build:
name: Deploy
FROM httpd:2.4 as apache
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf && \
sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf
FROM apache as production-stage
WORKDIR /usr/local/apache2/htdocs/
RUN rm index.html