This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for column_name in df.columns: | |
defined_type = column_types[column_name] | |
if defined_type == 'int': | |
df[column_name] = df[column_name].astype(int) | |
# e por aí vai... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: Understanding the Chain of responsability pattern | |
published: false | |
description: How to implement the design pattern "chain of responsibility" | |
tags: pattern | |
--- | |
# Introduction | |
On many occasions on our projects, we find ourselves writing pieces of code that stop entirely the program or to continue given a specific condition, it can be a validation of data that was sent, a query on the database, or a logic validation of our business rules, to solve each validation we tend to write simple `ifs`, in many cases it fits well but it also starts to generate a bigger problem that is having a bunch of `ifs` on the same place will make the code harder to debug and read. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LOOP DE TESTE | |
for _, tc := range testCases { | |
t.Run(tc.testName, func(t *testing.T) { | |
record := Call{ | |
StartPeriod: tc.start, | |
EndPeriod: tc.end, | |
} | |
price, _ := CalcAmount(record) | |
amountAsDecimal, _ := decimal.NewFromFloat(tc.expectedAmount).Float64() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This algorith convert all keys from json from camelCase to snake_case recursivily | |
""" | |
def _unpack(data): | |
if isinstance(data, dict): | |
return data.items() | |
return data | |
def snake_case(value): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function tipo(varchar) | |
returns setof notas as | |
' | |
SELECT n.* FROM notas n, tiponota t | |
where t.nome = $1 | |
and t.codigo = n.tipo_nota; | |
' | |
language 'sql'; | |
-- select tipo('p1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table fornecedor( | |
codigo integer primary key, | |
razao_social varchar(100), | |
telefone varchar(10) | |
); | |
create table categoria( | |
codigo integer primary key, | |
nome varchar(100) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
func GetPeople(w http.ResponseWriter, r *http.Request) {} | |
func GetPerson(w http.ResponseWriter, r *http.Request) {} | |
func CreatePerson(w http.ResponseWriter, r *http.Request) {} | |
func DeletePerson(w http.ResponseWriter, r *http.Request) {} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
"github.com/gorilla/mux" | |
) | |
// nossa função principal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
router := mux.NewRouter() | |
router.HandleFunc("/contato", GetPeople).Methods("GET") | |
router.HandleFunc("/contato/{id}", GetPerson).Methods("GET") | |
router.HandleFunc("/contato/{id}", CreatePerson).Methods("POST") | |
router.HandleFunc("/contato/{id}", DeletePerson).Methods("DELETE") | |
log.Fatal(http.ListenAndServe(":8000", router)) | |
} |
NewerOlder