Skip to content

Instantly share code, notes, and snippets.

Avatar

Renato Cassino tacnoman

View GitHub Profile
@tacnoman
tacnoman / abnt2.sh
Created Apr 17, 2020
Teclado americano com acentos em português no Linux
View abnt2.sh
# ´a ´c ~a
setxkbmap -model abnt2 -layout us -variant intl
# á ç ã
@tacnoman
tacnoman / CrawlAirbnb.js
Created Feb 4, 2020
Crawl Airbnb example
View CrawlAirbnb.js
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 = {
View .tmux.conf
set -g terminal-overrides 'xterm:colors=88'
set -g default-terminal "screen-256color"
@tacnoman
tacnoman / 2048-moveLine.js
Last active Aug 11, 2018
2048-moveLineUp.js
View 2048-moveLine.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]);
}
@tacnoman
tacnoman / 2048-generateArrayPad.js
Last active Aug 11, 2018
2048-generateArrayPad.js
View 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));
@tacnoman
tacnoman / 2048-moveUpTry3.js
Last active Aug 11, 2018
2048-moveUpTry3.js
View 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
@tacnoman
tacnoman / 2048-moveUpTry2.js
Last active Aug 11, 2018
2048-moveUpTry2.js
View 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);
@tacnoman
tacnoman / 2048-moveUpRecursion.js
Last active Aug 11, 2018
2048-moveUpRecursion.js
View 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
@tacnoman
tacnoman / 2048-addNumberBenchmark.js
Created Aug 8, 2018
2048-addNumberBenchmark.js
View 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]),
View 2048-addNumber-01.js
const addNumber = (board, point, number=2) => {
return board.map( // Iterate over columns
(line, columnIdx) => line.map((block, lineIdx) => // Iterate over line
// If column and line index is equals, return 2, else return the number
columnIdx === point[0] && lineIdx === point[1] ? number : block
));
};