Skip to content

Instantly share code, notes, and snippets.

View armand1m's full-sized avatar

Armando Magalhães armand1m

View GitHub Profile
{
"rules": {
".read": "auth.uid !== null && auth.provider === 'google'",
".write": "auth.uid !== null && auth.provider === 'google'"
}
}
@armand1m
armand1m / CreditCardDetector.js
Created November 5, 2018 11:20
CreditCardDetector.js extracted from Cleave.js code
'use strict';
var CreditCardDetector = {
blocks: {
uatp: [4, 5, 6],
amex: [4, 6, 5],
diners: [4, 6, 4],
discover: [4, 4, 4, 4],
mastercard: [4, 4, 4, 4],
dankort: [4, 4, 4, 4],
@armand1m
armand1m / results-first-page.txt
Last active February 21, 2019 16:09
Table of reimbursements higher than 1000 BRL for BOLSONARO family. Exactly 1082 reimbursements higher than 1000 BRL.
┌──────────┬──────────────────────────┬──────────────────────────────────────────────────────────────┬────────────┬─────────┬─────────────────────────────────────────────────────────────────────────────────┐
│ Position │ Name │ What for │ Date │ Price │ Receipt │
├──────────┼──────────────────────────┼──────────────────────────────────────────────────────────────┼────────────┼─────────┼─────────────────────────────────────────────────────────────────────────────────┤
│ 16 │ EDUARDO BOLSONARO │ Maintenance of office supporting parliamentary activity │ 2018-08-02 │ 4200 │ http://www.camara.gov.br/cota-parlamentar/documentos/publ/2907/2018/6649961.pdf │
├──────────┼──────────────────────────┼──────────────────────────────────────────────────────────────┼────────────┼─────────┼───────────────────────────────────────────────────────────────────
@armand1m
armand1m / setupTests.js
Created August 5, 2018 20:22
My usual jest setup file
/**
* prepareDom method
*
* just creates the DOM structure needed to render
* this application before running tests.
*
* it is needed to test the `index.js` file of the project.
*/
(function prepareDom() {
document.body.innerHTML = '<div id="root"></div>';
@armand1m
armand1m / setupTests.js
Created June 6, 2018 00:09
CRA Jest setup tests file with window.mediaMatch a simple mock
/**
* window.matchMedia mock
*
* it also exposes a custom global method called setMatchMediaProperties
* that accepts an object as parameter to merge with the default MatchMedia properties.
*/
(function matchMediaMock() {
const defaultMatchMedia = {
matches: false,
addListener() {},
@armand1m
armand1m / jsconfig.json
Created April 29, 2018 12:31
VSCode Intellisense for Javascript projects with Module path alias
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"paths": {
"Api/*": ["./src/api/*"],
"Components/*": ["./src/components/*"]
}
@armand1m
armand1m / paginate.js
Last active March 4, 2018 23:13
simple and naive js object pagination implementation
const paginate = (array, pageSize) => {
const numberOfPages = Math.round(array.length / pageSize);
const needsOneMorePage = array.length % pageSize;
const totalNumberOfPages = needsOneMorePage
? numberOfPages + 1
: numberOfPages;
const iterableNumberOfPages = [
...Array(totalNumberOfPages).keys()
@armand1m
armand1m / .emscripten
Created November 19, 2017 16:39
Fix emscripten LLVM problems
# Replace the path for LLVM and Emscripten for these:
EMSCRIPTEN_ROOT = os.path.expanduser(
os.getenv('EMSCRIPTEN') or
'/usr/local/opt/emscripten/libexec')
LLVM_ROOT = os.path.expanduser(
os.getenv('LLVM') or
'/usr/local/opt/emscripten/libexec/llvm/bin')
@armand1m
armand1m / withInitialData.js
Created November 15, 2017 22:38
Simple HOC for fetching data that is compatible with the SSR technique described by @BenLu here: https://medium.com/@benlu/ssr-with-create-react-app-v2-1-ee83fb767327
import React, { Component } from 'react';
const hasDataForThisKey = (staticContext) =>
(key) => staticContext && Object.keys(staticContext.data).includes(key);
const windowHasDataForThisKey = (window) =>
(key) => Object.keys(window.__DATA__).includes(key);
export default ({
key,
@armand1m
armand1m / login-npm-registry.sh
Created November 5, 2017 23:55
Login NPM Registry (useful for getting a token without having to `npm login`)
curl -s \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X PUT --data '{ "name": "username_user", "password": "password_here" }' \
https://registry.npmjs.org/-/user/org.couchdb.user:username_user