Want to fork your own gists? No fork button? No problem! Install this user script by clicking refork.user.js' "raw" link down below: ⇓
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Constructs a new function type from `F`, instead returning `R` */ | |
export type Returns<F, R> = F extends (...args: any[]) => infer _ | |
? (...args: Parameters<F>) => R | |
: never; | |
/** | |
* Given a (zero-indexed) positional argument number `n` | |
* and a function call signature generic type `F`, | |
* produce a well-typed function that selects that `n`th arg. | |
* @example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>HTML5 GPS</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<meta name="apple-mobile-web-app-status-bar-style" content="black"> | |
<link rel="stylesheet" href="style.css"> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<base href="https://www.timeanddate.com/date/workdays.html?d1=01&m1=05&y1=2018&d2=9&m2=7&y2=2018&"> | |
<title>Vacation Day Planner</title> | |
<script> | |
const sumUp = (td) => { const t = td.parentNode.parentNode, r = t.rows[t.rows.length-1], c = r.cells[r.cells.length-1]; c.textContent = Array.from(t.querySelectorAll('td')).filter(c => c.classList.contains('hl')).length; c.style.color = '#000'; } | |
document.onclick = (e) => { if (e.target.nodeName === 'TD') { const t = e.target, cl = t.classList; cl.contains('hl-b') || cl.contains('hl') ? cl.remove('hl-b', 'hl') : cl.add('hl'); sumUp(t); } }; | |
const pad = (n) => (n < 10 ? '0' : '') + n; | |
const date = (t) => t.getFullYear() + '-' + pad(t.getMonth() + 1) + '-' + pad(t.getDate()); | |
const ONE_DAY = 864e5; | |
const ghostThePast = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery no-double-tap-zoom plugin | |
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy! | |
(function($) { | |
var IS_IOS = /iphone|ipad/i.test(navigator.userAgent); | |
$.fn.nodoubletapzoom = function() { | |
if (IS_IOS) | |
$(this).bind('touchstart', function preventZoom(e) { | |
var t2 = e.timeStamp |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# request one at http://api.census.gov/data/key_signup.html and paste it below | |
CENSUS_API_KEY=YOUR_CODE_HERE | |
# a factor 1609.34 squared | |
SQ_M_TO_SQ_MI=2589975.2356 | |
#prereqs: | |
# npm install -g shapefile # 0.6.1 | |
# npm install -g d3-geo-projection # 1.2.1 | |
# npm install -g ndjson-cli # 0.3.0 |
These tools inject a breakpoint, console.log
or console.count
in any function you want to spy on via
stopBefore('Element.prototype.removeChild')
or ditto stopAfter
, logBefore
/ logAfter
/ logAround
/ logCount
.
Works in Chrome DevTools and Safari Inspector; Firefox dev tools reportedly less so.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const units = [["ms", 1000], ["s", 60], ["m", 60], ["h", 24], ["d", 7], ["w", 52.142857142858986], ["y", Infinity]]; | |
const duration = (ms) => units.reduce( | |
({ left, s }, [u, o]) => { | |
const n = left % o; | |
left -= n; | |
n && s.unshift(`${~~n}${u}`); | |
return { left: ~~(left / o), s }; | |
}, | |
{ left: ms, s: [] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright (c) 2013 Omar Shammas (omar@shammaslabs.com) | |
and Stripe (alex@stripe.com) | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to | |
permit persons to whom the Software is furnished to do so, subject to | |
the following conditions: |