This file contains hidden or 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
/** | |
* Fixes the content shift caused by disappearing/appearing scrollbars | |
* | |
* Inspired by https://aykevl.nl/2014/09/fix-jumping-scrollbar | |
*/ | |
@media screen and (min-width: 25em) { | |
html { | |
margin-left: calc(100vw - 100%); | |
margin-right: 0; | |
} |
This file contains hidden or 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
// This is all it takes to create those cancerous popups. | |
window.onbeforeunload = function (e) { | |
e = e || window.event; | |
// For IE and Firefox prior to version 4 | |
if (e) { | |
e.returnValue = 'Sure?'; | |
} | |
// For Safari |
This file contains hidden or 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
import fs from 'fs'; | |
import request from 'request'; | |
/** | |
* Download and save a file to the project root | |
* | |
* Courtesy of http://stackoverflow.com/a/12751657/2803743 | |
*/ | |
export const download = function(uri, filename, callback) { | |
request.head(uri, function(err, res, body) { |
This file contains hidden or 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
/* Medium */ | |
body { | |
font-family: -apple-system, | |
BlinkMacSystemFont, | |
"Segoe UI", | |
Roboto, | |
Oxygen, | |
Ubuntu, | |
Cantarell, | |
"Open Sans", |
This file contains hidden or 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
// For those crucial times you can't decide which element to pick | |
$.fn.random = () => { | |
return this.eq(Math.floor(Math.random() * this.length)); | |
}; | |
// Usage | |
$('nav li').random().find('a').click(); |
This file contains hidden or 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
// ES5 | |
function getNodeindex( elm ){ | |
var c = elm.parentNode.children, i = 0; | |
for(; i < c.length; i++ ) | |
if( c[i] == elm ) return i; | |
} | |
// ES6 | |
function getNodeindex( elm ){ | |
return [...elm.parentNode.children].findIndex(c => c == elm) |
This file contains hidden or 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
<!-- Digital clock --> | |
<a id=a> | |
<script> | |
setInterval`a.innerHTML=new Date().toLocaleTimeString('fr')` | |
</script> | |
<!-- Analog clock --> | |
<x id=c> | |
<script> | |
setInterval(eval(a="c.innerHTML='&#'+(128336+((h=(n=new Date).getHours(c.style.fontSize='20vw')%12)?h-1:11)+(n.getMinutes()>29&&12)),a"),1e3) |
This file contains hidden or 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
/** | |
* Returns a small symbol with the correct time displayed in the depicted analog clock | |
*/ | |
(function () { | |
return "\ud83d"+String.fromCharCode(56656+((h=(n=new Date).getHours()%12)?h-1:11)+(n.getMinutes()>29&&12)) | |
})(); |
This file contains hidden or 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
/** | |
* Animate navigation for anchor links on the same page | |
* // TODO: rewrite in vanilla | |
*/ | |
jQuery('a[href^="#"]').on('click', function(event) { | |
event.preventDefault(); | |
var $href = jQuery(this).attr('href'), | |
$toScroll = jQuery($href), | |
scrollToY = $toScroll.length ? $toScroll.offset().top - 0 : 0; |
This file contains hidden or 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
var counts = [4, 9, 15, 6, 2], | |
goal = 5; | |
var closest = counts.reduce(function (prev, curr) { | |
return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev); | |
}); |