Skip to content

Instantly share code, notes, and snippets.

View vincentorback's full-sized avatar
🌻

Vincent Orback vincentorback

🌻
View GitHub Profile
@vincentorback
vincentorback / getWeekNumber.js
Last active August 9, 2023 08:34
getWeekNumber.js
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()
@vincentorback
vincentorback / readingTime.js
Last active February 14, 2019 14:05
Reading time / Words per minute
/**
* 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,
@vincentorback
vincentorback / just-write
Last active May 8, 2017 12:30
Simple writing in the browser
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
@vincentorback
vincentorback / imageBrightness.js
Last active March 8, 2024 18:15
Get Image Brightness
function getImageBrightness(imageSrc, callback) {
var img = document.createElement('img'),
colorSum = 0,
i = 0,
len,
canvas,
ctx,
imageData,
data,
brightness,
@vincentorback
vincentorback / debounce-es2015.js
Last active July 22, 2024 11:49
Smarter debouncing
export function debounce (fn, wait = 1) {
let timeout
return function (...args) {
clearTimeout(timeout)
timeout = setTimeout(() => fn.call(this, ...args), wait)
}
}