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
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 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
/** | |
* 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 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
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 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
function getImageBrightness(imageSrc, callback) { | |
var img = document.createElement('img'), | |
colorSum = 0, | |
i = 0, | |
len, | |
canvas, | |
ctx, | |
imageData, | |
data, | |
brightness, |
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
export function debounce (fn, wait = 1) { | |
let timeout | |
return function (...args) { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => fn.call(this, ...args), wait) | |
} | |
} |
NewerOlder