Skip to content

Instantly share code, notes, and snippets.

View rafa-acioly's full-sized avatar
💭
-f

Rafael Acioly rafa-acioly

💭
-f
  • São Paulo - Brazil
View GitHub Profile
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...
---
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.
@rafa-acioly
rafa-acioly / test.go
Created November 6, 2018 15:53
pointer go
// 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()
@rafa-acioly
rafa-acioly / convert_json_keys_from_camel_case_to_snake_case.py
Last active June 14, 2024 19:42
Convert all keys from json/dict from camelCase to snake_case
"""
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):
@rafa-acioly
rafa-acioly / aula_10.sql
Created April 25, 2018 00:38
functions in sql and plpgsql
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');
create table fornecedor(
codigo integer primary key,
razao_social varchar(100),
telefone varchar(10)
);
create table categoria(
codigo integer primary key,
nome varchar(100)
);
...
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) {}
...
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/gorilla/mux"
)
// nossa função principal
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))
}
@rafa-acioly
rafa-acioly / create_menu_with_submenu_wordpress.php
Created November 18, 2017 15:48
Organize all menus with their respectives submenus.
<?php
function generateMenu ()
{
$array_menu = wp_get_nav_menu_items('main-menu');
$menu = [];
$submenu = [];
foreach ($array_menu as $item_menu) {
if (empty($item_menu->menu_item_parent)) {
$menu[$item_menu->ID] = [