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
class BinaryText { | |
static encode(string) { | |
return string.split('').map(char => { | |
const charCode = char.charCodeAt(0); | |
return charCode.toString(2); | |
}).join(''); | |
} | |
static decode(binary) { | |
return binary.match(/.{8}/g).map(byte => { |
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
class DateFormat { | |
constructor(format) { | |
this.format = format instanceof String ? format : String(format); | |
} | |
get _formatMap() { | |
return ['yyyy', 'yy', 'mm', 'm', 'dd', 'd', 'hh', 'h', 'ii', 'i', 'ss', 's']; | |
} | |
format(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
// 1. Create a new bookmark – usually by right-clicking the bookmark toolbar. | |
// 2. Name it (e.g. ‘crosshair’) and paste the following line in the URL field: | |
javascript:((d,p)=>{c=d.body.appendChild(d.createElement('canvas')),a=c.getContext('2d'),d.onmousemove=(e)=>{c.width=w=innerWidth;c.height=h=innerHeight;with(c.style)position='absolute',top=left=0,width=w+p,height=h+p,pointerEvents='none';with(a)clearRect(0,0,w,h),fillStyle='#0002',fillRect(0,e.pageY,w,1),fillRect(e.pageX,0,1,h)}})(document, 'px') |
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
javascript:((h,s)=>{(loop=()=>{requestAnimationFrame(loop),s.filter=`hue-rotate(${h=(h+10)%360}deg)`})()})(0,document.all[0].style); |
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
/** | |
* Usage example | |
* | |
* ``` | |
* const myStore = new Store({ | |
* count: 1, | |
* }); | |
* | |
* myStore.addEventListener('change', () => { | |
* console.log(store.state.count); |
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
/** | |
* Konami | |
* | |
* Listens for the [Konami code][1], runs a callback when detected. | |
* | |
* [1]: https://en.wikipedia.org/wiki/Konami_Code | |
* | |
* Example usage: | |
* | |
* import { konami } from './konami.js/'; |
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 watchMediaQuery(media, truthy = true, falsy = false) { | |
const listeners = []; | |
const mediaQuery = matchMedia(`(${media}: ${truthy})`); | |
mediaQuery.addListener(() => { | |
for (const listener of listeners) listener(); | |
}); | |
return (fn) => { | |
const listener = () => fn(mediaQuery.matches ? truthy : falsy) | |
listeners.push(listener); | |
listener(); |
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
#!/usr/bin/env bash | |
BLUE='\033[1;34m' | |
RESET='\033[0m' | |
WHITE='\033[1;37m' | |
echo -e "Creating temp dir..." | |
tempdir=$(mktemp -d) | |
pushd $tempdir &>/dev/null | |
echo -e "${BLUE}!${WHITE} Starting a new shell. Type ${BLUE}exit${WHITE} to return.${RESET}" |
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
/** | |
* Convert kebab-case to camelCase. | |
* @param {string} kebabString The kebab-case string to convert. | |
* @return {string} The string converted to camelCase. | |
*/ | |
function camelCase(kebabString) { | |
const div = document.createElement('div'); | |
div.setAttribute(`data-${kebabString}`, ''); | |
return Object.keys(div.dataset)[0]; | |
} |
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
/** | |
* RomanNumerals singleton class. | |
* | |
* Usage: | |
* | |
* RomanNumerals.convert(12); // 'XII' | |
*/ | |
class RomanNumerals { | |
static numeralValues = { | |
M: 1000, |
OlderNewer