Skip to content

Instantly share code, notes, and snippets.

View renatocassino's full-sized avatar

Renato Cassino renatocassino

View GitHub Profile
@renatocassino
renatocassino / docker-compose-graphite-statsd-grafana-loki.yml
Last active May 5, 2024 18:39
Docker compose to build graphite, statsd, grafana and Loki (logs)
version: '3'
services:
loki:
image: grafana/loki:2.0.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
promtail:
image: grafana/promtail:2.0.0
volumes:
@renatocassino
renatocassino / abnt2.sh
Created April 17, 2020 16:55
Teclado americano com acentos em português no Linux
# ´a ´c ~a
setxkbmap -model abnt2 -layout us -variant intl
# á ç ã
@renatocassino
renatocassino / CrawlAirbnb.js
Created February 4, 2020 17:57
Crawl Airbnb example
import axios from 'axios';
import cheerio from 'cheerio';
import logger from './lib/logger';
const BASE_URL = 'https://www.airbnb.com';
const URL = `${BASE_URL}/s/Miami--FL--United-States/homes`;
const CSS_QUERY = '._fhph4u ._8ssblpx';
const CSS_QUERY_PAGINATOR = 'nav[data-id="SearchResultsPagination"] > ul > li a[aria-label="Next"]';
const content = {
@renatocassino
renatocassino / .tmux.conf
Created December 6, 2019 20:54
Tmux config
set -g terminal-overrides 'xterm:colors=88'
set -g default-terminal "screen-256color"
@renatocassino
renatocassino / 2048-moveLine.js
Last active August 11, 2018 23:10
2048-moveLineUp.js
const moveLineUp = (line) => {
// Internal function to recursive
const moveLineUpInner = (currentLine, results=[]) => {
if (currentLine.length === 0) return results;
if(currentLine[0] === currentLine[1]) {
const total = currentLine[0] + currentLine[1];
return moveLineUpInner(currentLine.slice(2), [...results, total]);
}
@renatocassino
renatocassino / 2048-generateArrayPad.js
Last active August 11, 2018 23:14
2048-generateArrayPad.js
// Generate array with size
const generateArraySize = (size, defaultValue = 0) => Array.from({ length: size }, () => defaultValue);
// Function receive an array and the size
const arrayPad = (arr=[], size=4) => {
return [...arr, ...generateArraySize(size - arr.length)];
};
console.log(arrayPad([2,4,8], 4));
console.log(arrayPad([2], 4));
@renatocassino
renatocassino / 2048-moveUpTry3.js
Last active August 11, 2018 22:49
2048-moveUpTry3.js
/**
* @param line Array Old board array
*/
const moveLineUp = (line) => { // One uniq parameter
// Internal function to recursive
const moveLineUpInner = (counter, lineWithoutZeros, results=[]) => {
// now we have only a counter
if(counter === 0) return results; // If 0, return
if (lineWithoutZeros.length === 0) { // If all numbers different of 0 are empty
@renatocassino
renatocassino / 2048-moveUpTry2.js
Last active August 11, 2018 23:46
2048-moveUpTry2.js
/**
* @param line Array Old board array
* @param result New array with new state. Start empty
* @param lineWithoutZerosMemoized array list of numbers in line without 0
*/
const moveLineUp = (line, results=[], lineWithoutZerosMemoized=null) => {
// line is used like a counter to add in results
if(line.length === 0) return results; // If line is empty, get out recursion
const lineWithoutZeros = lineWithoutZerosMemoized || line.filter((n)=>n > 0);
@renatocassino
renatocassino / 2048-moveUpRecursion.js
Last active August 11, 2018 22:52
2048-moveUpRecursion.js
/**
* @param line Array Old board array
* @param result New array with new state. Start empty
* @param lineWithoutZerosMemoized array list of numbers in line without 0
*/
const moveLineUpFirst = (line, result=[], lineWithoutZerosMemoized=null) => {
const currentIndex = result.length; // The size of result is equals the line index
if(line.length === currentIndex) return result; // if result are full, return
const lineWithoutZeros = lineWithoutZerosMemoized || line.filter((n)=>n > 0); // In first iterate, set, in next iterates keep the value
@renatocassino
renatocassino / 2048-addNumberBenchmark.js
Created August 8, 2018 02:04
2048-addNumberBenchmark.js
// npm i --save benchmark
const Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
const addNumberFunc = (board, point, number=2)=>{
const line = board[point[0]];
return [
...board.slice(0, point[0]),
[
...line.slice(0, point[1]),