Skip to content

Instantly share code, notes, and snippets.

View ronaiza-cardoso's full-sized avatar
🏳️‍🌈

Ronaiza Cardoso ronaiza-cardoso

🏳️‍🌈
View GitHub Profile
@justindmyers
justindmyers / server.js
Created January 17, 2016 12:13
https with Ionic
var fs = require('fs');
var httpProxy = require('http-proxy');
var http = require('http');
var https = require('https');
var express = require('express');
var app = express();
app.use(function (req, res, next) {
console.log(req);
if (req.url === '/') {
import {Directive, Attribute} from '@angular/core';
import {NgModel} from '@angular/common';
@Directive({
selector: '[mask]',
host: {
'(keyup)': 'onInputChange()'
}
})
export class Mask {
maskPattern: string;
@0x1ad2
0x1ad2 / tabs.service.ts
Last active January 15, 2019 00:06
A service to hide and show tabs in Ionic 2
import {Injectable} from '@angular/core';
// Declare TabsService as a provider in app.module.ts
// Inject TabsService in your class: constructor(public tabs: TabsService){}
// Use the this.tabs.hide() or this.tabs.show() methods wherever you want
@Injectable()
export class TabsService {
constructor() {}
public hide() {
@vinicius73
vinicius73 / problema.md
Last active December 14, 2017 19:36
Um exercício simples com js

Default true

Existem 3 entradas possiveis

  • true
  • false
  • undefined

as saídas serão:

  • undefinded => true
@lubien
lubien / desafio.js
Last active August 4, 2019 03:23
Dado o array de dictionary abaixo some o total dos valores (https://gist.github.com/anabastos/fbdfef7fcc64105e76e5e26218ebf7e6)
const
composeN = (...fs) => x =>
fs.reduceRight((x, f) => f(x), x)
, map = f => xs =>
xs.map(f)
, reduce = f => xs =>
xs.reduce(f)
/**
* Show Me the Evens - Show me the Odds
* Diana is learning to count and she just learned the difference between odds and even numbers.
* She wants to have some fun, so she picks a random number.
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input.
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input.
**/
const counting = (x) => {
return arrayFrom(x)
@anabastos
anabastos / criaArrayPrimos.js
Last active January 7, 2020 00:16
Dado um número aleatório, retornar todos os números PRIMOS entre 0 e o número escolhido
const criaArrayPrimos = x =>
criaArray(x)
.slice(2)
.filter(checaFatores)
const criaArray = tamanho => Array.from({ length: tamanho }, (el, index) => index)
const checaFatores = n =>
criaArray(maiorDivisor(n))
.slice(2)
const matrix = [[2,4,6,8],[12,14,16,18],[20,24,28,32],[32,34,36,38],[42,44,46,48]];
const exp = matrix[0];
const arrNumbers = matrix.slice(1);
const props = [
(number, _i) => (number * exp[_i]),
(number, _i) => (number / exp[_i]),
(number, _i) => (number - exp[_i]),
(number, _i) => (number + exp[_i])
];
const op = (arr, _i) => arr.map(_a => props[_i](_a, _i));

Recuperar todos os valores do objeto

Tive uma situação em que precisei recuperar todos os valores de um objeto, mas esse objeto tinha vários níveis.

O que fiz então foi, criar uma recursividade, verificando cada nó do objeto, se o nó fosse o tipo Object, como quase tudo no JS é, a função é novamente chamada entrando em um loop até que todos os nós fossem processados e seus valores armazenados.

O reduce permite um valor inicial, então usando o concat e o valor inicial como um array vazio