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
export function debounce (fn, wait = 1) { | |
let timeout | |
return function (...args) { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => fn.call(this, ...args), wait) | |
} | |
} |
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
function getImageBrightness(imageSrc, callback) { | |
var img = document.createElement('img'), | |
colorSum = 0, | |
i = 0, | |
len, | |
canvas, | |
ctx, | |
imageData, | |
data, | |
brightness, |
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
Paste this into your browser: | |
data:text/html,<html><head><title>Just write!</title><style>*{margin: 0 padding: 0}body{width: 90%; max-width: 650px; margin: 5% auto;}@media (min-width:800px){body{font-size: 2em;}}</style><script>var body=document.body if(localStorage.justWrite) body.innerHTML=localStorage.justWrite} function downloadInnerHtml(filename,mimeType){var elHtml=body.innerHTML var link=document.createElement('a') mimeType=mimeType||'text/plain' filename=filename||'document.txt' link.setAttribute('download',filename) link.setAttribute('href','data:'+mimeType+'charset=utf-8,'+encodeURIComponent(elHtml)) link.click()} window.onkeydown=function(event){if((event.key===83)&&(event.metaKey||event.ctrlKey)){downloadInnerHtml() e.preventDefault() return false} localStorage.justWrite=body.innerHTML}</script></head><body contenteditable></body></html> | |
<!-- | |
TODO: | |
- CMD + S to save file. ✓ | |
- Auto focus on input | |
- Choose file extension .md, .txt, .doc |
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
/** | |
* Get reading time | |
* @param {String} text The text string to analyze | |
* @return {Int} Reading time in milliseconds | |
*/ | |
function getReadingTime(text) { | |
var totalWords, | |
wordsPerMillisecond, | |
totalReadingTime, | |
wordsPerMinute = 250, |
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
function getWeekNumber(d) { | |
d = new Date(+d) // Copy date so don't modify original. | |
d.setHours(0, 0, 0, 0) // Reset hours. | |
d.setDate(d.getDate() + 4 - (d.getDay() || 7)) // Set to nearest Thursday: current date + 4 - current day number and make Sunday's day number 7 | |
var yearStart = new Date(d.getFullYear(), 0, 1) // Get first day of year | |
var weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7) // Calculate full weeks to nearest Thursday | |
return weekNo // Return week number | |
} | |
var date = new Date() |
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
function stringToElements (string) { | |
const div = document.createElement('div') | |
div.innerHTML = string | |
if (div.childNodes.length > 1) { | |
return div.childNodes | |
} | |
return div.firstChild | |
} |
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 PREFIXES = ['', 'Moz', 'webkit', 'Webkit', 'O', 'ms']; | |
function applyStyle(prop, value, element) { | |
const first = prop[0]; | |
const trail = prop.slice(1); | |
PREFIXES.forEach(prefix => { | |
let name = prefix ? (prefix + first.toUpperCase()) : first.toLowerCase(); | |
name += trail; |
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
<?php | |
/** | |
* Check if on posts-page | |
*/ | |
function is_page_for_posts () { | |
return ( is_home() || (is_archive() && ! is_post_type_archive() ) ); | |
} | |
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
var distance = distanceBetween({ | |
lat: 59.329323, | |
lng: 18.068581 | |
}, { | |
lat: 57.708870, | |
lng: 11.974560 | |
}); | |
function getRadius(x) { | |
return x * Math.PI / 180; |
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
/** | |
* isUndefined | |
* Check if object is undefined | |
* @param {Anything} value | |
* @return {Boolean} Returns `true` if `value` is `undefined`, else `false`. | |
*/ | |
export function isUndefined(value) { | |
return value === undefined; | |
} |
OlderNewer