Skip to content

Instantly share code, notes, and snippets.

View hamg26's full-sized avatar

Hansel Abraham Mendoza García hamg26

View GitHub Profile
@hamg26
hamg26 / rng-coinFlip.js
Last active May 20, 2019 04:44
You are provided this flip function: function flip() { return Math.random() >= 0.5; }. You must implement a randomNumber(n) function that generates a random number greater than or equal to 0, and less than input n. n must be greater than 0. n must be less than 1,000,000. Your only source of randomness must be the provided flip() function. You ca…
function flip() {
return Math.random() >= 0.5;
}
function randomNumber(n) {
if(n === undefined) throw new Error("n is required");
if(n <= 0) throw new Error("n must be greater than 0");
if(n > 1000000) throw new Error("n must be lower than 1,000,000");
// No need to further calculations
@hamg26
hamg26 / countdown.html
Created February 1, 2018 15:01
Create a simple countdown timer. The countdown should update every second. You may use any JS framework or no framework at all. Please write CSS without a framework
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#clockdiv{
width: 100%;
font-family: sans-serif;
display: inline-block;
//example data
db.venues.insert( {
name: "Central Park",
location: { type: "Point", coordinates: [ -73.97, 40.77 ] },
category: "Parks"
} );
db.venues.insert( {
name: "Sara D. Roosevelt Park",
location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] },
category: "Parks"
// Really cool conferences here:
// https://www.youtube.com/watch?v=8aGhZQkoFbQ
// https://www.youtube.com/watch?v=cCOL7MC4Pl0
/*********
1
*********/
for ( var i = 0; i < 3; i++) {
setTimeout( function() { console.log(i); }, i * 1000 );
}
/*********
1
*********/
var a = 12;
var superFunction = function () {
console.log(a);
var a = 80;
};
superFunction ();
@hamg26
hamg26 / banana.js
Created August 14, 2019 17:13
Javascript string concatenations
('b' + 'a' + + 'a' + 'a').toLowerCase(); // should print "banana"
('' + + ''); // should print "0"
@hamg26
hamg26 / rate_limited_api.js
Created January 4, 2022 22:32
Rate limited API consumption (FIFO)
const https = require('https')
const HOST = "";
const PATH = ""
const TOKEN = ""
const RATE_LMIT = 10;
const RATE_INTERVAL = 1000; //ms
const post = (phone, code) => new Promise((resolve, reject) => {