Skip to content

Instantly share code, notes, and snippets.

View wesbos's full-sized avatar
🔥
SLAYING BUGS

Wes Bos wesbos

🔥
SLAYING BUGS
View GitHub Profile
// get an array of all the keys on the window
const dirty = Object.keys(window);
// Then create an iframe set to nothing
const iframe = document.createElement('iframe');
iframe.src = '';
// put it into the DOM
document.body.append(iframe);
/* eslint-disable */
String.prototype.sarcastic = function() {
return [...this]
.map((char, i) => char[`to${i % 2 ? 'Upper' : 'Lower'}Case`]())
.join('');
};
# Uses tree - install first:
# brew install tree
function t() {
# Defaults to 3 levels deep, do more with `t 5` or `t 1`
# pass additional args after
tree -I '.git|node_modules|bower_components|.DS_Store' --dirsfirst --filelimit 15 -L ${1:-3} -aC $2
}
// this is a big array of 76 items I need to split into groups of 10
const hugeArray = Array.from({ length: 76 }, (_, i) => i);
function chunkify(array, chunkSize = 10) {
// make a new array
const chunks = Array.from(
// give it however many slots are needed - in our case 8
// 1-7 with 10 items, and 8th slot will have 6
{ length: Math.ceil(array.length / chunkSize) },
// this is a map function that will fill up our slots
@wesbos
wesbos / some-text.html
Created April 5, 2019 13:32
cool headings
<h1>Cool text</h1>
@wesbos
wesbos / facebookScrape.js
Created January 25, 2019 20:30
marketplace
require('isomorphic-fetch');
async function go(params) {
const variables = {
params: {
bqf: { callsite: 'COMMERCE_MKTPLACE_WWW', query: 'iphone' },
browse_request_params: {
// burlington
filter_location_id: '108043585884666',
// hamilton
{
"window.zoomLevel": -1,
"editor.fontFamily": "Operator Mono, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 29,
"editor.lineHeight": 40,
"editor.letterSpacing": 0.5,
"workbench.editor.tabSizing": "shrink",
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"html.format.enable": true,
@wesbos
wesbos / index.html
Created October 4, 2017 17:28
ios 11 compatible getUserMedia
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
const countryCodes = {
US: 'United States',
CA: 'Canada',
NG: 'Nigeria',
GB: 'United Kingdom',
};
const sales = [
{ code: 'US', count: 233 },
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}