Skip to content

Instantly share code, notes, and snippets.

@joncasey
joncasey / polyfill.js
Created July 15, 2017 00:20
Polyfill with a Promise
function polyfill (feature, url) {
return new Promise(function (resolve, reject) {
if (!!feature) return resolve(feature)
var el = document.createElement('script')
el.async = el.defer = true
el.src = url
el.onload = function () { resolve(url) }
el.onerror = function (e) { reject(e) }
document.head.appendChild(el)
})
@joncasey
joncasey / CracklePop.js
Created April 12, 2015 02:22
Apply to Recurse Center (formerly known as Hacker School)
for (var i = 1, l = 100; i <= l; i++) {
var s = ''
if (i % 3 === 0) s += 'Crackle'
if (i % 5 === 0) s += 'Pop'
console.log(s || i)
}
@joncasey
joncasey / snippet_html5-elements.js
Created April 12, 2015 02:08
Scrape HTML spec for list of elements
// http://www.w3.org/html/wg/drafts/html/master/index.html#elements-1
// http://www.w3.org/TR/html/index.html#elements-1
var events = document.querySelector('table#ix-event-handlers').tBodies[0].rows
var elements = document.querySelector('table').tBodies[0].rows
var spec = {}
Array.prototype.forEach.call(elements, function (tr) {
var tags = tr.cells[0].textContent.replace(/\s/g, '').split(',')
var attr = tr.cells[5].textContent.replace(/\s/g, '').trim().replace(/globals;?/, '').replace(/;/g, ' ')
@joncasey
joncasey / snippet_GwG List.js
Created April 12, 2015 02:06
Convert Games with Gold list to JSON
// http://en.wikipedia.org/wiki/List_of_Games_with_Gold_games
// http://www.tekrevue.com/complete-xbox-games-with-gold-list-details/
var tables = document.querySelectorAll('table.wikitable')
var data = {
xbox360: tabular(tables[0]),
xboxOne: tabular(tables[1])
}
var prettyData = JSON.stringify(data, 0, 2)
@joncasey
joncasey / r.html
Created January 9, 2015 04:44
Reddit Viewer with JSONP
<!doctype html>
<html>
<head>
<title>/r/</title>
<style>
body {
cursor: default;
font-family: Calibri;
font-size: 140%;
@joncasey
joncasey / getScript.js
Created October 18, 2013 23:49
Quick/Dirty way to read in a file using Windows Script Host.
function getScript(s) {with(new ActiveXObject('microsoft.xmlhttp'))open('GET',s,!1),send(),s=responseText;return s}
eval(getScript('i:/love/dirty_girls'))