Skip to content

Instantly share code, notes, and snippets.

View nitely's full-sized avatar
🟢
online

Esteban C Borsani nitely

🟢
online
View GitHub Profile
"use latest";
var Promise = require("[email protected]");
var request = Promise.promisifyAll(require("[email protected]"));
var validator = require('[email protected]');
const SLACK_WEBHOOK_URL = "https://hooks.slack.com/services/T00000000/B00000000/X00000000000000000";
@nitely
nitely / python_list_bench.py
Last active August 21, 2016 14:20
Slow lists, Fast list (python 3)
import timeit
INNER_ITERATIONS = 10000
TIMEIT_ITERATIONS = 5000
def func():
return [x for x in range(INNER_ITERATIONS)]
@nitely
nitely / hackealo.py
Created September 1, 2016 04:11
Hekealo.co challenge
# -*- coding: utf-8 -*-
"""
A pretty lame test from:
http://hackealo.co/
El instituto geográfico nacional se encarga de, periódicamente,
tomar fotografías aéreas para detectar cambios en el relieve terrestre.
Para agilizar esta tarea desean tener una herramienta que, dada una imagen tomada,
@nitely
nitely / constraint.py
Created September 14, 2016 19:05
Unremovable assert
# Assertions can be removed by command flags,
# this can not
class ConstraintError(AssertionError):
""""""
def constraint(condition, message=''):
"""
Usage::
@nitely
nitely / sqrt.js
Last active May 2, 2023 18:37
Square root (sqrt) in JavaScript using a binary search
/*
sqrt(8)
(0 + 8) / 2 = 4
4 * 4 = 16
(0 + 4) / 2 = 2
2 * 2 = 4
(2 + 4) / 2 = 3
3 * 3 = 9
@nitely
nitely / flatten.js
Last active May 13, 2023 17:07
Flatten array in JavaScript
// Space complexity: O(n)
// Time complexity: O(n) where n includes nested elements
function flatten(arr) {
return arr.reduce((acc, elem) => {
if (Array.isArray(elem))
acc.push(...flatten(elem));
else
acc.push(elem);
@nitely
nitely / fb.screener.js
Last active March 9, 2017 00:22
Lame JS puzzle #1
/*
We have an array of objects A and an array of indexes B. Reorder objects in array A with given indexes in array B. Do not change array A's length.
example:
var A = [C, D, E, F, G];
var B = [3, 0, 4, 1, 2];
sort(A, B);
@nitely
nitely / fb_debounce.js
Created March 9, 2017 14:48
Lame JS puzzle #2 debounce requests
/*
If you were building a search tool and wanted search results to pop up as you
typed but the server call was taxing, write a function that gets called on every
key down but calls the server when the user stops typing for 400ms.
*/
// <input type="text" class="js-search">
// Why a IIFE? coz I don't feel like polluting the global scope with crap [happy face]
(() => {
@nitely
nitely / fb_find_me_a_node.js
Created March 9, 2017 19:38
Lame JS puzzle #3
/*
This is just a BFS. It only works if the node to find is unique (ie: has an ID)
*/
function findNode(curr, node) {
if (curr == null)
return;
if (curr.isEqualNode(node))
@nitely
nitely / fb.js
Last active March 10, 2017 18:35
Lame JS puzzle #4
/*
Translate roman numbers to decimals. If a roman letter/number is lesser than the next one substract, otherwise add.
*/
// Time-Complexity = O(n)
// Space-Complexity = O(1)
const Romans = {
I: 1,
V: 5,