Skip to content

Instantly share code, notes, and snippets.

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

Jean Carlo Nascimento suissa

🏠
Working from home
  • Suissa Corp
  • Brasil
View GitHub Profile
@suissa
suissa / rich-already-answered-that.md
Created February 16, 2018 05:53 — forked from reborg/rich-already-answered-that.md
Clojure Design Decisions

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats. The link points back at them.

Index:

@suissa
suissa / pure.js
Created November 20, 2017 17:51
JavaScript Pure
const { log } = console;
/*
* Aritmética: equal, max, min, negative, positive, reverseSign, opositeSigns
* swap, def, undef, plus, minus, sum
*/
const equal = function( x, y ) {
return ( x === y );
};
@suissa
suissa / compose.js
Created October 21, 2017 02:03 — forked from WaldoJeffers/compose.js
JavaScript one-line compose (ES6)
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)))
// Usage : compose functions right to left
// compose(minus8, add10, multiply10)(4) === 42
//
// The resulting function can accept as many arguments as the first function does
// compose(add2, multiply)(4, 10) === 42
@suissa
suissa / comoSerChatoNowhatsapp.js
Created October 19, 2017 08:10 — forked from callmeloureiro/comoSerChatoNoWhatsapp.js
Como fazer alguém te responder no whatsapp
/*
Hoje iremos MUDAR a vida da pessoa que não te responde no whatsappp...
Que tal enviar mensagens pra ela até obter uma resposta?!
Sensacional não acha?! Mas, somos devs, correto?! Então vamos automatizar esse paranauê!
Para utilizar:
- Abra o web.whatsapp.com;
- Selecione a conversa que você quer;
- Abra o console e cole o código que está no gist;
const crypto = require('../../helpers/crypto')
const Errors = require('../../errors/sistem/pt-br')
const Validate = require('../../helpers/validate')
const authenticate = (User, Validate, Business, Errors) => (req, res, next) => {
const exclude = ['password',
'created_at',
'updated_at',
@suissa
suissa / comp.js
Last active October 15, 2017 08:53
Demonstrando o poder da composição com fold
const def = ( x ) => typeof x !== 'undefined'
const identityFn = ( x ) => x
const compose = ( f, g ) => ( x ) => f( g( x ) )
const fold = ( fn, acc, [ x, ...xs ] ) =>
def( x ) && fold( fn, fn( acc, x ), xs ) || acc
const addOne = ( x ) => x + 1
const timesTwo = ( x ) => x * 2
const addThree = ( x ) => x + 3
@suissa
suissa / add&prod.js
Created October 11, 2017 04:13
Adição e Produto por axioma de peano
const sucessor = x => x + 1;
const predecessor = x => x - 1;
// 1. P(a, 0) = a
// 2. P(a,S(b)) = S(P(a, b))
const adicaoPeano = ( a, b ) =>
( a === 0 )
? b
: adicaoPeano( predecessor( a ), sucessor( b ) );
@suissa
suissa / memorizador.js
Last active October 5, 2017 01:59
Memoized pattern
const memoize = ( fn ) => {
const cache = {}
return function mfn () {
const args = [].slice.call( arguments )
const key = JSON.stringify( args )
return key in cache
? cache[ key ]
: cache[ key ] = fn.apply( this, args )
@suissa
suissa / utils.js
Created October 3, 2017 17:15
Funções Uteis (só one-liners)
const fact = n => n && n * fact(n-1) || 1;
const decToBin = dec => dec && dec % 2 + 10 * decToBin(0 | dec / 2) || 0;
const iif = pr => t => f => x => pr(x) ? t(x) : f(x);
const not = fn => x => !fn(x);
const or = pra => prb => x => pra(x) || prb(x);
const isArray = x => x instanceof Array;
const isPromise = x => x instanceof Promise;
const isPlainObject = x => typeof x === 'object' && x !== null && x == '[object Object]';
const isTraversable = or(isPlainObject)(isArray);
const keys = Object.keys.bind(Object);
@suissa
suissa / stream.js
Created October 2, 2017 23:55
Gerenciando estruturas infinitas com Streams - Prog. Funcional de verdade com JS
// A definição de um stream se dá inicio com o uso do construtor [Stream]
// que recebe como único parâmento uma fonte que é o gerador.
// Por meio de técnicas compositivas fluídas é que se define uma cadeia
// de composição funcional. As operações de composição são [map]
// [reduce] e [filter], versão unitária das funções sobre vetores
// e [skip] e [take] que permite saltar ou recoletar n elementos
// que passam pela cadeia de composição.
// Fonts:
// https://sites.ualberta.ca/~jhoover/325/CourseNotes/section/Streams.htm
// http://blog.jeremyfairbank.com/javascript/functional-javascript-streams-2/