Skip to content

Instantly share code, notes, and snippets.

View allonsmandy's full-sized avatar
👩‍💻
Working from home

Amanda Almeida Matos allonsmandy

👩‍💻
Working from home
View GitHub Profile
@allonsmandy
allonsmandy / filterArray.js
Created January 4, 2021 14:46 — forked from jherax/arrayFilterFactory.1.ts
Filters an array of objects with multiple match-criteria.
/**
* Filters an array of objects using custom predicates.
*
* @param {Array} array: the array to filter
* @param {Object} filters: an object with the filter criteria
* @return {Array}
*/
function filterArray(array, filters) {
const filterKeys = Object.keys(filters);
return array.filter(item => {
@allonsmandy
allonsmandy / exceptions.py
Created August 31, 2020 07:02
Exceções em python
lista = [1, 10]
try:
divisao = 10 / 1
numero = lista[1
x = a
except ZeroDivisionError # classe de excessões acoplada ja no python
print('Não é possivel realizar uma divisão por 0')
except IndexError:
print('Erro ao acessar um indice inválido da lista')
from datetime import date, time, datetime
def trabalhando_com_datetime():
data_atual = datetime.now()
data_atual_formatada = data_atual.strftime('%d/%m/%Y %H:%M:%S')
print(data_atual.minute)
print(data_atual.weekday())
tupla = ('Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sabado', 'Domingo')
print(tupla[data_atual.weekday()])
data_criada = datetime(2020, 6, 22, 15, 30, 20)
import shutil
def escrever_arquivo(texto):
arquivo = open('contatos.txt', 'w')
arquivo.write(texto)
arquivo.close()
def atualizar_arquivo(nome_arquivo, texto):
arquivo = open(nome_arquivo, 'a')
arquivo.write(texto)
@allonsmandy
allonsmandy / lambda.py
Created August 30, 2020 19:09
lambda functions python
calculadora = {
'soma': lambda a, b: a + b,
'subtracao': lambda a, b: a - b,
'multiplicacao': lambda a, b: a * b,
'divisao': lambda a, b: a / b
}
soma = calculadora['soma']
print('A soma é: {}'.format(soma(10, 5)))
@allonsmandy
allonsmandy / index.js
Created July 27, 2020 05:13
composiçao
function composicao(...funcoes) {
return function(valor) {
return funcoes.reduce((acc, fn) => {
return fn(acc)
}, valor)
}
}
@allonsmandy
allonsmandy / index.js
Created April 21, 2020 18:30
clean code javascript deep nesting
const exampleArray = [ [ [ 'value' ] ] ]
// bad
exampleArray.forEach((array1) => {
array1.forEach((array2) => {
array2.forEach((el) => {
console.log(el)
})
})
})
@allonsmandy
allonsmandy / main.js
Created September 22, 2019 11:51
axios github
import axios from 'axios';
class Api {
static async getUserInfo(username) {
try {
const response = await axios.get(`https://api.github.com/users/${username}`);
console.log(response);
} catch {
console.warn('erro na api');
}
@allonsmandy
allonsmandy / .babelrc
Created September 22, 2019 11:45
configs {babel, webpack, package.json } async await, etc
{
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-async-to-generator"
]
}
@allonsmandy
allonsmandy / React.md
Created September 22, 2019 08:29 — forked from taniarascia/React.md
React notes

React Notes

  • A React component can only return one parent element.
return <h1>Hello</h1><p>World</p>            // error
return <div><h1>Hello</h1><p>World</p></div> // okay 
  • JavaScript expressions can be interpolated in JSX with {}