Skip to content

Instantly share code, notes, and snippets.

View andrescabana86's full-sized avatar

Andres Cabana andrescabana86

  • Freelance
  • Cordoba, Argentina
View GitHub Profile
from collections import deque
def compare(a, b):
return -1
def sort_horizontal_axis(matrix):
result = sorted(matrix, lambda a,b : -1)
return result
def sort_horizontal_axis_lambda(matrix):
@andrescabana86
andrescabana86 / fibonacci_secuence_optimized.py
Last active January 31, 2019 22:06
This is the formula I followed up -> Fn = {[(√5 + 1)/2] ^ n} / √5
import math
def fib(n):
return int(round(pow(((1 + math.sqrt(5)) / 2), n) / math.sqrt(5)))
# complexity O(n)
# space O(n)
@andrescabana86
andrescabana86 / pwer-of-two.js
Last active April 23, 2018 00:17
This function returns "true" if the number is power of 2, if not, returns the previous number power of two.
function checkIfIsPowerOfTwoOrReturnPrevious(number) {
var previousNumber = number
number = number | (number >> 1);
number = number | (number >> 2);
number = number | (number >> 4);
number = number | (number >> 8);
number = number | (number >> 16);
var result = number - (number >> 1);
if (result === previousNumber) {
result = true
@andrescabana86
andrescabana86 / pure.js
Created April 8, 2017 00:11
Pure functions examples
/*
pure functions are those that:
- are syncronous
- same input returns same output
- do not have collateral damage (change values from different scopes)
*/
//Examples of pure functions
function (a, b) {
@andrescabana86
andrescabana86 / multiple-route-map.js
Created March 9, 2017 16:51
Create multiple routes in a map
var location1 = new google.maps.LatLng(34.04429454929703, -118.22793351693724);
var location2 = new google.maps.LatLng(33.688522885631706, -116.15151750131224);
var location3 = new google.maps.LatLng(32.69561555501597, -117.06338273568724);
var location4 = new google.maps.LatLng(34.525395303965354, -117.27212297006224);
var map;
var mapOptions = { center: new google.maps.LatLng(42.5584308, -70.8597732), zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP };
@andrescabana86
andrescabana86 / context-this.js
Created February 10, 2017 05:21
Context "this" in EMAC2015
//exec with node.js
this.me = 'context file:';
var names = ["José", "Alfredo", "Ernesto"];
var person = {
me: 'context person:',
greet: function () {
names.forEach(function (name) {
console.log(this.me, 'saying hello to', name); // this print: undefined saying hello to ${name}
});
@andrescabana86
andrescabana86 / commonFactorInArray.js
Created February 6, 2017 20:40
Verify if number is a common factor of an array of Numbers
function isCommonFactorOf(arrayOfNumbers, factor) {
var numbers = arrayOfNumbers;
var length = numbers.length;
var minor = 0;
for (let i=0; i < length; i++) {
let number = numbers[i];
if (i===0 || number < minor) {
minor = number;
if (factor > minor) {
@andrescabana86
andrescabana86 / arrayFactors.js
Last active February 6, 2017 20:30
Get common factors of an array of numbers
function getCommonFactorsOf(arrayOfNumbers) {
var numbers = arrayOfNumbers;
var length = numbers.length;
var minor = 0;
for (let i=0; i < length; i++) {
let number = numbers[i];
if (i===0 || number < minor) {
minor = number;
}
@andrescabana86
andrescabana86 / factors.js
Last active February 6, 2017 20:06
All factors of a number O( log(n/2) ) Raw
function getFactorsOf(number) {
var factors = [];
var factor = 1;
var stopped = false;
while (stopped != true) {
if (number % factor === 0) {
let a = number / factor;
let b = factor;