Skip to content

Instantly share code, notes, and snippets.

View theuves's full-sized avatar

Matheus Alves theuves

View GitHub Profile
function filterObj(obj, cb) {
const newObj = {};
const entries = Object.entries(obj);
for (entry of entries) {
const [key, val] = entry;
if (cb(key)) {
newObj[key] = val;
}
┌────────────────────────────┐
│ x × (lMax - lMin)          │
│ ─────────────────── + lMin │
│     gMax - gMin            │
├────────────────────────────┴──┐
│ x    → Valor para comparação. │
│ lMax → Máximo do menor.       │
│ lMin → Mínimo do menor.       │
│ gMax → Máximo do maior. │
@theuves
theuves / hex2rgb.js
Created March 5, 2019 16:35
Gambiarra interessante para converter cor hexadecimal para RGB.
const hex2rgb = colorHex => eval(colorHex.replace(/^#?(.{2})(.{2})(.{2})$/, '({r:0x$1,g:0x$2,b:0x$3})'))
@theuves
theuves / hex2rgb.js
Created March 5, 2019 16:18
Convert hex color to RGB.
const hex2rgb = (colorHex) => colorHex
.match(/(.{2})(.{2})(.{2})/)
.slice(1)
.map((hexVal) => parseInt(hexVal, 16))
///
// Algorítmos: Pragramando em JavaScript na língua portuguesa.
//
programa('Verificador de Maioridade', ($) => {
var nome = 'Matheus'
var idade = 19
$.se(nome >= 18).então(() => {
$.escreva(nome, 'é maior de idade.')
@theuves
theuves / Link.js
Created February 26, 2019 19:46
A component to use internal and external links with Gatsby.
@theuves
theuves / md.css
Created February 26, 2019 15:40
Um CSS para estilizar artigos --- normalmente convertidos de markdown.
.md {
line-height: 180%;
font-size: 16px;
font-family: Helvetica, Arial, sans-serif;
}
.md * {
box-sizing: border-box;
}
@theuves
theuves / Ideia.js
Created February 25, 2019 17:27
Rascunho aleatório acerca da análise de uma frase.
[ 'Todo', 'professor', 'tem', 'vários', 'alunos', '.' ]
[
{
valor: 'Todo',
cru: 'todo',
tipo: 'quantidade',
formula: (x) => x === x
},
{
@theuves
theuves / gamp
Created February 16, 2019 14:09
GIT: Add, commit and push in a single command.
#!/usr/bin/env bash
# gamp
#
# GIT: Add, commit and push in a single command.
#
# Created on: 2019-02-16
# Author: Matheus Alves <[email protected]>
# License: MIT
@theuves
theuves / filterProps.js
Created February 6, 2019 14:01
FIlter properties of an object.
function filterProps(obj, props) {
var newObj = {}
var keys = Object.keys(obj);
for (var i in keys) {
var key = keys[i]
if (props.includes(key)) {
newObj[key] = obj[key]
}