Skip to content

Instantly share code, notes, and snippets.

View edrdesigner's full-sized avatar

Eduardo Reichert edrdesigner

View GitHub Profile
/**
In a game, there is a string, direction, of length n that consists of characters
L and R.
L denotes left. R denotes right, and there is a line segment of
length 2" that extends from [0, 2"], a player takes n turns.
In the th turn,
• The player places the number i at the center of the current line segment.
• If direction[i] = L; the player proceeds in the left direction, eliminating the right half of the current line segment,
and vice versa for direction[i] = 'R'.
Following this rule, find the final order of numbers on the line segment,
static getUniqueArrayListBy(arr, key) {
return [...new Map(arr.map((item) => [item[key], item])).values()];
}
@edrdesigner
edrdesigner / binary-search.js
Created March 23, 2022 16:12
Binary search algorithm
const arr = ['a','b', 'c', 'd','x', 'y', 'z'];
function findMe(target, start, end) {
if (start > end) return 'not found';
const middle = Math.floor((start+end)/2);
if (arr[middle] === target) {
return `found it at index ${middle}`;
}
@edrdesigner
edrdesigner / Adonis-ACL.md
Created March 10, 2022 21:37 — forked from maykbrito/Adonis-ACL.md
Basic step-by-step to use ACL in AdonisJS

Install

adonis install adonis-acl

Config

app.js

// Javascript one-liner to calculate total minesweeper neighbours
// Polyfill for ECMA 2019
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
if (!Array.prototype.flat) {
Array.prototype.flat = function () {
return this.reduce((acc, val) => acc.concat(val), []);
}
}
export default function flatten(arr) {
return arr.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
// Test
flatten([[1,2,[3]],4]);
@edrdesigner
edrdesigner / media-query.css
Created August 12, 2019 11:36 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@edrdesigner
edrdesigner / nginx_config_deploy
Created June 23, 2019 19:17
Nginx config para react deploy
## cmd vim /etc/nginx/sites-available/default
upstream node {
server 127.0.0.1:8080;
keepalive 64;
}
server {
listen 80;
# server_name domain.com;
@edrdesigner
edrdesigner / radioTabbable.ng.js
Created April 5, 2019 14:03 — forked from jonathanconway/radioTabbable.ng.js
Angular Directive that makes individual radio-buttons focusable using the keyboard only. (Useful for accessibility, on a case-by-case basis.)
/**
* @ngdoc directive
* @name radioTabbable
* @requires none
* @description
* Makes individual radio buttons focuseable using the TAB key.
* (By default, pressing TAB while on a radio button would have shifted focus to the next control outside of the radio group.)
* @usage
* <input type="radio" name="radioGroup" value="0" radio-tabbable="" />
* <input type="radio" name="radioGroup" value="1" radio-tabbable="" />
@edrdesigner
edrdesigner / robots.txt
Created November 7, 2018 13:19 — forked from petskratt/robots.txt
Magento robots.txt
# robots.txt for Magento 1.9.x / v1.6 2018-08-19 / Peeter Marvet
# (original version from 2015, edited in 2017 to add filter query parameter disallow samples + some wildcards,
# edited in 2018 to add query params blocking to Yandex as named User-agent does not read *)
# based on:
# http://inchoo.net/ecommerce/ultimate-magento-robots-txt-file-examples/
# http://www.byte.nl/blog/magento-robots-txt/
# https://astrio.net/blog/optimize-robots-txt-for-magento/
#
# comment and clone at https://gist.github.com/petskratt/016c9dbf159a81b9d6aa
# Keep in mind that by standard robots.txt should NOT contain empty lines, except between UA blocks!