Skip to content

Instantly share code, notes, and snippets.

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

Leonardo Farias leleofg

🏠
Working from home
View GitHub Profile
@leleofg
leleofg / crud.js
Last active October 22, 2019 14:31
Demonstração do crud de usuários com async/await em node.js para o post no medium https://medium.com/@leoo.farias/crud-com-async-await-no-node-js-4e1032da5a33
exports.get = async(req, res, next) => {
try {
const data = await repository.get();
res.status(200).send({data: data});
} catch (e) {
res.status(500).send({
message: 'Falha ao processar sua requisição'
});
}
}
@leleofg
leleofg / dataframe_2_example.py
Created February 1, 2018 03:31
dataframe_2_example
import pandas as pd
purchase_1 = pd.Series({'Name': 'Chris',
'Item Purchased': 'Dog Food',
'Cost': 22.50})
purchase_2 = pd.Series({'Name': 'Kevyn',
'Item Purchased': 'Kitty Litter',
'Cost': 2.50})
purchase_3 = pd.Series({'Name': 'Vinod',
'Item Purchased': 'Bird Seed',
@leleofg
leleofg / pandas_discount.py
Created February 1, 2018 02:46
Pandas Discount
import pandas as pd
purchase_1 = pd.Series({'Name': 'Chris',
'Item Purchased': 'Dog Food',
'Cost': 22.50})
purchase_2 = pd.Series({'Name': 'Kevyn',
'Item Purchased': 'Kitty Litter',
'Cost': 2.50})
purchase_3 = pd.Series({'Name': 'Vinod',
'Item Purchased': 'Bird Seed',
@leleofg
leleofg / numpy_array.py
Last active February 1, 2018 01:12
Numpy array
import numpy as np
mylist = [1, 2, 3, 4]
x = np.array(mylist)
print(x)
# array([1, 2, 3, 4])
y = np.array([1, 2, 3], [4, 6, 12])
print(y)
# array([[1, 2, 3],[4, 6, 12]])
@leleofg
leleofg / map.py
Created January 31, 2018 16:19
Example Map function
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
def split_title_and_name(person):
title = person.split()[0]
lastname = person.split()[-1]
return '{} {}'.format(title, lastname)
list(map(split_title_and_name, people))
#['Dr. Brooks', 'Dr. Collins-Thompson', 'Dr. Vydiswaran', 'Dr. Romero']
var string = "abcd";
var array = string.split("");
for(i=0; i<array.length;i++){
str = array[i].repeat(i+1);
if(str.length == 1) {
console.log(str.toUpperCase());
} else {
primeira_posicao = str.substring(0,1);