Skip to content

Instantly share code, notes, and snippets.

@aalvesjr
aalvesjr / v.rs
Created July 19, 2020 22:12
Rust notations
// mutable references are move
// unmutable references are copy
@aalvesjr
aalvesjr / graph.md
Created April 21, 2020 00:44
Seaching over a graph with recursive queries (Postgres)

img

CREATE TEMP TABLE prod_comps (
  prod_id VARCHAR(20),
  comp_id VARCHAR(20)
);

INSERT INTO prod_comps (prod_id, comp_id) VALUES ('Prod', 'B');
INSERT INTO prod_comps (prod_id, comp_id) VALUES ('Prod', 'C');
@aalvesjr
aalvesjr / transaction.md
Created June 22, 2018 17:55
Using transaction on Postgresql
psql (9.6.1, server 9.5.10)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

auth_svc=> select id, deleted_at from users order by id desc limit 2;
   id    | deleted_at
---------+------------
 1910482 |
 1910481 |
@aalvesjr
aalvesjr / links.md
Created February 20, 2018 18:50
Rate Limiting in golang
@aalvesjr
aalvesjr / main.go
Last active May 22, 2017 14:29
Using Authorizate middleware to check JWT token and enqueue the next handler
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/gorilla/mux"
@aalvesjr
aalvesjr / token-jwt.go
Created May 22, 2017 02:07
Try JWT with golang
package main
import (
"fmt"
"time"
"github.com/dgrijalva/jwt-go"
)
const secret = "big-secret"
@aalvesjr
aalvesjr / gormtest.go
Last active May 19, 2017 15:02
[Golang] Relacionamento com GORM
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
type Manufacturer struct {
gorm.Model
@aalvesjr
aalvesjr / train.rb
Last active May 25, 2017 17:33
Train problem
position_train = 0
def train_leaving_station(station, train)
return if station.empty?
if station.last == train[position_train]
station.pop
position_train++
train_leaving_station(station, train)
@aalvesjr
aalvesjr / commands.sh
Created April 3, 2017 01:39
Golang more detailed testing
# covermodes: set, atomic, count
go test -coverprofile="coverage.out" -covermode count
# coverage by function
go tool cover --func="coverage.out"
# HTML
go tool cover -html=coverage.out -o coverage.html
@aalvesjr
aalvesjr / links.md
Created March 24, 2017 01:47
Links to try use migration schema in Golang