Skip to content

Instantly share code, notes, and snippets.

View TiagoNunesDeveloper's full-sized avatar

Tiago Nunes TiagoNunesDeveloper

  • Aracaju/Se - Brasil
View GitHub Profile
@TiagoNunesDeveloper
TiagoNunesDeveloper / app.js
Created March 22, 2017 18:24
Serie de validação..
function email(fieldValue){
let emailReg = /[^\s@]+@[^\s@]+\.[^\s@]+/
return emailReg.test(fielValue)
}
function url(fieldValue) {
var urlReg = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
return urlReg.test(fieldValue)
}
@TiagoNunesDeveloper
TiagoNunesDeveloper / Lifecycle.js
Created March 25, 2017 00:54
Lifecycle Page Ionic 2
ionViewCanEnter(): Promise<any> {
console.info('Agurdando 2 segundos....')
return new Promise((resolve, reject) => {
setTimeout(() => {
let number = Math.round(Math.randon() * 100)
number % 2 == 0 ? autorizado() : naoAutorizado()
}, 2000)
function autorizado(){
@TiagoNunesDeveloper
TiagoNunesDeveloper / reduce.js
Last active April 4, 2017 15:51
Array.prototype.reduce
// MAP
let numeros = [1,2,3,4,5,6,7,8,9]
let map = (func, lista) => lista.reduce((acc, x) => acc.concat(func(x)), [])
let inc = (x) => x + 1
map(inc, numeros) //=> [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
// FILTER
let filter = (func, lista) => lista.reduce((acc, x) => func(x) ? acc.concat(x): acc, [])
let odd = (x) => x % 2
filter(odd, numeros) //=> [ 1, 3, 5, 7, 9 ]
function criaIterador(array) {
let proximoIndice = 0
return {
next: () => {
return proximoIndice < array.length
? { value: array[proximoIndice++], done: false }
: { value: undefined, done: true }
}
}
}
@TiagoNunesDeveloper
TiagoNunesDeveloper / currying.js
Last active April 6, 2017 15:34
Essa técnica de preencher os primeiros argumentos de uma função (e de retornar uma nova função) normalmente é chamada de 'currying'. Que transforma uma função que recebe múltiplos parâmetros de forma que ela pode ser chamada como uma cadeia de funções que recebem um parâmetro cada.
Function.prototype.partial = function() {
var fn = this, args = Array.prototype.slice.call(arguments)
return function() {
var arg = 0
for(var i = 0; i < args.length && arg < arguments.length; i++ ) {
if (args[i] === undefined) {
args[i] = arguments[arg++]
}
}
return fn.apply(this, args)
@TiagoNunesDeveloper
TiagoNunesDeveloper / recursao.js
Created April 7, 2017 01:25
Recursão: Este conceito, também largamente utilizado na programação procedural, abre caminho para potencializar o uso de uma função. Com uma função que chama ela mesma em certas circunstâncias, criamos algoritmos capazes de percorrer estruturas aninhadas de arrays e objetos a fim de calcular valores, processar dados ou adaptar estas estruturas g…
//Regras --> Ela tem que chamar ela mesma. --> Tem que ter uma estratégia para parar a função.
const sum = (arr) => {
if(arr.length === 0){
return 0
}
return arr[0] + sum(arr.slice(1))
}
//Usando ES6
const sum = arr => {
@TiagoNunesDeveloper
TiagoNunesDeveloper / webComponents.js
Created April 7, 2017 19:37
Estudos sobre WebComponents.
(function () {
let template = `<style></style>
<div class="container">
<input type="text" data-js="inputTest"></input>
<p data-js="pTest"></p>
<button type='button'
uppercase="true"
attrBackground="red"
attrColor="#fff"
@TiagoNunesDeveloper
TiagoNunesDeveloper / README.md
Last active April 9, 2017 16:41
Front-end-Developer-Interview-Questions

####[⬆] Questões de JS:

  • Explique o evento delegation.

Resposta: " delegation" Ele defini um evento para um elemento pai, que será disparado para todos os seus filhos. Assim o evento vai funcionar para qualquer elemento filho que já existir e também para os que forem adicionados posteriormente na árvore do DOM.

  • Explique como this funciona em JavaScript.

Resposta: " this" Ele funciona como um objeto do contexto da função, aonde esse objeto aponta para uma instância da classe dentro da qual o método é definido.

  • Explique como funciona herança prototipada.
@TiagoNunesDeveloper
TiagoNunesDeveloper / ywcc_ptbr.py
Created April 21, 2017 03:55 — forked from ericoporto/ywcc_ptbr.py
Yahoo Weather API Condition Codes in Brazilian Portuguese (Códigos do Yahoo Weather em Português - Brasil)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2015 Erico Vieira Porto
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@TiagoNunesDeveloper
TiagoNunesDeveloper / app.js
Created October 6, 2017 14:22
concat filter
var arr1 = [1, 2, 3]
var arr2 = [1, 3, 5]
var arr3 = arr1.concat(arr2).filter(function (item, index, array) {
return array.indexOf(item) === index
})
console.log(arr3) // [1, 2, 3, 5]