Skip to content

Instantly share code, notes, and snippets.

View bmorelli25's full-sized avatar
πŸ“š
Writing docs

Brandon Morelli bmorelli25

πŸ“š
Writing docs
View GitHub Profile
function speak() {
return function logIt() {
var words = 'hi';
console.log(words);
}
}
@bmorelli25
bmorelli25 / speak.js
Created July 6, 2017 14:30
closure 2
function speak() {
var words = 'hi';
return function logIt() {
console.log(words);
}
}
@bmorelli25
bmorelli25 / whoLikesWhat.js
Created July 6, 2017 14:57
closure example 2
function name(n) {
return function(a) {
return `${n} likes ${a}`;
};
}
const svgLocation = document.getElementsByClassName("linechart")[0].getBoundingClientRect();
const adjustment = (svgLocation.width - svgWidth) / 2; //takes padding into consideration
const relativeLoc = e.clientX - svgLocation.left - adjustment;
@bmorelli25
bmorelli25 / scrape.js
Created August 1, 2017 14:14
web scraping with Node.js Boilerplate
const rp = require('request-promise');
const cheerio = require('cheerio');
const options = {
uri: `https://www.google.com`,
transform: function (body) {
return cheerio.load(body);
}
};
rp(options)
@bmorelli25
bmorelli25 / binarySearch.js
Created August 1, 2017 17:50
Bitcoin Chart Binary Search
// d=data, t=target, s=start, e=end, m=middle
const binarySearch = (d, t, s, e) => {
const m = Math.floor((s + e)/2);
if (t == d[m].svgX) return d[m];
if (e β€” 1 === s) return Math.abs(d[s].svgX β€” t) > Math.abs(d[e].svgX β€” t) ? d[e] : d[s];
if (t > d[m].svgX) return binarySearch(d,t,m,e);
if (t < d[m].svgX) return binarySearch(d,t,s,m);
}
let closestPoint = binarySearch(data,target, 0, data.length-1)
@bmorelli25
bmorelli25 / padEnd.js
Created August 2, 2017 19:07
Object.entries() + padEnd() example
const data = {
Portland: '78/50',
Dublin: '88/52',
Lima: '58/40'
}
Object.entries(data).map(([city, temp]) => {
console.log(`City: ${city} Weather: ${temp}`)
});
@bmorelli25
bmorelli25 / padEnd.js
Created August 2, 2017 19:10
Object.entries() + padEnd() example
const data = {
Portland: '78/50',
Dublin: '88/52',
Lima: '58/40'
}
Object.entries(data).map(([city, temp]) => {
console.log(`City: ${city.padEnd(16)} Weather: ${temp}`)
});
@bmorelli25
bmorelli25 / puppeteer.js
Last active March 22, 2019 10:53
Screenshot with Puppeteer
const puppeteer = require('puppeteer');
async function getPic() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://google.com');
await page.screenshot({path: 'google.png'});
await browser.close();
}
@bmorelli25
bmorelli25 / test-final.js
Created October 9, 2017 18:05
Puppeteer Final Test
const puppeteer = require('puppeteer');
async function getPic() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://google.com');
await page.setViewport({width: 1000, height: 500})
await page.screenshot({path: 'google.png'});
await browser.close();