Skip to content

Instantly share code, notes, and snippets.

View andreleoni's full-sized avatar
🎮
playing software development

André Luiz Leoni andreleoni

🎮
playing software development
View GitHub Profile
@andreleoni
andreleoni / Dockerfile
Created March 31, 2024 22:03
Golang docker-compose.yml with mongodb and multiple microservices
FROM golang:1.22.1
WORKDIR /go/src/app
COPY . .
RUN go mod download
# dd if=/dev/zero of=/swapfile bs=1M count=12k
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.23138 s, 872 MB/s
# losetup --find --show /swapfile
/dev/loop0
# mkswap /dev/loop0
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
@andreleoni
andreleoni / array.rb
Created January 15, 2021 22:48
flatten implementation for ruby
input = [[1, 2], 3, 4, 5, [6, 7, [8, [10, 11],9]]]
expected = input.dup.flatten
class Array
def flatten2!
self.replace(flatten2)
end
def flatten2(array = self, result = [])
array.each { |a| a.is_a?(Array) ? flatten2(a, result) : result << a }
@andreleoni
andreleoni / main.go
Created August 11, 2020 01:51
context studies
package main
import (
"context"
"fmt"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(
@andreleoni
andreleoni / separate.rb
Last active July 31, 2020 20:06
Separate CSV in slices
require "csv"
current = 0
read_to_array = CSV.read("all.csv", :headers => true)
unique_user_ids = read_to_array.uniq { |u| u["user_id"] }
unique_user_ids.each_slice(10000) do |rows|
CSV.open("slice-#{current}.csv", "w") do |csv|
rows.each do |row|
@andreleoni
andreleoni / main.go
Last active May 16, 2020 18:28
[Medium] Example of code with principle open-closed with GOLang
package main
import "fmt"
// Product attributes to be filtered
type Color int
const (
red Color = iota
green
@andreleoni
andreleoni / main.go
Last active May 16, 2020 18:27
[Medium] Example of code without principle open-closed with GOLang
package main
import "fmt"
// Product structures to be filtered
type Color int
const (
red Color = iota
green
Os cenários se repetem pra bundle. Com excessao que nao poderá receber o email 2x, e fazer 2 requests de cancelamento para os correios.
O job: verifica unidades suspensas com "shipments" até completar os 7 dias de envio de suas etiquetas.
- Executa o procedimento de bloqueio nos correios para cada um destes.
Cenário 1:
Sendo um Usuário que comprei um produto fora da setting
E Gerei etiqueta
E encaminhei o produto
@andreleoni
andreleoni / bench.rb
Last active February 8, 2019 13:43
Benchmark sobre uso de memória Ruby Module vs Class
# Gem: https://github.com/SamSaffron/memory_profiler
##### Benchmark vendo memória de um módulo
require "memory_profiler"
MemoryProfiler.start
module Teste
extend self
@andreleoni
andreleoni / gist:3708cd58e730d72bc644515d17722de0
Created January 21, 2019 20:12
total of purchase ratings on the years
SELECT COUNT(DISTINCT (CASE WHEN bundle_id IS NOT NULL THEN bundle_id END )) + COUNT(CASE WHEN bundle_id IS NULL THEN 1 END)
FROM purchase_ratings
WHERE created_at BETWEEN to_date('01/09/2018', 'DD/MM/YYYY') AND to_date('30/09/2018', 'DD/MM/YYYY')
Janeiro
39,688
Fevereiro